Re-enables right click on image and video embeds in Discord, since the new custom context menu update.
当前为
// ==UserScript==
// @name Discord Embed Right Click Enabler
// @namespace https://greasyfork.org
// @version 1.3.3
// @description Re-enables right click on image and video embeds in Discord, since the new custom context menu update.
// @author ScocksBox
// @icon https://i.imgur.com/ZOKp8LH.png
// @include https://discord.com/*
// @license MIT
// @run-at document-end
// @grant none
// ==/UserScript==
/* jshint esversion: 6 */
const selectors = [
".message__80c10 img:not(.avatar__08316):not(.replyAvatar_cea07c)", // image embeds
".message__80c10 video", // video embeds
".message__80c10 .messageAttachment_b97504 a", // download buttons and file links
".message__80c10 .anchor_c8ddc0", // links in message
".message_d8db25 img:not(.avatar__08316):not(.replyAvatar_cea07c)", // images embeds in search
".message_d8db25 video", // video embeds in search
".message_d8db25 .messageAttachment_b97504 a", // download buttons and file links in search
".message_d8db25 .anchor_c8ddc0", // links in search
".originalLink__94d5d" // image links
];
const selectorStr = selectors.join(", ");
var callback = function (mutationsList, observer) {
for (const mutation of mutationsList) {
for (const added of mutation.addedNodes) {
if (added.nodeType !== Node.ELEMENT_NODE) {
continue;
}
if (added.matches(selectorStr)) {
added.addEventListener('contextmenu', function(event) {
event.stopImmediatePropagation();
}, true);
}
const elements = added.querySelectorAll(selectorStr);
for (let i = 0; i < elements.length; i++) {
let el = elements[i];
el.addEventListener('contextmenu', function(event) {
event.stopImmediatePropagation();
}, true);
}
}
}
};
const observer = new MutationObserver(callback);
observer.observe(document.body, { childList: true, subtree: true });