Mastodon link changer
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 Link changer | |
// @namespace https://github.com/Kjwon15/mastodon-link-change | |
// @updateURL https://gist.githubusercontent.com/Kjwon15/33c6e32279bf3c40868db41741a24c0a/raw/mastodon_link_changer.user.js | |
// @version 0.2 | |
// @description Change link on mastodon | |
// @author Kjwon15 | |
// @match https://*/web/* | |
// @grant none | |
// ==/UserScript== | |
function patchLink() { | |
document.addEventListener('click', (event) => { | |
let target = event.target; | |
while (target.parentNode) { | |
if (target.nodeName === 'A') break; | |
target = target.parentNode; | |
} | |
if (target === document) return; | |
const url = new URL(target.href); | |
switch (url.host) { | |
case 'youtube.com': | |
case 'youtu.be': | |
url.host = 'invidio.us'; | |
break; | |
case 'twitter.com': | |
case 'mobile.twitter.com': | |
url.host = 'nitter.net'; | |
break; | |
default: | |
return; | |
} | |
event.preventDefault(); | |
window.open(url.href); | |
}); | |
} | |
window.addEventListener('load', patchLink); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment