Created
July 10, 2026 14:59
-
-
Save tijnjh/b905d4c855375d245222d448930b11d6 to your computer and use it in GitHub Desktop.
slop detector userscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ==UserScript== | |
| // @name Highlight Em Dashes | |
| // @namespace https://imjonas.nl/ | |
| // @version 1.0 | |
| // @description Highlights every em dash on every page | |
| // @match *://*/* | |
| // @run-at document-end | |
| // ==/UserScript== | |
| (() => { | |
| const HIGHLIGHT_CLASS = "emdash-highlight"; | |
| const style = document.createElement("style"); | |
| style.textContent = ` | |
| .${HIGHLIGHT_CLASS} { | |
| background: yellow; | |
| color: black; | |
| border-radius: 2px; | |
| padding: 0 2px; | |
| font-weight: bold; | |
| } | |
| `; | |
| document.head.appendChild(style); | |
| function highlightEmDashes(root = document.body) { | |
| const walker = document.createTreeWalker( | |
| root, | |
| NodeFilter.SHOW_TEXT, | |
| { | |
| acceptNode(node) { | |
| if (!node.nodeValue.includes("—")) return NodeFilter.FILTER_REJECT; | |
| const parent = node.parentElement; | |
| if (!parent) return NodeFilter.FILTER_REJECT; | |
| const ignoredTags = ["SCRIPT", "STYLE", "TEXTAREA", "INPUT"]; | |
| if (ignoredTags.includes(parent.tagName)) { | |
| return NodeFilter.FILTER_REJECT; | |
| } | |
| if (parent.closest(`.${HIGHLIGHT_CLASS}`)) { | |
| return NodeFilter.FILTER_REJECT; | |
| } | |
| return NodeFilter.FILTER_ACCEPT; | |
| } | |
| } | |
| ); | |
| const nodes = []; | |
| while (walker.nextNode()) { | |
| nodes.push(walker.currentNode); | |
| } | |
| for (const node of nodes) { | |
| const fragment = document.createDocumentFragment(); | |
| for (const part of node.nodeValue.split("—")) { | |
| fragment.append(document.createTextNode(part)); | |
| const span = document.createElement("span"); | |
| span.className = HIGHLIGHT_CLASS; | |
| span.textContent = "—"; | |
| fragment.append(span); | |
| } | |
| fragment.lastChild?.remove(); | |
| node.replaceWith(fragment); | |
| } | |
| } | |
| highlightEmDashes(); | |
| const observer = new MutationObserver((mutations) => { | |
| for (const mutation of mutations) { | |
| for (const node of mutation.addedNodes) { | |
| if (node.nodeType === Node.TEXT_NODE) { | |
| highlightEmDashes(node.parentElement); | |
| } else if (node.nodeType === Node.ELEMENT_NODE) { | |
| highlightEmDashes(node); | |
| } | |
| } | |
| } | |
| }); | |
| observer.observe(document.body, { | |
| childList: true, | |
| subtree: true | |
| }); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment