获取main-entry用来获取anti_content

This commit is contained in:
aixianling
2023-08-14 18:25:19 +08:00
parent 55d2684c52
commit 788c879ed6
4 changed files with 480 additions and 52 deletions

View File

@@ -1,51 +1,55 @@
/**
利用chrome的fetch来避免跨域
**/
利用chrome的fetch来避免跨域
**/
import {genAnti} from "@/entry/genAnti";
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.type == 'api') {
new Promise((resolve, reject) => {
let headers = {};
if (request.needMallId) {
headers.Mallid = request.mallId;
}
headers['Content-Type'] = 'application/json';
headers.cookie = getCookie();
fetch(request.url, {
// Promise.resolve(genAnti()).then(r => {
// headers["Anti-Content"] = r
// })
Promise.resolve().then(() => fetch(request.url, {
'headers': headers,
'method': 'POST',
'referrerPolicy': 'no-referrer',
'credentials': 'include',
'body': JSON.stringify(request.data),
'mode': 'cors'
}).then((res) => {
})).then((res) => {
resolve(res.json());
});
}).then((res) => {
sendResponse(res);
});
} else if (request.type == 'init') {
fetch(request.url,{headers:{cookie: getCookie()}}).then(res => sendResponse(res.text()));
} else if (request.type == 'notify') {
chrome.notifications.create(
"" + Math.random(), {
type: "basic",
title: "TEMU助手",
message: "您店铺【" + request.mallName + "】的商品【" + request.productName + "】成功加入发货台,请尽快处理",
iconUrl: "./icons/48.png"
}, null
"" + Math.random(), {
type: "basic",
title: "TEMU助手",
message: "您店铺【" + request.mallName + "】的商品【" + request.productName + "】成功加入发货台,请尽快处理",
iconUrl: "./icons/48.png"
}, null
)
}
return true;
});
chrome.action.onClicked.addListener(function () {
chrome.tabs.create({
url: "./popup.html"
url: "./popup.html"
}, function (tab) {
console.log('tab is:' + tab);
console.log('tab is:' + tab);
});
});
@@ -58,4 +62,4 @@ function getCookie() {
});
});
return cStr;
}
}