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-17 提交的版本,查看 最新版本

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