Skip to content

[Feature] 更多后台/定时脚本API #1034

Description

@DreamNya

使后台/定时脚本支持 @run-in

目前后台/定时脚本不支持 @run-in,当浏览器同时打开正常标签页和隐身模式标签页时,如果恰好触发定时脚本,脚本猫会在两种模式下各运行一次,可能引发各种意料之外的问题。
而现在用户/开发者既无法为后台/定时脚本指定 @run-in,也无法通过 GM_info.isIncognito 判断是否处于隐身模式。


更灵活的 @crontab 、 使定时脚本支持禁用本脚本

目前定时脚本 @crontab 不太灵活,只能静态定义一个 @crontab,无法满足某些应用场景
可以尝试增加动态 @crontab(比如一个精确时间 2025/11/29 19:12:34),让脚本根据不同情况决定下一次运行时间而不是机械的、静态的下一次运行时间。甚至如果脚本完成了任务不需要继续定时执行了,可以让定时脚本禁用自己(也就是没有下一次运行时间)

Activity

  1. added theissue type on Nov 29, 2025
  2. cyfung1031 commented on Nov 30, 2025

    @cyfung1031
    Collaborator

    虽然我没时间提PR
    但我还是认为背景脚本应该是 event driven
    不是定义 @crontab
    而是 CAT_onEvent({event: "CRONTAB 5 4 * * *", callback: ....}) 这样的方式
    然后里面可以再定义其他东西,取消CAT_onEvent等等

    CAT_onEvent({event: "crontab", crontab: "5 4 * * *", callback: ...., id: "handleId1"});
    CAT_offEvent("handleId1");

    CAT_onEvent({event: "valueChange" , key: "key123", callback: ...., id: "handleId2"});
    ....

  3. CodFrm commented on Nov 30, 2025

    @CodFrm
    Member

    虽然我没时间提PR
    但我还是认为背景脚本应该是 event driven
    不是定义 @crontab
    而是 CAT_onEvent({event: "CRONTAB 5 4 * * *", callback: ....}) 这样的方式
    然后里面可以再定义其他东西,取消CAT_onEvent等等

    CAT_onEvent({event: "crontab", crontab: "5 4 * * *", callback: ...., id: "handleId1"});
    CAT_offEvent("handleId1");

    CAT_onEvent({event: "valueChange" , key: "key123", callback: ...., id: "handleId2"});
    ....

    可以增加类似的API,其实就是后台脚本 @background 自己管理定时任务,自己引用一个库都可以,现在的定时脚本确实不够灵活 等后续再计划一下吧

  4. cyfung1031 commented on Apr 23, 2026

    @cyfung1031
    Collaborator

    使后台/定时脚本支持 @run-in

    目前后台/定时脚本不支持 @run-in,当浏览器同时打开正常标签页和隐身模式标签页时,如果恰好触发定时脚本,脚本猫会在两种模式下各运行一次,可能引发各种意料之外的问题。 而现在用户/开发者既无法为后台/定时脚本指定 @run-in,也无法通过 GM_info.isIncognito 判断是否处于隐身模式。

    @CodFrm
    在 PR #1368 处理

  5. CodFrm commented on Apr 23, 2026

    @CodFrm
    Member

    使后台/定时脚本支持 @run-in

    目前后台/定时脚本不支持 @run-in,当浏览器同时打开正常标签页和隐身模式标签页时,如果恰好触发定时脚本,脚本猫会在两种模式下各运行一次,可能引发各种意料之外的问题。 而现在用户/开发者既无法为后台/定时脚本指定 @run-in,也无法通过 GM_info.isIncognito 判断是否处于隐身模式。

    @CodFrm 在 PR #1368 处理

    我后续看看,先弄完手头上的内容吧

  6. changed the issue type fromtoon Apr 23, 2026
  7. changed the issue type fromtoon Apr 23, 2026
  8. cyfung1031 commented on Apr 23, 2026

    @cyfung1031
    Collaborator

    @DreamNya

    下次分开两个 issue 开吧。前者是bug 后者是 feature
    前者:一直都没看到。刚发PR了
    后者:以前的做法暂时不动了。今年应该都不会有什么变化

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions