Discord Embed Right Click Enabler

Re-enables right click on image and video embeds in Discord, since the new custom context menu update.

  1. // ==UserScript==
  2. // @name Discord Embed Right Click Enabler
  3. // @namespace https://greasyfork.org
  4. // @version 1.3.7
  5. // @description Re-enables right click on image and video embeds in Discord, since the new custom context menu update.
  6. // @author ScocksBox
  7. // @icon https://i.imgur.com/ZOKp8LH.png
  8. // @include https://discord.com/*
  9. // @license MIT
  10. // @run-at document-end
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. /* jshint esversion: 6 */
  15.  
  16. const selectors = [
  17. ".message__5126c img:not(.avatar_c19a55):not(.replyAvatar_c19a55):not(.emoji)", // image embeds
  18. ".message__5126c video", // video embeds
  19. ".message__5126c .anchor_edefb8", // links in message, including buttons
  20. //".message_d5deea .messageAttachment__5dae1 a", // download buttons and file links
  21. //".message__80c10 .attachmentLink", // externally linked attachments
  22. ".message__02a39 img:not(.avatar_c19a55):not(.replyAvatar_c19a55):not(.emoji)", // images embeds in search
  23. ".message__02a39 video", // video embeds in search
  24. ".message__02a39 .anchor_edefb8", // links in search, including buttons
  25. //".message__7e601 .messageAttachment__5dae1 a", // download buttons and file links in search
  26. //".message_d8db25 .attachmentLink", // externally linked attachments in search
  27. ".originalLink_af017a" // image embed links
  28. ];
  29. const selectorStr = selectors.join(", ");
  30.  
  31. var callback = function (mutationsList, observer) {
  32. for (const mutation of mutationsList) {
  33. for (const added of mutation.addedNodes) {
  34. if (added.nodeType !== Node.ELEMENT_NODE) {
  35. continue;
  36. }
  37.  
  38. if (added.matches(selectorStr)) {
  39. added.addEventListener('contextmenu', function(event) {
  40. event.stopImmediatePropagation();
  41. }, true);
  42. }
  43.  
  44. const elements = added.querySelectorAll(selectorStr);
  45. for (let i = 0; i < elements.length; i++) {
  46. let el = elements[i];
  47. el.addEventListener('contextmenu', function(event) {
  48. event.stopImmediatePropagation();
  49. }, true);
  50. }
  51. }
  52. }
  53. };
  54.  
  55. const observer = new MutationObserver(callback);
  56. observer.observe(document.body, { childList: true, subtree: true });