develop-userscripts
作者: xixu-me
在构建、调试、打包或发布用于Tampermonkey或ScriptCat的浏览器用户脚本时使用,包括GM API、元数据块、权限问题、@match/@grant/@connect设置、ScriptCat后台或定时脚本、UserConfig块或订阅工作流。
npx skills add https://github.com/xixu-me/skills --skill develop-userscriptsUserscript work usually breaks at the runtime and metadata boundary, not in the page logic. Choose the runtime first, declare the minimum permissions up front, then debug in the environment where the script actually runs.
When to Use
Use this skill for:
- writing or fixing a Tampermonkey or ScriptCat userscript
- debugging injection timing, missing permissions, CSP workarounds, update checks, or
GM_*behavior - deciding between a portable foreground script and ScriptCat-only
@backgroundor@crontab - adding config UI with
==UserConfig== - packaging a ScriptCat
==UserSubscribe==bundle or preparing a CloudCat-compatible script
Do not use this skill for full browser extension development or general browser automation outside userscript managers.
Runtime Selection
digraph userscript_runtime {
"Need page DOM or page context?" [shape=diamond];
"Need persistent or scheduled work?" [shape=diamond];
"Need to install many scripts as one package?" [shape=diamond];
"Portable foreground script" [shape=box];
"ScriptCat background or crontab script" [shape=box];
"ScriptCat subscription package" [shape=box];
"Need page DOM or page context?" -> "Portable foreground script" [label="yes"];
"Need page DOM or page context?" -> "Need persistent or scheduled work?" [label="no"];
"Need persistent or scheduled work?" -> "ScriptCat background or crontab script" [label="yes"];
"Need persistent or scheduled work?" -> "Need to install many scripts as one package?" [label="no"];
"Need to install many scripts as one package?" -> "ScriptCat subscription package" [label="yes"];
"Need to install many scripts as one package?" -> "Portable foreground script" [label="no"];
}
Preflight
- Confirm the manager and browser. On Manifest V3 browsers, ScriptCat may require
Allow User Scriptsor browser developer mode before scripts run. - Decide page script versus background script before writing code. ScriptCat background scripts cannot touch the DOM.
- Start with metadata, not implementation:
@match,@grant,@connect,@run-at, and any update URLs. - Prefer portable
==UserScript==patterns for ordinary page scripts. Only switch to ScriptCat-only headers when the requested behavior actually needs them.
Workflow
- Choose the runtime and metadata first.
- Declare the smallest permission surface that fits the task.
- Implement against the runtime you chose.
- Debug where the code really runs.
- Foreground scripts: page console plus manager logs.
- ScriptCat background scripts: run log first, then
background.htmlfor real-environment debugging.
- Publish with the right update model.
- Normal scripts: keep
@versionaccurate and add@updateURLor@downloadURLonly when needed. - Subscription bundles: use
==UserSubscribe==, HTTPS URLs, and subscription-level@connect.
- Normal scripts: keep
Quick Reference
| Intent | Default choice | Watch for |
|---|---|---|
| Page UI, DOM scraping, page patching | Portable ==UserScript== | @match, @grant, @run-at, CSP-sensitive injection |
| Cross-origin API access | GM_xmlhttpRequest with explicit @connect | Missing hosts, cookie behavior differences, user authorization |
| Long-running worker | ScriptCat @background | No DOM, must return Promise for async work |
| Scheduled task | ScriptCat @crontab | Only first @crontab counts, prefer 5-field cron, avoid interval overlap |
| User-editable settings | ==UserConfig== plus GM_getValue | Block placement and group.key naming |
| Silent bundle install and updates | ==UserSubscribe== | HTTPS, user.sub.js, subscription connect overrides child scripts |
Common Mistakes
- Missing
@grantfor APIs the script actually uses. - Missing
@connectfor hosts used byGM_xmlhttpRequestorGM_cookie. - Treating
@includeas a better default than@matchfor ordinary host targeting. - Using DOM APIs inside ScriptCat background or cron scripts.
- Returning from a ScriptCat background script before async GM work is truly finished.
- Mixing
==UserScript==and==UserSubscribe==packaging concepts. - Putting
==UserConfig==in the wrong place or reading config keys without thegroup.keyname. - Assuming Tampermonkey and ScriptCat storage, notification, or request behavior is identical.
References
来自 xixu-me 的更多技能
github-actions-docs
xixu-me
当用户询问如何编写、解释、自定义、迁移、保护或排查GitHub Actions工作流、工作流语法、触发器、矩阵、运行器、可复用工作流、制品、缓存、密钥、OIDC、部署、自定义操作或Actions Runner Controller时使用,尤其是当用户需要官方GitHub文档、精确链接或基于文档的YAML指导时。
developmentdevopsdocument
use-my-browser
xixu-me
当工作依赖于用户的实时浏览器会话或可见渲染状态而非静态抓取时使用,尤其适用于浏览器调试场景、DevTools选中的元素或请求、已登录的仪表盘或CMS流程、本地应用、表单、上传、下载、媒体检查、DOM或iframe检查、Shadow DOM,以及表现为软404、认证墙、反爬虫检测或速率限制的浏览器故障。
browser-automationweb-scrapingtesting
readme-i18n
xixu-me
当用户想要翻译仓库的README、使仓库支持多语言、本地化文档、添加语言切换器、国际化README,或更新GitHub风格仓库中的本地化README变体时使用。
documentdevelopmentapi
openclaw-secure-linux-cloud
xixu-me
在云服务器上自托管OpenClaw时使用,用于加固远程OpenClaw网关、选择SSH隧道、Tailscale或反向代理暴露方式,或审查Podman、配对、沙箱、令牌认证及工具权限默认设置,以实现安全的个人部署。
devopssecurity
secure-linux-web-hosting
xixu-me
Use when setting up, hardening, or reviewing a cloud server for self-hosting, including DNS, SSH, firewalls, Nginx, static-site hosting, reverse-proxying an app, HTTPS with Let's Encrypt or ACME clients, safe HTTP-to-HTTPS redirects, or optional post-launch network tuning such as BBR.
devopssecurityaws
opensource-guide-coach
xixu-me
当用户希望获得关于启动、贡献、发展、治理、资助、保护或维护开源项目的指导,或询问贡献者入职、社区健康、维护者倦怠、行为准则、指标、法律基础或开源项目采用等问题时使用。
developmentresearch
running-claude-code-via-litellm-copilot
xixu-me
Use when routing Claude Code through a local LiteLLM proxy to GitHub Copilot, reducing direct Anthropic spend, configuring ANTHROPIC_BASE_URL or ANTHROPIC_MODEL overrides, or troubleshooting Copilot proxy setup failures such as model-not-found, no localhost traffic, or GitHub 401/403 auth errors.
developmentapidevops
skills-cli
xixu-me
Use when users ask to discover, install, list, check, update, remove, back up, restore, sync, or initialize Agent Skills, mention `bunx skills`, `npx skills`, `skills.sh`, or `skills-lock.json`, ask "find a skill for X", or want help extending agent capabilities with installable skills.
developmentapiproductivity