Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Reveal Spoiler Images (Dynamic)
- // @namespace http://tampermonkey.net/
- // @version 1.1
- // @description Replaces spoiler images with real thumbnails even on auto-updating sites
- // @match *://*/*
- // @grant none
- // ==/UserScript==
- (function () {
- 'use strict';
- function replaceSpoilerImages(root = document) {
- const links = root.querySelectorAll('a.imgLink');
- links.forEach(link => {
- const img = link.querySelector('img');
- if (!img) return;
- // Already processed
- if (img.dataset.spoilerHandled === 'true') return;
- if (img.src.includes('/spoiler.png')) {
- const href = link.getAttribute('href');
- const filename = href.split('/').pop();
- const thumbSrc = `/.media/${filename}`;
- img.src = thumbSrc;
- img.dataset.spoilerHandled = 'false'; // Prevent reprocessing
- }
- });
- }
- // Run on initial load
- replaceSpoilerImages();
- // Set up MutationObserver to watch for new nodes
- const observer = new MutationObserver(mutations => {
- for (const mutation of mutations) {
- mutation.addedNodes.forEach(node => {
- if (node.nodeType === 1) { // ELEMENT_NODE
- // If the node itself might be a spoiler, or contains some
- replaceSpoilerImages(node);
- }
- });
- }
- });
- observer.observe(document.body, {
- childList: true,
- subtree: true
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement