Discord Embed Right Click Enabler

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

Ajankohdalta 30.3.2024. Katso uusin versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Discord Embed Right Click Enabler
// @namespace    https://greasyfork.org
// @version      1.3.5
// @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_ccca67 img:not(.avatar__08316):not(.replyAvatar__4ba85)", // image embeds
	".message_ccca67 video", // video embeds
	".message_ccca67 .messageAttachment__5dae1 a", // download buttons and file links
	".message_ccca67 .anchor_c8ddc0", // links in message
  //".message__80c10 .attachmentLink", // externally linked attachments
	".message__7e601 img:not(.avatar__08316):not(.replyAvatar__4ba85)", // images embeds in search
	".message__7e601 video", // video embeds in search
	".message__7e601 .messageAttachment__5dae1 a", // download buttons and file links in search
	".message__7e601 .anchor_c8ddc0", // links in search
  //".message_d8db25 .attachmentLink", // externally linked attachments in search
	".originalLink__0d99e" // image embed 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 });