A userscript that adds a repository-search filter panel, saved presets, and a hide-words filter to GitHub. TypeScript + Preact + Vite (vite-plus) + vite-plugin-monkey, entry point src/index.ts, built to dist/github-filter.user.js.
src/
├── index.ts # Bootstrap: migrate storage, inject CSS, mount launcher, start scanner
├── config.ts # IDs, storage keys, selectors, slider scales, and the field schema
├── query.ts # Pure: FormState <-> query parts/URL, preset normalising, hide matcher
├── query.test.ts # Covers build/parse round-trips, ranges, slider scale and legacy presets
├── launcher.ts # Places the launcher in GitHub's own filter sidebar/toolbar
├── launcher.test.ts # Covers native slot discovery and idempotent placement
├── scanner.ts # Hides result rows matching the hide list
├── scanner.test.ts # Covers matching, re-render recovery, and page gating
├── storage.ts # localStorage accessors, preset CRUD, legacy migration
├── styles.ts # The whole stylesheet as one template literal (Primer tokens)
├── icons.tsx # Octicon path registry, <Icon>, and the imperative launcher glyph
└── ui.tsx # Preact: dialog shell, query table, sliders, date ranges, tape, presets
- The field schema is the single source of truth.
KEYWORDS,SORTSandQUALIFIERSinconfig.tsdrive the rendered rows,queryParts, the preset summaries and URL parsing. FormStateis typed, not stringly.repo/langhold the raw comma-separated input;stars/forksare{ min, max }where 0 means unbounded;created/pushedare{ from, to }holdingYYYY-MM-DDor empty.- Preact owns the panel. State is
useState/useMemo, and JSX escapes user-supplied preset names and qualifier values. - The panel opens after state commits.
openPanelupdates builder state and bumpsopenRequest; auseLayoutEffectthen callsshowModal(). - The query tape is derived, not stored.
queryParts(state)returns{ text, kind }parts; the footer renders interactive removal chips andbuildQueryjoins the same parts for copy and search. - Primer tokens, not fixed colors.
--ghf-*variables alias GitHub's own--bgColor-*,--fgColor-*,--borderColor-*and--button-*tokens, so the panel follows the page's light, dark, or auto theme. Hex values are fallbacks for pages that do not expose Primer. SVGs explicitly inherit text/accent colors (fill="currentColor"). - Pure logic is separated and tested.
query.tshas no DOM or network dependency; everything else is glue. - Version and description come from
package.jsonviavite.config.ts.
- Unified Single-Page Architecture. Builder and Presets tabs are eliminated. Presets are stored, rendered as interactive chips (load, run, delete), and created via an inline save field directly on the single page.
- Silky Smooth Logarithmic Sliders. Instead of coarse discrete array notches,
SmoothSlideruses pointer capture (setPointerCapture) and continuous ratio mapping (valToRatio/ratioToVal) to interpolate values across logarithmic space. Natural human quantization steps cleanly through 1, 10, 50, 100, 250, 500, 1k, 5k, 10k, 25k, 50k, 100k without dragging stutter or dead zones. Thumbs track with precision, scale on grab, and support full keyboard ARIA navigation. Keyboard steps go throughstepValue()(value-based, not ratio-based) because the log track compresses the bottom: a fixed ratio delta rounds back to 1 and wedges the thumb.Home/Endstill jump to the open bounds, and a max thumb at 0 means unbounded and sits at the right edge. - Compact Header-Integrated Metric Chips. Stars and Forks feature symmetric quick-chip presets (
1+,10+,100+,1k+and10k+) housed directly in the slider header alongside the live readout, saving vertical height. - React owns the result rows, we don't. GitHub hydrates
[data-testid="results-list"]after the script runs, and rewritesclassNamefrom its own state — which stripsghf-hiddenback off.scanResultsis therefore stateless and recomputed from scratch on every pass rather than tracking rows in aWeakMapor adata-*flag. An attribute survives the re-render and makes a row look handled when it is not. Re-adding a class that is already present mutates nothing, and theMutationObserverwatcheschildListonly, so this cannot loop. The observer is attached todocument.documentElement, notdocument.body: Turbo replaces body content (and a body-scoped observer would silently stop seeing results). Panel-only mutations are ignored, and nav events schedule rescans at 150 ms and 700 ms because Turbo renders before it writes the new URL. - Transient feedback resets itself. Copy reports “Copied”/“Failed” in both the button and an
aria-liveregion, and returns to idle after 1.6 s on either outcome, so a failed clipboard write cannot leave a permanent error. - Row text is walked, not read from
textContent.textContentconcatenates adjacent nodes with no separator, so<a>acme/repo</a><p>wontfix…</p>reads as "repowontfix" and a whole-word match fails at element boundaries.rowText()walks text nodes and joins with a space;innerTextwould be correct too but forces layout on every pass. - Thumb
z-indexand focus follow the active thumb.leadstate raises whichever thumb the user clicked, dragged, or focused via keyboard tab (onFocus). - Interactive query tape chips.
queryParts(state)assignsfieldIdandtokenattributes to parts; clicking×on any tape chip invokesremoveQueryPart(state, part)for instant 1-click filter removal. <dialog>+showModal()provides the focus trap,Eschandling, inert background and top-layer stacking. Follows modern web platform guidance:closedby="any"enables native light dismiss, andoverscroll-behavior: containon both dialog and::backdrop(withoverflow: hidden) prevents scroll chaining to the page underneath.- Mobile Bottom-Sheet Architecture (≤767px).
<dialog>specifies a definite height (height: 85dvh; max-height: 88dvh;) to avoid CSS 2.1 §10.5 indefinite flex height collapse. This keeps header, drag handle, and footer pinned while.ghf-bodyscrolls with touch momentum (-webkit-overflow-scrolling: touch).SmoothSliderhandles pointer interactions across both mouse and touch by only enforcinge.button === 0whene.pointerType === 'mouse'(touch interactions reportbutton === -1).- Mobile slider thumb hit target expands to 42px via
::beforepseudo-element. - Enforces
font-size: 16px !importanton mobile inputs to eliminate iOS Safari viewport auto-zooming. - Auto-focus is disabled on viewports ≤767px (
window.innerWidth > 767) to prevent unwanted virtual keyboard pops upon modal opening. - Modal backdrop dismiss verifies
e.clientX/e.clientYagainstd.getBoundingClientRect()to prevent premature dismissals from inner taps. - Launcher button (
#ghf-fab) is hidden while dialog is open via${F}[aria-expanded="true"], body:has(${P}[open]) ${F} { display: none !important; }.
- The launcher lives in GitHub's chrome, not over it.
findLauncherTarget()reuses native hooks: the[data-testid="filter-button"]toolbar on phones (a full-width row under the search sub-header, or beside the button if there is no sub-header), and the[role="region"][aria-labelledby="search-filters-title"]sidebar on desktop/tablet (above the facet list, directly under “Filter by”). Only the bare/searchlanding page falls back to a floating pill. On results pages with no native slot yet, the launcher is removed rather than floated, so a Turbo restore cannot flash a pill over the page; a bounded 400 ms retry (5 attempts) re-homes it. - One persistent launcher button.
placeLaunchermoves the same#ghf-fabbetween slots and never clones it;placeLauncher/syncLauncherare idempotent so the debounced observer, resize listener and Turbo events can all call them safely. The launcher is hidden outside/search(including/search/) and while the dialog is open.
Release badges (a per-result "latest tag" badge, backed by releases.atom fetching with a cache, fetch pool and rate-limit handling) were removed at the user's request — a request per result row is not worth the rate limiting. migrateLegacyStorage clears the leftover gh-rel-*, ghf:scan and ghf:releases keys. Do not reintroduce without asking.
The scope switch (Code, Issues, PRs, Discussions, Users) and the extension/size filters were removed in v10: every remaining control is a repository qualifier, so buildUrl always sends type=repositories. A v9 preset's leftover q.size/q.ext values are dropped by normalizeState, and a pasted size: or ext: term stays in the free-text field rather than being swallowed.
- Package manager:
bun - Runtime:
preact11.2 (the only dependency) bun install,bun run build,bun run dev,bun run test,bun run tsc,bun run lint,bun run knip,bun run check- GM grants:
GM_registerMenuCommandonly. State is inlocalStorageunder theghf:prefix. - Toolchain:
vite-plus1.7.0,vite-plugin-monkey8.1.1, TypeScript 7.0, Biome 2.6.8, happy-dom 21, Knip 6.