Mercurial > ec-userscripts
view disable-discord-menu-on-links.user.js @ 136:1e64e81370a3
Add nginx-https
author | nanaya <me@nanaya.net> |
---|---|
date | Tue, 27 Feb 2024 01:17:43 +0900 |
parents | 77c5ac0ae047 |
children |
line wrap: on
line source
// ==UserScript== // @name Disable Discord Menu on Links // @namespace https://nanaya.net // @match https://discord.com/* // @grant none // @version 1.0.0 // @author nanaya // @description Disable custom context menu for external links in Discord // @downloadURL https://hg.nanaya.net/ec-userscripts/raw-file/tip/disable-discord-menu-on-links.user.js // ==/UserScript== function disableCustomContextMenu (e) { e.stopPropagation(); } function fix (link) { if (!(link instanceof window.HTMLAnchorElement)) return; if (link.rel.match(/\bnoopener\b/) == null && link.dataset.role !== 'img') return; if (link._ecDisableDiscordMenuOnLinks) return; link._ecDisableDiscordMenuOnLinks = true; link.addEventListener('contextmenu', disableCustomContextMenu); } function run (nodes) { nodes ??= [document.body]; for (const node of nodes) { if (!(node instanceof window.HTMLElement)) continue; fix(node); for (const link of node.querySelectorAll('a[rel~=noopener], a[data-role=img]')) { fix(link); } } } function onMutate (mutations) { for (const mutation of mutations) { run(mutation.addedNodes); } } const observer = new window.MutationObserver(onMutate); observer.observe(document, { childList: true, subtree: true }); run();