Skip to content

Instantly share code, notes, and snippets.

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 joachimesque/057adac4741ea722f78e55116b35ceca to your computer and use it in GitHub Desktop.
Save joachimesque/057adac4741ea722f78e55116b35ceca to your computer and use it in GitHub Desktop.
Transforms @mention@twitter.com to a bona fide link to Twitter in the Mastodon web interface.
// ==UserScript==
// @name Twitter mentions linker for Mastodon
// @description Transforms @mention@twitter.com to a bona fide link to Twitter in the Mastodon web interface.
// @include https://boitam.eu/*
// ==/UserScript==
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
var nodes = Array.prototype.slice.call(mutation.addedNodes);
nodes.forEach(function(node) {
if (node.parentElement.classList.contains("detailed-status__wrapper") || node.parentElement.classList.contains("item-list")) {
node.parentElement.querySelectorAll(".status__content").forEach(function(e){ e.innerHTML = e.innerHTML.replace(/(@(\w{1,50})@twitter\.com)\b/gi, function(m, a, b){ return "<a href='https://twitter.com/" + b + "'>" + a + "</a>" })})
}
});
});
});
observer.observe(document.querySelector(".app-body"), {
childList: true,
subtree: true,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment