diff --git a/config-overrides.js b/config-overrides.js index 288ac26..51727d3 100644 --- a/config-overrides.js +++ b/config-overrides.js @@ -97,6 +97,7 @@ const userscriptWebpack = (config, env) => { // @grant GM.getValue // @grant GM_deleteValue // @grant GM.deleteValue +// @grant unsafeWindow // @connect translate.googleapis.com // @connect api-edge.cognitive.microsofttranslator.com // @connect edge.microsoft.com diff --git a/src/apis/index.js b/src/apis/index.js index 7207b26..be8e2e4 100644 --- a/src/apis/index.js +++ b/src/apis/index.js @@ -20,14 +20,18 @@ import { getSetting, detectLang } from "../libs"; * @returns */ export const apiSyncData = async (url, key, data) => - fetchPolyfill(url, { - headers: { - "Content-type": "application/json", - [KV_HEADER_KEY]: key, + fetchPolyfill( + url, + { + headers: { + "Content-type": "application/json", + [KV_HEADER_KEY]: key, + }, + method: "POST", + body: JSON.stringify(data), }, - method: "POST", - body: JSON.stringify(data), - }); + { useUnsafe: true } + ); /** * 谷歌翻译 diff --git a/src/libs/fetch.js b/src/libs/fetch.js index 25a44fb..ac4d881 100644 --- a/src/libs/fetch.js +++ b/src/libs/fetch.js @@ -72,7 +72,11 @@ const newCacheReq = async (request, translator) => { * @param {*} opts * @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 cache = await caches.open(CACHE_NAME); let res; @@ -89,7 +93,11 @@ export const fetchData = async (input, init, { useCache, translator } = {}) => { // 发送请求 if (!res) { if (isGm) { - res = await fetchGM(input, init); + if (useUnsafe) { + res = await window.unsafeWindow.fetch(input, init); + } else { + res = await fetchGM(input, init); + } } else { res = await fetch(input, init); }