From fa9dcbcb39abb1de70eb0bee9fc72314958d44a8 Mon Sep 17 00:00:00 2001 From: CodFrm Date: Fri, 17 Dec 2021 16:06:35 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8DGM=5FsetValue?= =?UTF-8?q?=E8=AE=BE=E7=BD=AEobject=E5=AE=9E=E4=BE=8B=E6=97=B6=E7=9A=84?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apps/grant/background.ts | 2 +- src/apps/grant/frontend.ts | 6 +++++- src/types/main.d.ts | 22 +++++++++++++++++++++- src/types/tampermonkey.d.ts | 2 +- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/apps/grant/background.ts b/src/apps/grant/background.ts index d676b73a..91b2841a 100644 --- a/src/apps/grant/background.ts +++ b/src/apps/grant/background.ts @@ -464,7 +464,7 @@ export class BackgroundGrant { //错误 return reject('param is null'); } - const config = grant.params[0]; + const config = grant.params[0]; const xhr = new XMLHttpRequest(); xhr.open(config.method || 'GET', config.url, true, config.user || '', config.password || ''); diff --git a/src/apps/grant/frontend.ts b/src/apps/grant/frontend.ts index bc73c20c..ac5ec1b1 100644 --- a/src/apps/grant/frontend.ts +++ b/src/apps/grant/frontend.ts @@ -143,7 +143,7 @@ export class FrontendGrant implements ScriptContext { } } } - let param: GM_Types.XHRDetails = { + let param: GMSend.XHRDetails = { method: details.method, timeout: details.timeout, url: u.href, @@ -313,6 +313,10 @@ export class FrontendGrant implements ScriptContext { @FrontendGrant.GMFunction() public GM_setValue(name: string, value: any): void { + // 对object的value进行一次转化 + if (typeof value === "object") { + value = JSON.parse(JSON.stringify(value)); + } let ret = this.script.value![name]; if (ret) { ret.value = value; diff --git a/src/types/main.d.ts b/src/types/main.d.ts index 38dc30b4..24fc357e 100644 --- a/src/types/main.d.ts +++ b/src/types/main.d.ts @@ -86,4 +86,24 @@ interface Userinfo { id: number; username: string; avatar?: string; -} \ No newline at end of file +} + +declare namespace GMSend { + interface XHRDetails { + method?: "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" + url: string + headers?: { [key: string]: string } + data?: string | Array + cookie?: string + binary?: boolean + timeout?: number + context?: CONTEXT_TYPE + responseType?: "arraybuffer" | "blob" | "json" + overrideMimeType?: string, + anonymous?: boolean, + fetch?: boolean, + user?: string, + password?: string, + nocache?: boolean + } +} diff --git a/src/types/tampermonkey.d.ts b/src/types/tampermonkey.d.ts index 538d46c0..84cb74af 100644 --- a/src/types/tampermonkey.d.ts +++ b/src/types/tampermonkey.d.ts @@ -193,7 +193,7 @@ declare namespace GM_Types { method?: "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" url: string headers?: { [key: string]: string } - data?: any + data?: string | FormData cookie?: string binary?: boolean timeout?: number