fix data sync bug
This commit is contained in:
@@ -97,6 +97,7 @@ const userscriptWebpack = (config, env) => {
|
|||||||
// @grant GM.getValue
|
// @grant GM.getValue
|
||||||
// @grant GM_deleteValue
|
// @grant GM_deleteValue
|
||||||
// @grant GM.deleteValue
|
// @grant GM.deleteValue
|
||||||
|
// @grant unsafeWindow
|
||||||
// @connect translate.googleapis.com
|
// @connect translate.googleapis.com
|
||||||
// @connect api-edge.cognitive.microsofttranslator.com
|
// @connect api-edge.cognitive.microsofttranslator.com
|
||||||
// @connect edge.microsoft.com
|
// @connect edge.microsoft.com
|
||||||
|
|||||||
@@ -20,14 +20,18 @@ import { getSetting, detectLang } from "../libs";
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const apiSyncData = async (url, key, data) =>
|
export const apiSyncData = async (url, key, data) =>
|
||||||
fetchPolyfill(url, {
|
fetchPolyfill(
|
||||||
headers: {
|
url,
|
||||||
"Content-type": "application/json",
|
{
|
||||||
[KV_HEADER_KEY]: key,
|
headers: {
|
||||||
|
"Content-type": "application/json",
|
||||||
|
[KV_HEADER_KEY]: key,
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(data),
|
||||||
},
|
},
|
||||||
method: "POST",
|
{ useUnsafe: true }
|
||||||
body: JSON.stringify(data),
|
);
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 谷歌翻译
|
* 谷歌翻译
|
||||||
|
|||||||
@@ -72,7 +72,11 @@ const newCacheReq = async (request, translator) => {
|
|||||||
* @param {*} opts
|
* @param {*} opts
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export const fetchData = async (input, init, { useCache, translator } = {}) => {
|
export const fetchData = async (
|
||||||
|
input,
|
||||||
|
init,
|
||||||
|
{ useCache, translator, useUnsafe } = {}
|
||||||
|
) => {
|
||||||
const cacheReq = await newCacheReq(new Request(input, init), translator);
|
const cacheReq = await newCacheReq(new Request(input, init), translator);
|
||||||
const cache = await caches.open(CACHE_NAME);
|
const cache = await caches.open(CACHE_NAME);
|
||||||
let res;
|
let res;
|
||||||
@@ -89,7 +93,11 @@ export const fetchData = async (input, init, { useCache, translator } = {}) => {
|
|||||||
// 发送请求
|
// 发送请求
|
||||||
if (!res) {
|
if (!res) {
|
||||||
if (isGm) {
|
if (isGm) {
|
||||||
res = await fetchGM(input, init);
|
if (useUnsafe) {
|
||||||
|
res = await window.unsafeWindow.fetch(input, init);
|
||||||
|
} else {
|
||||||
|
res = await fetchGM(input, init);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
res = await fetch(input, init);
|
res = await fetch(input, init);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user