Last active
April 29, 2018 20:32
-
-
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.
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 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