Skip to content

✨ 实现异步GM函数#492

Merged
CodFrm merged 1 commit intoscriptscat:mainfrom
cyfung1031:patch_async
Jul 5, 2025
Merged

✨ 实现异步GM函数#492
CodFrm merged 1 commit intoscriptscat:mainfrom
cyfung1031:patch_async

Conversation

@cyfung1031
Copy link
Copy Markdown
Collaborator

No description provided.

public GMDotSetValue(key: string, value: any): Promise<void> {
// Asynchronous wrapper for GM_setValue to support GM.setValue
return new Promise((resolve) => {
this.GM_setValue(key, value);
Copy link
Copy Markdown
Member

@CodFrm CodFrm Jul 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GM_setValue的实现返回值是一个Promise,这里应该可以直接返回,或者不用专门的实现GMDotSetValue,部分函数同理例如(GM_deleteValue,也可以直接做一个返回)

  @GMContext.API({ depend: ["GM_setValue"] })
  public GM_deleteValue(name: string): void {
    return this.GM_setValue(name, undefined);
  }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

思考了一下,毕竟GM_setValue是专门作为同步函数存在的,这样处理一下避免以后又进行了改动,也挺好的

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

倒回來 GM_setValue 才是寫錯吧。 按照TM,GM_setValue 不傳回任何東西
還有 GM_setValue的值undefined 不等如刪除 才對

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是如此,可以修改掉

@GMContext.API({ depend: ["GM_deleteValue"] })
public GMDotDeleteValue(name: string): Promise<void> {
// Asynchronous wrapper for GM_deleteValue to support GM.deleteValue
return new Promise((resolve) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

@CodFrm
Copy link
Copy Markdown
Member

CodFrm commented Jul 5, 2025

🙏,非常感谢,辛苦了

@CodFrm CodFrm merged commit cb8edf7 into scriptscat:main Jul 5, 2025
2 checks passed
@cyfung1031 cyfung1031 deleted the patch_async branch July 8, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants