Discord Embed Right Click Enabler

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

当前为 2022-04-03 提交的版本,查看 最新版本

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