Discord Embed Right Click Enabler

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

当前为 2022-09-06 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Discord Embed Right Click Enabler
  3. // @namespace https://greasyfork.org
  4. // @version 1.3.1
  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-2CShn3 img:not(.avatar-2e8lTP):not(.replyAvatar-sHd2sU)", // image embeds
  18. ".message-2CShn3 video", // video embeds
  19. ".message-2CShn3 .metadataDownload-3IY84h", // video download buttons
  20. ".message-2CShn3 .attachment-1PZZB2 a", // file download button and link
  21. ".message-24k8JL img:not(.avatar-2e8lTP):not(.replyAvatar-sHd2sU)", // images embeds in search
  22. ".message-24k8JL video", // video embeds in search
  23. ".originalLink-Azwuo9" // image links
  24. ];
  25. const selectorStr = selectors.join(", ");
  26.  
  27. var callback = function (mutationsList, observer) {
  28. for (const mutation of mutationsList) {
  29. for (const added of mutation.addedNodes) {
  30. if (added.nodeType !== Node.ELEMENT_NODE) {
  31. continue;
  32. }
  33.  
  34. if (added.matches(selectorStr)) {
  35. added.addEventListener('contextmenu', function(event) {
  36. event.stopImmediatePropagation();
  37. }, true);
  38. }
  39.  
  40. const elements = added.querySelectorAll(selectorStr);
  41. for (let i = 0; i < elements.length; i++) {
  42. let el = elements[i];
  43. el.addEventListener('contextmenu', function(event) {
  44. event.stopImmediatePropagation();
  45. }, true);
  46. }
  47. }
  48. }
  49. };
  50.  
  51. const observer = new MutationObserver(callback);
  52. observer.observe(document.body, { childList: true, subtree: true });