Created
December 9, 2022 16:34
-
-
Save Veticia/35fb049f9f749af77a7e2d7cf892db61 to your computer and use it in GitHub Desktop.
Convert twitter URLs to Nitter URLs
This file contains hidden or 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 links To Nitter | |
// @namespace brazenvoid | |
// @description Convert twitter URLs to Nitter URLs | |
// @author brazenvoid | |
// @include * | |
// @exclude https://twitter.com/* | |
// @run-at document-end | |
// ==/UserScript== | |
const NITTER_URL = 'unofficialbird.com' | |
const TWITTER_URL = 'twitter.com' | |
function redirectToNitter () { | |
document.querySelectorAll('a[href*="'+ TWITTER_URL +'"]').forEach((element) => { | |
element.href = element.href.replace(TWITTER_URL, NITTER_URL) | |
element.textContent = element.textContent.replace(TWITTER_URL, NITTER_URL) | |
}) | |
} | |
(new MutationObserver((mutations) => { | |
let runCheck = false | |
for (let mutation of mutations) { | |
if (mutation.addedNodes.length || mutation.attributeName === 'href') { | |
runCheck = true | |
break | |
} | |
} | |
if (runCheck) { | |
redirectToNitter() | |
} | |
})).observe(document.querySelector('body'), {attributeFilter: ['href'], childList: true, subtree: true}) | |
redirectToNitter() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment