Discord Image Unwrapper (Obfuscation-Resistant)

Removes image wrappers on Discord.com regardless of class obfuscation, useful when opening images

  1. // ==UserScript==
  2. // @name Discord Image Unwrapper (Obfuscation-Resistant)
  3. // @namespace https://greasyfork.org/en/scripts/533235-discord-image-unwrapper-obfuscation-resistant
  4. // @version 1.1
  5. // @description Removes image wrappers on Discord.com regardless of class obfuscation, useful when opening images
  6. // @author Cragsand
  7. // @license MIT
  8. // @match *://discord.com/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function unwrapImages() {
  16. const candidates = document.querySelectorAll('div[class*="imageWrapper_"]');
  17. candidates.forEach(wrapper => {
  18. const classList = Array.from(wrapper.classList);
  19. const hasImageWrapper = classList.some(cls => cls.startsWith('imageWrapper_'));
  20. const hasMedia = classList.some(cls => cls.startsWith('media_'));
  21.  
  22. if (hasImageWrapper && hasMedia && !wrapper.dataset.unwrapped) {
  23. const img = wrapper.querySelector('img');
  24. if (img) {
  25. wrapper.dataset.unwrapped = "true";
  26. const imgClone = img.cloneNode(true);
  27. wrapper.replaceWith(imgClone);
  28. }
  29. }
  30. });
  31. }
  32.  
  33. // Observe changes to the DOM
  34. const observer = new MutationObserver(() => unwrapImages());
  35. observer.observe(document.body, { childList: true, subtree: true });
  36.  
  37. // Initial run
  38. unwrapImages();
  39. })();