// ==UserScript== // @name Open in Discord app // @namespace sebastienbarre // @description Replace "Open in discord" links with Discord app protocol links // @include https://www.midjourney.com/app/* // @run-at document-idle // @version 1.9 // @grant none // @icon https://www.midjourney.com/favicon-32x32.png // ==/UserScript== // INSTALLATION: // - Install Greasemonkey, Tampermonkey, or Violentmonkey (say, https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/) // - Visit https://gist.github.com/sebastienbarre/aa1303724c739bdcb3cd55a3ba03343b/raw/midjourney.user.js // - Confirm your intention to install the userscript // Example of links to handle: // https://discord.com/channels/@me/1007648178033664071/1013814594109710337 // https://discord.com/channels/662267976984297473/995431514080813086/1014024788467011654 // An unofficial list of discord app protocols // https://gist.github.com/ghostrider-05/8f1a0bfc27c7c4509b4ea4e8ce718af0 // Add support for discord:// protocols in buttons #3347 // https://github.com/discord/discord-api-docs/discussions/3347 // Userscript to wait for page to load before executing code techniques? // https://stackoverflow.com/a/47406751/250457 // https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver // https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors // Not the most optimized way, but this will do for now new MutationObserver(check).observe(document, { childList: true, subtree: true }); function check(changes, observer) { // This selector may break if they rewrite their pop-up menu, but that's as specific as possible ATM var menu = document.querySelector('div[id^=headlessui-menu-items-]'); if (menu) { var links = menu.getElementsByTagName('a'); for (var i = 0; i < links.length; i++) { links[i].href = links[i].href.replace( 'https://discord.com/channels/', 'discord://-/channels/', ); links[i].setAttribute('target', '_self'); } } }