jaidedctrl / Nitterize

// ==UserScript==
// @name         Nitterize
// @description  Replace Twitter links with links to a Nitter instance.
// @author       jaidedctrl
// @license      GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @match        *://*
// @run-at       document-end
// ==/UserScript==

// !! REPLACE HERE TO CHANGE NITTER INSTANCE
var nitterInstance = "https://nitter.net";
 
var url = window.location.href;
if ( url.match("twitter.com") == null ) {
	var links = document.querySelectorAll( "a" );

	for ( var i = 0; i < links.length; i++ ) {
		var href = links[i].getAttribute( "href" );
		if ( href.match( "twitter.com" ) != null ) {
			href = href.replace( /.*twitter.com/, nitterInstance );
			links[i].setAttribute( "href", href );
		}
	}
}