文 件上传
This commit is contained in:
@@ -5,20 +5,44 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
if (request.type == 'api') {
|
||||
new Promise((resolve) => {
|
||||
let headers = {};
|
||||
let data = null;
|
||||
if (request.needMallId) {
|
||||
headers.Mallid = request.mallId;
|
||||
}
|
||||
if (request.anti) {
|
||||
headers["Anti-Content"] = request.anti
|
||||
}
|
||||
headers['Content-Type'] = 'application/json';
|
||||
if (!request.isFormData) {
|
||||
headers['Content-Type'] = 'application/json';
|
||||
data = JSON.stringify(request.data)
|
||||
} else {
|
||||
console.log(request.data)
|
||||
const formData = new FormData();
|
||||
Object.keys(request.data).forEach(key => {
|
||||
const value = request.data[key]
|
||||
if (Array.isArray(value)) {
|
||||
value.forEach((subValue, i) => {
|
||||
formData.append(key + `[${i}]`, subValue)
|
||||
})
|
||||
} else {
|
||||
if (key == 'image') {
|
||||
let blob = new Blob([request.data[key]], {type: 'application/png'})
|
||||
// formData.append(key, new Blob([request.data[key]], {type: 'application/png'}))
|
||||
formData.append(key, blob)
|
||||
} else {
|
||||
formData.append(key, request.data[key])
|
||||
}
|
||||
}
|
||||
})
|
||||
data = formData
|
||||
}
|
||||
headers.cookie = getCookie();
|
||||
Promise.resolve().then(() => fetch(request.url, {
|
||||
'headers': headers,
|
||||
'method': 'POST',
|
||||
'referrerPolicy': 'no-referrer',
|
||||
'credentials': 'include',
|
||||
'body': JSON.stringify(request.data),
|
||||
'body': data,
|
||||
'mode': 'cors'
|
||||
})).then((res) => {
|
||||
resolve(res.json());
|
||||
@@ -111,6 +135,24 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
||||
});
|
||||
});
|
||||
}).then(sendResponse);
|
||||
} else if (request.type == 'sheinApi') {
|
||||
new Promise((resolve) => {
|
||||
let headers = {};
|
||||
headers['Content-Type'] = 'application/json';
|
||||
headers.cookie = getSheinCookie()
|
||||
request.params = formatParams(request.params)
|
||||
let _url = request.url + (request.params ? ('?' + request.params) : '')
|
||||
Promise.resolve().then(() => fetch(_url, {
|
||||
'headers': headers,
|
||||
'method': request.method,
|
||||
'referrerPolicy': 'no-referrer',
|
||||
'credentials': 'include',
|
||||
'body': JSON.stringify(request.data),
|
||||
'mode': 'cors'
|
||||
})).then((res) => {
|
||||
resolve(res.json());
|
||||
});
|
||||
}).then(sendResponse);
|
||||
} else if (request.type == 'notify') {
|
||||
chrome.notifications.create(
|
||||
"" + Math.random(), {
|
||||
@@ -183,8 +225,8 @@ function getTemuCookie() {
|
||||
return cStr;
|
||||
}
|
||||
|
||||
function getAliexpressCookie() {
|
||||
const url = new URL("https://www.aliexpress.us/");
|
||||
function getSheinCookie() {
|
||||
const url = new URL("https://www.shein.com/");
|
||||
let cStr = '';
|
||||
chrome.cookies.getAll({domain: url.host}, (cookie) => {
|
||||
cookie.map((c) => {
|
||||
@@ -192,4 +234,24 @@ function getAliexpressCookie() {
|
||||
});
|
||||
});
|
||||
return cStr;
|
||||
}
|
||||
|
||||
|
||||
function getAliexpressCookie() {
|
||||
const url = new URL("https://www.aliexpress.com/");
|
||||
let cStr = '';
|
||||
chrome.cookies.getAll({domain: url.host}, (cookie) => {
|
||||
cookie.map((c) => {
|
||||
cStr += c.name + '=' + c.value + ';';
|
||||
});
|
||||
});
|
||||
return cStr;
|
||||
}
|
||||
|
||||
function formatParams(data) {
|
||||
const arr = []
|
||||
for (let name in data) {
|
||||
arr.push(encodeURIComponent(name) + "=" + encodeURIComponent(data[name]))
|
||||
}
|
||||
return arr.join("&")
|
||||
}
|
||||
Reference in New Issue
Block a user