The idea
Most websites have something worth changing: a cookie banner, a sidebar nobody uses, text that's too small, a bug that never gets fixed. Tampermonkey and Stylus can change them, but they're two separate tools, and writing a selector by hand is the slow part. Site Patcher keeps CSS and JavaScript rules together in one side panel and takes the slow part out: point at an element and it writes the selector, or describe the change and it drafts the rule for you to review.
Implementation
- A Manifest V3 extension built with WXT, React and TypeScript for Chromium browsers and Firefox 136+, with the whole interface in the browser's side panel.
- CSS rules become constructed stylesheets applied from document_start in every frame. They cascade after the page's own styles and can reach into shadow DOM, including closed roots and components that upgrade late.
- JavaScript rules run through the userScripts API, each in its own scope: in an isolated world by default, or in the page's own context when a rule needs the site's variables.
- Script registrations are kept in sync with a diff behind a lock, so quick toggles or edits from two windows never leave stale scripts behind.
- A CodeMirror editor with live preview: CSS changes show on the current tab as you type and revert if you leave without saving.
- Ask AI uses Chrome's on-device Prompt API where it's available, and otherwise writes a self-contained prompt for any chatbot and parses the reply back into a rule.
- Imports Tampermonkey and Greasemonkey userscripts, Stylus styles and Stylus backups, with a compatibility subset of the GM API.
Challenges
- Writing selectors that survive redesigns: the picker skips auto-generated class names and escapes Tailwind-style ones.
- Getting styles in place before the page's own scripts run, with no flash, and keeping them working across single-page-app navigation on sites like YouTube, Reddit and GitHub.
- Beating the site's own CSS without needing !important in every rule.
- Importing userscripts safely: a script whose exclusions can't be converted is imported switched off, so it never runs where its author excluded it.
Result
Version 0.2.0 handles CSS and JavaScript rules with several site patterns and exclusions each, point-and-click hiding, AI drafting, imports and a toolbar badge that counts the rules on the current tab. Vitest unit tests and Playwright end-to-end tests against a local fixture server run in GitHub Actions, and it builds for Chrome and Firefox; it isn't on the browser stores yet.
Gallery
The Side Panel
- This page: the rules that apply to the current site, and quick ways to add one
- All rules: every rule, grouped by site, with search
- Ask AI: describe a change and get a rule to review
Rule Options
- Several site patterns per rule, with exclusions
- Inside iframes and inside shadow DOM
- When a script runs: document start, end or idle
- Isolated or page context for JavaScript
- Run again on in-app navigation
