Last active
April 2, 2026 10:05
-
-
Save mu-hun/5dd65200448137fca8681cd6ebe2fae9 to your computer and use it in GitHub Desktop.
This userscript should be enable when working on NSFW AdGuardFilters.
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 Blur media elements | |
| // @match *://*/* | |
| // @run-at document-start | |
| // ==/UserScript== | |
| const MEDIA_RE = /thumb|preview|photo|image|img|pic|video|media/i; | |
| const URL_RE = /url\(["']?(.*?)["']?\)/; | |
| const style = document.createElement('style'); | |
| style.textContent = ` | |
| img, video { filter: blur(60px) !important; } | |
| .adg-blur-pseudo::before, | |
| .adg-blur-pseudo::after { filter: blur(40px) !important; } | |
| `; | |
| (document.head ?? document.documentElement).appendChild(style); | |
| function isMedia(str) { | |
| if (!str || str === 'none') return false; | |
| const match = URL_RE.exec(str); | |
| return match ? MEDIA_RE.test(match[1]) : false; | |
| } | |
| const processed = new WeakSet(); | |
| function processEl(el) { | |
| if (!(el instanceof Element) || processed.has(el)) return; | |
| processed.add(el); | |
| const cs = getComputedStyle(el); | |
| if (isMedia(cs.backgroundImage) || isMedia(cs.background)) { | |
| el.style.filter = 'blur(60px)'; | |
| } | |
| const before = getComputedStyle(el, '::before').backgroundImage; | |
| const after = getComputedStyle(el, '::after').backgroundImage; | |
| if (isMedia(before) || isMedia(after)) { | |
| el.classList.add('adg-blur-pseudo'); | |
| } | |
| } | |
| function blurBackgrounds(els) { | |
| els.forEach(processEl); | |
| } | |
| document.addEventListener('DOMContentLoaded', () => { | |
| blurBackgrounds(document.querySelectorAll('*')); | |
| const observer = new MutationObserver((mutations) => { | |
| for (const mutation of mutations) { | |
| mutation.addedNodes.forEach((node) => { | |
| if (node instanceof Element) { | |
| processEl(node); | |
| node.querySelectorAll('*').forEach(processEl); | |
| } | |
| }); | |
| } | |
| }); | |
| 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