Advertisement
Guest User

Untitled

a guest
Apr 20th, 2025
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Reveal Spoiler Images (Dynamic)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Replaces spoiler images with real thumbnails even on auto-updating sites
  6. // @match *://*/*
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (function () {
  11. 'use strict';
  12.  
  13. function replaceSpoilerImages(root = document) {
  14. const links = root.querySelectorAll('a.imgLink');
  15.  
  16. links.forEach(link => {
  17. const img = link.querySelector('img');
  18. if (!img) return;
  19.  
  20. // Already processed
  21. if (img.dataset.spoilerHandled === 'true') return;
  22.  
  23. if (img.src.includes('/spoiler.png')) {
  24. const href = link.getAttribute('href');
  25. const filename = href.split('/').pop();
  26. const thumbSrc = `/.media/${filename}`;
  27. img.src = thumbSrc;
  28. img.dataset.spoilerHandled = 'false'; // Prevent reprocessing
  29. }
  30. });
  31. }
  32.  
  33. // Run on initial load
  34. replaceSpoilerImages();
  35.  
  36. // Set up MutationObserver to watch for new nodes
  37. const observer = new MutationObserver(mutations => {
  38. for (const mutation of mutations) {
  39. mutation.addedNodes.forEach(node => {
  40. if (node.nodeType === 1) { // ELEMENT_NODE
  41. // If the node itself might be a spoiler, or contains some
  42. replaceSpoilerImages(node);
  43. }
  44. });
  45. }
  46. });
  47.  
  48. observer.observe(document.body, {
  49. childList: true,
  50. subtree: true
  51. });
  52. })();
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement