Skip to content

Instantly share code, notes, and snippets.

@sebastienbarre
Last active May 16, 2023 06:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sebastienbarre/aa1303724c739bdcb3cd55a3ba03343b to your computer and use it in GitHub Desktop.
Save sebastienbarre/aa1303724c739bdcb3cd55a3ba03343b to your computer and use it in GitHub Desktop.
Midjourney Greasemonkey User Script

Installation

  1. make sure to have Greasemonkey/Tampermonkey/Violentmonkey installed
  2. click here to install the midjourney.user.js userscript below.
  3. confirm your intention to install the userscript.
  4. the "Open in discord" links should now open in your Discord app.
// ==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