Discord Embed Right Click Enabler

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

目前為 2022-02-26 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Discord Embed Right Click Enabler
  3. // @namespace https://greasyfork.org
  4. // @version 1.2
  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.  
  25. var callback = function (mutationsList, observer) {
  26. let elements = document.querySelectorAll(selectors.join(", "));
  27. for (let i = 0; i < elements.length; i++) {
  28. let el = elements[i];
  29. if (!el.classList.contains("contextmenu-fixed")) {
  30. el.addEventListener('contextmenu', function(event) {
  31. event.stopImmediatePropagation();
  32. }, true);
  33. el.classList.add("contextmenu-fixed");
  34. }
  35. }
  36. };
  37.  
  38. const observer = new MutationObserver(callback);
  39. observer.observe(document.body, { childList: true, subtree: true });