fix GM.xmlHttpRequest & use GM/unsafeWindow global
This commit is contained in:
@@ -34,7 +34,11 @@
|
||||
"extends": [
|
||||
"react-app",
|
||||
"react-app/jest"
|
||||
]
|
||||
],
|
||||
"globals": {
|
||||
"GM": true,
|
||||
"unsafeWindow": true
|
||||
}
|
||||
},
|
||||
"browserslist": {
|
||||
"production": [
|
||||
|
||||
@@ -21,8 +21,7 @@ import { msAuth } from "./auth";
|
||||
*/
|
||||
const fetchGM = async (input, { method = "GET", headers, body } = {}) =>
|
||||
new Promise((resolve, reject) => {
|
||||
try {
|
||||
(window.GM_xmlhttpRequest || window.GM.xmlhttpRequest)({
|
||||
GM.xmlHttpRequest({
|
||||
method,
|
||||
url: input,
|
||||
headers,
|
||||
@@ -31,7 +30,7 @@ const fetchGM = async (input, { method = "GET", headers, body } = {}) =>
|
||||
if (response.status === 200) {
|
||||
const headers = new Headers();
|
||||
response.responseHeaders.split("\n").forEach((line) => {
|
||||
let [name, value] = line.split(":").map((item) => item.trim());
|
||||
const [name, value] = line.split(":").map((item) => item.trim());
|
||||
if (name && value) {
|
||||
headers.append(name, value);
|
||||
}
|
||||
@@ -43,9 +42,6 @@ const fetchGM = async (input, { method = "GET", headers, body } = {}) =>
|
||||
},
|
||||
onerror: reject,
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,8 +4,8 @@ async function set(key, val) {
|
||||
if (isExt) {
|
||||
await browser.storage.local.set({ [key]: val });
|
||||
} else if (isGm) {
|
||||
const oldValue = await (window.GM_getValue || window.GM.getValue)(key);
|
||||
await (window.GM_setValue || window.GM.setValue)(key, val);
|
||||
const oldValue = await GM.getValue(key);
|
||||
await GM.setValue(key, val);
|
||||
window.dispatchEvent(
|
||||
new StorageEvent("storage", {
|
||||
key,
|
||||
@@ -31,7 +31,7 @@ async function get(key) {
|
||||
const val = await browser.storage.local.get([key]);
|
||||
return val[key];
|
||||
} else if (isGm) {
|
||||
const val = await (window.GM_getValue || window.GM.getValue)(key);
|
||||
const val = await GM.getValue(key);
|
||||
return val;
|
||||
}
|
||||
return window.localStorage.getItem(key);
|
||||
@@ -41,8 +41,8 @@ async function del(key) {
|
||||
if (isExt) {
|
||||
await browser.storage.local.remove([key]);
|
||||
} else if (isGm) {
|
||||
const oldValue = await (window.GM_getValue || window.GM.getValue)(key);
|
||||
await (window.GM_deleteValue || window.GM.deleteValue)(key);
|
||||
const oldValue = await GM.getValue(key);
|
||||
await GM.deleteValue(key);
|
||||
window.dispatchEvent(
|
||||
new StorageEvent("storage", {
|
||||
key,
|
||||
|
||||
@@ -16,12 +16,8 @@ import { Translator } from "./libs/translator";
|
||||
document.location.href.includes(process.env.REACT_APP_OPTIONSPAGE) ||
|
||||
document.location.href.includes(process.env.REACT_APP_OPTIONSPAGE2)
|
||||
) {
|
||||
window.unsafeWindow.GM = window.GM;
|
||||
window.unsafeWindow.GM_xmlhttpRequest = window.GM_xmlhttpRequest;
|
||||
window.unsafeWindow.GM_setValue = window.GM_setValue;
|
||||
window.unsafeWindow.GM_getValue = window.GM_getValue;
|
||||
window.unsafeWindow.GM_deleteValue = window.GM_deleteValue;
|
||||
window.unsafeWindow.APP_NAME = process.env.REACT_APP_NAME;
|
||||
unsafeWindow.GM = GM;
|
||||
unsafeWindow.APP_NAME = process.env.REACT_APP_NAME;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user