chrome.webRequest.onBeforeRequest.addListener(
    function (details) {
        // 在这里修改请求的 URL
        // console.log(details.url)
        if (details.url.indexOf('outbound') != -1) {
            details.url = 'https://www.jetblue.com/lfs-rwb/outboundLFSsss';
        }
        return {redirectUrl: details.url};
    },
    {urls: ['<all_urls>']},
    ['blocking', 'requestBody', 'extraHeaders']
);

chrome.webRequest.onBeforeSendHeaders.addListener((details) => {
    console.log(details.requestHeaders.map(e => {
        return e.name
    }) + '')
    let res = [];
    const needOrigin = details.requestHeaders.map(v => {
        if (v.name.indexOf('X-1ItxWO9i') > -1) {
            res.push(v);
        }
    })
    let t = parseInt(Math.random() * 1500) + 10000
    let proxy = `http://unfflcc:76cc14-47b8dd-1f8ace-827836-0c740e@usa.rotating.proxyrack.net:${t}`
    let body = {
        "brush_fromto": "LAS-BOS",
        "brush_fromdate": "2023-05-26",
        "brush_header": {
            "authority": "jbrest.jetblue.com",
            "accept": "application/json",
            "accept-language": "zh-CN,zh;q=0.9",
            "api-version": "v3",
            "application-channel": "Desktop_Web",
            "booking-application-type": "NGB",
            "cache-control": "no-cache",
            "content-type": "application/json",
            "origin": "https://www.jetblue.com",
            "pragma": "no-cache",
            "sec-ch-ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\"",
            "sec-ch-ua-mobile": "?0",
            "sec-ch-ua-platform": "\"Windows\"",
            "sec-fetch-dest": "empty",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "same-site",
            "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
        },
        "brush_proxy": proxy,
        "brush_mode": "shopping",
        "brush_name": "js",
        "brush_type": "headerB6"
    }
    for (let i = 0; i < res.length; i++) {
        body.brush_header[res[i].name] = res[i].value
    }
    if (res.length > 0) {
        fetch("http://ymx-lcc.unififi.com/header/add", {
            "headers": {
                "accept": "application/json",
                "accept-language": "en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,ru;q=0.6",
                "api-version": "v3",
                "application-channel": "Desktop_Web",
                "booking-application-type": "NGB",
                "cache-control": "no-cache",
                "content-type": "application/json",
                "pragma": "no-cache",
                "sec-ch-ua": "\"Not/A)Brand\";v=\"99\", \"Google Chrome\";v=\"115\", \"Chromium\";v=\"115\"",
                "sec-ch-ua-mobile": "?0",
                "sec-ch-ua-platform": "\"macOS\"",
                "sec-fetch-dest": "empty",
                "sec-fetch-mode": "cors",
                "sec-fetch-site": "same-site",
                "x-auth-token": "7d66f40f-77e5-4857-b0f5-1a2bbd16427a",
                "x-b3-spanid": "1694597336668",
                "x-b3-traceid": "fa70f4c5a0583941"
            },
            "referrerPolicy": "no-referrer-when-downgrade",
            "body": JSON.stringify(body),
            "method": "POST",
            "mode": "cors",
            "credentials": "omit"
        }).then(r => {
            return r.text()
        }).then(r => {
            console.log(r)
        })
    }

}, {
    urls: ["<all_urls>"],
    types: ["xmlhttprequest"]
}, ["blocking", "requestHeaders", "extraHeaders"])