- make sure to have Greasemonkey/Tampermonkey/Violentmonkey installed
- click here to install the
midjourney.user.js
userscript below. - confirm your intention to install the userscript.
- the "Open in discord" links should now open in your Discord app.
Last active
May 16, 2023 06:10
-
-
Save sebastienbarre/aa1303724c739bdcb3cd55a3ba03343b to your computer and use it in GitHub Desktop.
Midjourney Greasemonkey User Script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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.githubusercontent.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'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment