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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Discord Embed Right Click Enabler
// @namespace    https://greasyfork.org
// @version      1.1
// @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-2CShn3 img:not(.avatar-2e8lTP):not(.replyAvatar-sHd2sU)", // image embeds
	".message-2CShn3 video", // video embeds
	".message-2CShn3 .metadataDownload-3IY84h", // video download buttons
	".message-24k8JL img:not(.avatar-2e8lTP):not(.replyAvatar-sHd2sU)", // images embeds in search
	".message-24k8JL video" // video embeds in search
];

var callback = function (mutationsList, observer) {
	let elements = document.querySelectorAll(selectors.join(", "));
	for (let i = 0; i < elements.length; i++) {
		let el = elements[i];
		if (!el.classList.contains("contextmenu-fixed")) {
			el.addEventListener('contextmenu', function(event) {
				event.stopImmediatePropagation();
			}, true);
			el.classList.add("contextmenu-fixed");
		}
	}
};

const observer = new MutationObserver(callback);
observer.observe(document.body, { childList: true, subtree: true });