Last active
November 29, 2022 07:50
-
-
Save m0n5t3r/fdd267c81b4e4059a4b409890a019fa3 to your computer and use it in GitHub Desktop.
Random nitter redirect userscript; tested with violentmonkey on brave, gets instance data from https://xnaas.github.io/nitter-instances/
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== | |
// @description Redirects Twitter URLs to nitter | |
// @name Nitter Redirect | |
// @namespace Backend | |
// @downloadURL https://gist.github.com/m0n5t3r/fdd267c81b4e4059a4b409890a019fa3/raw/nitter-redirect.userscript.js | |
// @include https://twitter.com/* | |
// @version 1.0 | |
// @run-at document-start | |
// @inject-into content | |
// @grant none | |
// ==/UserScript== | |
// prevent twitter content from loading | |
var newDoc = document.implementation.createHTMLDocument (""), | |
h1 = document.createElement("h1"); | |
h1.innerText = "Redirecting, please wait..."; | |
newDoc.body.appendChild(h1); | |
document.replaceChild (document.importNode(newDoc.documentElement, true), document.documentElement); | |
document.close(); | |
const blacklist = [ | |
]; | |
function find_parameter(name) { | |
var result = null, | |
tmp = []; | |
location.search | |
.substr(1) | |
.split("&") | |
.forEach((item) => { | |
tmp = item.split("="); | |
if (tmp[0] === name) result = decodeURIComponent(tmp[1]); | |
}); | |
return result; | |
} | |
// pick a random instance that is up | |
fetch("https://raw.githubusercontent.com/xnaas/nitter-instances/master/history/summary.json").then((response) => { | |
response.json().then((instances) => { | |
var filtered, domain, idx, a; | |
console.log(instances); | |
filtered = instances.filter((i) => { | |
if(blacklist.includes(i.name)) { | |
return false; | |
} | |
return i.status == "up" && i.timeDay <= 500; | |
}).map((i) => { return i.name }); | |
idx = Math.floor(Math.random() * filtered.length); | |
domain = filtered[idx]; | |
a = window.location.href.replace(/twitter\.com/, domain).replace('/shorts/', '/watch?v='); | |
window.location.replace(a); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment