Skip to content

Commit

Permalink
🐛 修复GM_setValue设置object实例时的错误
Browse files Browse the repository at this point in the history
  • Loading branch information
CodFrm committed Dec 17, 2021
1 parent 74981dc commit fa9dcbc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/apps/grant/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ export class BackgroundGrant {
//错误
return reject('param is null');
}
const config = <GM_Types.XHRDetails>grant.params[0];
const config = <GMSend.XHRDetails>grant.params[0];

const xhr = new XMLHttpRequest();
xhr.open(config.method || 'GET', config.url, true, config.user || '', config.password || '');
Expand Down
6 changes: 5 additions & 1 deletion src/apps/grant/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion src/types/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,24 @@ interface Userinfo {
id: number;
username: string;
avatar?: string;
}
}

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
}
}
2 changes: 1 addition & 1 deletion src/types/tampermonkey.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fa9dcbc

Please sign in to comment.