Skip to content

Commit 247db9c

Browse files
committed
🐛 修复订阅@connect错误的问题
1 parent f5183bd commit 247db9c

5 files changed

Lines changed: 223 additions & 190 deletions

File tree

src/apps/grant/background.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ export class BackgroundGrant {
244244
const _this: BackgroundGrant = <BackgroundGrant>this;
245245
return new Promise((resolve, reject) => {
246246
const handler = async () => {
247-
const script = <Script | undefined>await App.Cache.getOrSet('script:' + grant.id.toString(), () => {
248-
return _this.scriptMgr.getScript(grant.id)
247+
const script = <Script | undefined>await App.Cache.getOrSet('script:grant:' + grant.id.toString(), () => {
248+
return _this.scriptMgr.getScriptSelfMeta(grant.id);
249249
});
250250
if (!script) {
251251
return reject('permission denied');
@@ -530,6 +530,7 @@ export class BackgroundGrant {
530530
@BackgroundGrant.GMFunction({
531531
confirm: (grant: Grant, script: Script) => {
532532
return new Promise(resolve => {
533+
console.log(grant, script);
533534
const config = <GM_Types.XHRDetails>grant.params[0];
534535
const url = new URL(config.url);
535536
if (script.metadata['connect']) {
@@ -542,11 +543,11 @@ export class BackgroundGrant {
542543
}
543544
const ret: ConfirmParam = {
544545
permission: 'cors',
545-
permissionValue: url.host,
546+
permissionValue: url.hostname,
546547
title: '脚本正在试图访问跨域资源',
547548
metadata: {
548549
'脚本名称': script.name,
549-
'请求域名': url.host,
550+
'请求域名': url.hostname,
550551
'请求地址': config.url,
551552
},
552553
describe: '请您确认是否允许脚本进行此操作,脚本也可增加@connect标签跳过此选项',

src/apps/script/controller.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -490,31 +490,34 @@ export class ScriptController {
490490
}
491491

492492
public buildScriptCache(script: Script): Promise<ScriptCache> {
493-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
494-
return new Promise(async resolve => {
495-
const ret: ScriptCache = <ScriptCache>Object.assign({}, script);
496-
497-
// 自定义配置
498-
for (const key in ret.metadata) {
499-
if (ret.selfMetadata && ret.selfMetadata[key]) {
500-
ret.metadata[key] = ret.selfMetadata[key];
493+
return new Promise(resolve => {
494+
const handler = async () => {
495+
const ret: ScriptCache = <ScriptCache>Object.assign({}, script);
496+
497+
// 自定义配置
498+
if (ret.selfMetadata) {
499+
ret.metadata = Object.assign({}, ret.metadata);
500+
for (const key in ret.selfMetadata) {
501+
ret.metadata[key] = ret.selfMetadata[key];
502+
}
501503
}
502-
}
503504

504-
ret.value = await this.getScriptValue(ret);
505+
ret.value = await this.getScriptValue(ret);
505506

506-
ret.resource = await this.getResources(ret);
507+
ret.resource = await this.getResources(ret);
507508

508-
ret.flag = randomString(16);
509-
ret.code = compileScriptCode(ret);
509+
ret.flag = randomString(16);
510+
ret.code = compileScriptCode(ret);
510511

511-
ret.grantMap = {};
512+
ret.grantMap = {};
512513

513-
ret.metadata['grant']?.forEach((val: string) => {
514-
ret.grantMap[val] = 'ok';
515-
});
514+
ret.metadata['grant']?.forEach((val: string) => {
515+
ret.grantMap[val] = 'ok';
516+
});
516517

517-
resolve(ret);
518+
resolve(ret);
519+
}
520+
void handler();
518521
});
519522
}
520523

0 commit comments

Comments
 (0)