重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
tampermonkey by henkisdabro/wookstar-claude-code-plugins
npx skills add https://github.com/henkisdabro/wookstar-claude-code-plugins --skill tampermonkey编写 Tampermonkey 用户脚本的专家指南 - 这些浏览器脚本可以修改网页、自动化任务并增强浏览体验。
// ==UserScript==
// @name My Script Name // <- 自定义:唯一的脚本名称
// @namespace https://example.com/scripts/ // <- 自定义:您唯一的命名空间
// @version 1.0.0 // <- 更新时递增
// @description Brief description of the script // <- 自定义:脚本功能描述
// @author Your Name // <- 自定义:您的姓名
// @match https://example.com/* // <- 自定义:目标 URL 模式
// @grant none // <- 根据需要添加权限
// @run-at document-idle // <- 根据需要调整执行时机
// ==/UserScript==
(function() {
'use strict';
// 在此处编写您的代码
console.log('Script loaded!');
})();
| 标签 | 必需 | 用途 | 示例 |
|---|---|---|---|
@name |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 是 |
脚本名称(支持使用 :locale 进行国际化) |
@name My Script |
@namespace | 推荐 | 唯一标识符命名空间 | @namespace https://yoursite.com/ |
@version | 是* | 用于更新的版本号(*自动更新必需) | @version 1.2.3 |
@description | 推荐 | 脚本功能描述 | @description Enhances page layout |
@match | 是** | 运行脚本的 URL(**或使用 @include) | @match https://example.com/* |
@grant | 视情况而定 | API 权限(使用 none 表示不需要 GM_* API) | @grant GM_setValue |
@run-at | 可选 | 注入时机(默认:document-idle) | @run-at document-start |
完整头部文档请参阅: header-reference.md
// 精确域名 // @match https://example.com/*
// 所有子域名 // @match https://*.example.com/*
// HTTP 和 HTTPS // @match *://example.com/*
// 排除路径(使用 @match) // @exclude https://example.com/admin/*
高级模式(正则表达式、@include、特定路径)请参阅: url-matching.md
| 您需要... | 授予此权限 |
|---|---|
| 存储持久化数据 | @grant GM_setValue + @grant GM_getValue |
| 发起跨域请求 | @grant GM_xmlhttpRequest + @connect domain |
| 添加自定义 CSS | @grant GM_addStyle |
| 访问页面的 window 对象 | @grant unsafeWindow |
| 显示通知 | @grant GM_notification |
| 添加菜单命令 | @grant GM_registerMenuCommand |
| 检测 URL 变化(SPA) | @grant window.onurlchange |
// 禁用沙盒(除 GM_info 外无 GM_* 权限)
// @grant none
// 跨域请求需要 @connect
// @grant GM_xmlhttpRequest
// @connect api.example.com
// @connect *.googleapis.com
完整权限指南请参阅: header-reference.md
| 值 | 脚本运行时机 | 使用场景 |
|---|---|---|
document-start | DOM 存在之前 | 阻止资源、早期修改全局变量 |
document-body | body 存在时 | 早期 DOM 操作 |
document-end | DOMContentLoaded 时 | 大多数脚本 - DOM 准备就绪 |
document-idle | DOMContentLoaded 之后(默认) | 安全的默认值 |
context-menu | 右键菜单时 | 用户触发的操作 |
这些模式经常使用。以下是简要摘要 - 加载 patterns.md 查看包含代码示例的完整实现。
window.onurlchange 授权或 History API 拦截检测单页应用中的导航GM_xmlhttpRequest 和 @connect 域名白名单从外部 API 获取数据。另请参阅 http-requests.mdGM_addStyle 注入 CSS 以重新设计页面样式或隐藏元素。另请参阅 api-dom-ui.mdGM_setValue/GM_getValue 存储用户偏好,并通过 GM_registerMenuCommand 公开切换。另请参阅 api-storage.md// @require - 加载外部脚本
// @require https://code.jquery.com/jquery-3.6.0.min.js#sha256-/xUj+3OJU...
// @require tampermonkey://vendor/jquery.js // 内置库
// @resource - 预加载并注入外部 CSS
// @resource myCSS https://example.com/style.css // 然后:GM_addStyle(GM_getResourceText('myCSS'))
// @grant GM_getResourceText
// @grant GM_addStyle
用户脚本存在以下限制:
大多数限制都有变通方案 - 请参阅 common-pitfalls.md。
始终在您的响应中包含:
返回用户脚本前,请验证:
*://*/*)完整安全清单请参阅: security-checklist.md
根据用户需求按需加载:
| 文件 | 何时加载 |
|---|---|
| 核心 | |
| header-reference.md | 头部语法 - 所有 @标签及示例 |
| url-matching.md | @match、@include、@exclude 模式 |
| patterns.md | 常见实现模式及代码 |
| sandbox-modes.md | 安全/隔离执行上下文 |
| API | |
| api-sync.md | GM_* 同步函数用法 |
| api-async.md | GM.* 基于 Promise 的 API 用法 |
| api-storage.md | GM_setValue、GM_getValue、监听器 |
| http-requests.md | GM_xmlhttpRequest 跨域请求 |
| web-requests.md | GM_webRequest 拦截(Firefox) |
| api-cookies.md | GM_cookie 操作 |
| api-dom-ui.md | addElement、addStyle、unsafeWindow |
| api-tabs.md | getTab、saveTab、openInTab |
| api-audio.md | 静音/取消静音标签页 |
| 质量 | |
| common-pitfalls.md | 导致脚本失效的原因及变通方案 |
| debugging.md | 如何调试用户脚本 |
| browser-compatibility.md | Chrome 与 Firefox 的差异 |
| security-checklist.md | 交付前的安全验证 |
| version-numbering.md | 版本字符串比较规则 |
每周安装数
66
仓库
GitHub 星标数
45
首次出现
2026年1月25日
安全审计
安装于
opencode61
codex60
gemini-cli58
github-copilot57
cursor55
kimi-cli54
Expert guidance for writing Tampermonkey userscripts - browser scripts that modify web pages, automate tasks, and enhance browsing experience.
// ==UserScript==
// @name My Script Name // <- CUSTOMISE: Unique script name
// @namespace https://example.com/scripts/ // <- CUSTOMISE: Your unique namespace
// @version 1.0.0 // <- INCREMENT on updates
// @description Brief description of the script // <- CUSTOMISE: What it does
// @author Your Name // <- CUSTOMISE: Your name
// @match https://example.com/* // <- CUSTOMISE: Target URL pattern
// @grant none // <- ADD permissions as needed
// @run-at document-idle // <- ADJUST timing if needed
// ==/UserScript==
(function() {
'use strict';
// Your code here
console.log('Script loaded!');
})();
| Tag | Required | Purpose | Example |
|---|---|---|---|
@name | Yes | Script name (supports i18n with :locale) | @name My Script |
@namespace | Recommended | Unique identifier namespace | @namespace https://yoursite.com/ |
@version | Yes* | Version for updates (*required for auto-update) | @version 1.2.3 |
@description | Recommended | What the script does | @description Enhances page layout |
@match | Yes** | URLs to run on (**or @include) | @match https://example.com/* |
@grant | Situational | API permissions (use none for no GM_* APIs) | @grant GM_setValue |
@run-at | Optional | When to inject (default: document-idle) | @run-at document-start |
For complete header documentation, see: header-reference.md
// Exact domain // @match https://example.com/*
// All subdomains // @match https://*.example.com/*
// HTTP and HTTPS // @match *://example.com/*
// Exclude paths (with @match) // @exclude https://example.com/admin/*
For advanced patterns (regex, @include, specific paths), see: url-matching.md
| You Need To... | Grant This |
|---|---|
| Store persistent data | @grant GM_setValue + @grant GM_getValue |
| Make cross-origin requests | @grant GM_xmlhttpRequest + @connect domain |
| Add custom CSS | @grant GM_addStyle |
| Access page's window | @grant unsafeWindow |
| Show notifications | @grant GM_notification |
// Disable sandbox (no GM_* except GM_info)
// @grant none
// Cross-origin requests require @connect
// @grant GM_xmlhttpRequest
// @connect api.example.com
// @connect *.googleapis.com
For complete permissions guide, see: header-reference.md
| Value | When Script Runs | Use Case |
|---|---|---|
document-start | Before DOM exists | Block resources, modify globals early |
document-body | When body exists | Early DOM manipulation |
document-end | At DOMContentLoaded | Most scripts - DOM ready |
document-idle | After DOMContentLoaded (default) | Safe default |
context-menu | On right-click menu |
These patterns are used frequently. Brief summaries are below - load patterns.md for full implementations with code examples.
window.onurlchange grant or History API interceptionGM_xmlhttpRequest with @connect domain whitelisting. See also http-requests.mdGM_addStyle to restyle pages or hide elements. See also api-dom-ui.mdGM_setValue/GM_getValue and expose toggle via . See also // @require - Load external scripts
// @require https://code.jquery.com/jquery-3.6.0.min.js#sha256-/xUj+3OJU...
// @require tampermonkey://vendor/jquery.js // Built-in library
// @resource - Preload and inject external CSS
// @resource myCSS https://example.com/style.css // Then: GM_addStyle(GM_getResourceText('myCSS'))
// @grant GM_getResourceText
// @grant GM_addStyle
Userscripts have limitations:
Most limitations have workarounds - see common-pitfalls.md.
Always include in your response:
Before returning a userscript, verify:
*://*/*)For complete security checklist, see: security-checklist.md
Load these on-demand based on user needs:
| File | When to Load |
|---|---|
| Core | |
| header-reference.md | Header syntax - all @tags with examples |
| url-matching.md | @match, @include, @exclude patterns |
| patterns.md | Common implementation patterns with code |
| sandbox-modes.md | Security/isolation execution contexts |
| API | |
| api-sync.md | GM_* synchronous function usage |
Weekly Installs
66
Repository
GitHub Stars
45
First Seen
Jan 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode61
codex60
gemini-cli58
github-copilot57
cursor55
kimi-cli54
GitHub Actions 官方文档查询助手 - 精准解答 CI/CD 工作流问题
47,200 周安装
| Add menu commands | @grant GM_registerMenuCommand |
| Detect URL changes (SPA) | @grant window.onurlchange |
| User-triggered actions |
GM_registerMenuCommand| GM.* promise-based API usage |
| api-storage.md | GM_setValue, GM_getValue, listeners |
| http-requests.md | GM_xmlhttpRequest cross-origin |
| web-requests.md | GM_webRequest interception (Firefox) |
| api-cookies.md | GM_cookie manipulation |
| api-dom-ui.md | addElement, addStyle, unsafeWindow |
| api-tabs.md | getTab, saveTab, openInTab |
| api-audio.md | Mute/unmute tabs |
| Quality |
| common-pitfalls.md | What breaks scripts and workarounds |
| debugging.md | How to debug userscripts |
| browser-compatibility.md | Chrome vs Firefox differences |
| security-checklist.md | Pre-delivery security validation |
| version-numbering.md | Version string comparison rules |