$npx -y skills add henkisdabro/wookstar-claude-plugins --skill tampermonkeyWrite and debug Tampermonkey userscripts for browser automation, page modification, and web enhancement. Use whenever the user mentions userscripts, Tampermonkey, Greasemonkey, Violentmonkey, or wants to write a script that runs on a website - even if they don't say 'userscript'
| 1 | # Tampermonkey Userscript Development |
| 2 | |
| 3 | Expert guidance for writing Tampermonkey userscripts - browser scripts that modify web pages, automate tasks, and enhance browsing experience. |
| 4 | |
| 5 | ## Quick Start Template |
| 6 | |
| 7 | **JavaScript (simple scripts with no GM.* APIs)** |
| 8 | |
| 9 | ```javascript |
| 10 | // ==UserScript== |
| 11 | // @name My Script Name // <- CUSTOMISE: Unique script name |
| 12 | // @namespace https://example.com/scripts/ // <- CUSTOMISE: Your unique namespace |
| 13 | // @version 1.0.0 // <- INCREMENT on updates |
| 14 | // @description Brief description of the script // <- CUSTOMISE: What it does |
| 15 | // @author Your Name // <- CUSTOMISE: Your name |
| 16 | // @match https://example.com/* // <- CUSTOMISE: Target URL pattern |
| 17 | // @grant none // <- ADD permissions as needed |
| 18 | // @run-at document-idle // <- ADJUST timing if needed |
| 19 | // ==/UserScript== |
| 20 | |
| 21 | (function() { |
| 22 | 'use strict'; |
| 23 | // Your code here |
| 24 | })(); |
| 25 | ``` |
| 26 | |
| 27 | **Modern (async/await - recommended when using GM.* APIs)** |
| 28 | |
| 29 | ```javascript |
| 30 | // ==UserScript== |
| 31 | // @name My Script Name |
| 32 | // @namespace https://example.com/scripts/ |
| 33 | // @version 1.0.0 |
| 34 | // @description Brief description of the script |
| 35 | // @author Your Name |
| 36 | // @match https://example.com/* |
| 37 | // @grant GM.getValue |
| 38 | // @grant GM.setValue |
| 39 | // @run-at document-idle |
| 40 | // ==/UserScript== |
| 41 | |
| 42 | (async () => { |
| 43 | 'use strict'; |
| 44 | // Async entry point — use await with GM.* APIs |
| 45 | const setting = await GM.getValue('myKey', 'default'); |
| 46 | console.log('Script loaded, setting:', setting); |
| 47 | })(); |
| 48 | ``` |
| 49 | |
| 50 | **TypeScript:** Add `@types/tampermonkey` for full type safety. See [typescript.md](references/typescript.md). |
| 51 | |
| 52 | --- |
| 53 | |
| 54 | ## Essential Header Tags |
| 55 | |
| 56 | | Tag | Required | Purpose | Example | |
| 57 | |-----|----------|---------|---------| |
| 58 | | `@name` | Yes | Script name (supports i18n with `:locale`) | `@name My Script` | |
| 59 | | `@namespace` | Recommended | Unique identifier namespace | `@namespace https://yoursite.com/` | |
| 60 | | `@version` | Yes* | Version for updates (*required for auto-update) | `@version 1.2.3` | |
| 61 | | `@description` | Recommended | What the script does | `@description Enhances page layout` | |
| 62 | | `@match` | Yes** | URLs to run on (**or @include) | `@match https://example.com/*` | |
| 63 | | `@grant` | Situational | API permissions (use `none` for no GM_* APIs) | `@grant GM_setValue` | |
| 64 | | `@run-at` | Optional | When to inject (default: `document-idle`) | `@run-at document-start` | |
| 65 | | `@run-in` | Optional | Limit to normal or incognito tabs, or Firefox containers (v5.3+) | `@run-in normal-tabs` | |
| 66 | |
| 67 | **For complete header documentation, see:** [header-reference.md](references/header-reference.md) |
| 68 | |
| 69 | --- |
| 70 | |
| 71 | ## URL Matching Quick Reference |
| 72 | |
| 73 | ```javascript |
| 74 | // Exact domain // @match https://example.com/* |
| 75 | // All subdomains // @match https://*.example.com/* |
| 76 | // HTTP and HTTPS // @match *://example.com/* |
| 77 | // Exclude paths (with @match) // @exclude https://example.com/admin/* |
| 78 | ``` |
| 79 | |
| 80 | **For advanced patterns (regex, @include, specific paths), see:** [url-matching.md](references/url-matching.md) |
| 81 | |
| 82 | --- |
| 83 | |
| 84 | ## @grant Permissions Quick Reference |
| 85 | |
| 86 | | You Need To... | Grant This | |
| 87 | |----------------|------------| |
| 88 | | Store persistent data | `@grant GM_setValue` + `@grant GM_getValue` | |
| 89 | | Make cross-origin requests | `@grant GM_xmlhttpRequest` + `@connect domain` | |
| 90 | | Add custom CSS | `@grant GM_addStyle` | |
| 91 | | Access page's window | `@grant unsafeWindow` | |
| 92 | | Show notifications | `@grant GM_notification` | |
| 93 | | Add menu commands | `@grant GM_registerMenuCommand` | |
| 94 | | Detect URL changes (SPA) | `@grant window.onurlchange` | |
| 95 | | Batch read/write settings (v5.3+) | `@grant GM.getValues` + `@grant GM.setValues` | |
| 96 | | Mute/unmute tab audio | `@grant GM_audio` | |
| 97 | |
| 98 | ```javascript |
| 99 | // Disable sandbox (no GM_* except GM_i |