Discord Embed Right Click Enabler

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

Versione datata 27/06/2024. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         Discord Embed Right Click Enabler
// @namespace    https://greasyfork.org
// @version      1.3.6
// @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_d5deea img:not(.avatar_ec86aa):not(.replyAvatar_ec86aa)", // image embeds
	".message_d5deea video", // video embeds
	".message_d5deea .anchor_af404b", // links in message, including buttons
	//".message_d5deea .messageAttachment__5dae1 a", // download buttons and file links
  //".message__80c10 .attachmentLink", // externally linked attachments
	".message_ddc613 img:not(.avatar_ec86aa):not(.replyAvatar_ec86aa)", // images embeds in search
	".message_ddc613 video", // video embeds in search
	".message_ddc613 .anchor_af404b", // links in search, including buttons
	//".message__7e601 .messageAttachment__5dae1 a", // download buttons and file links in search
  //".message_d8db25 .attachmentLink", // externally linked attachments in search
	".originalLink_d4597d" // 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 });