Skip to content

Instantly share code, notes, and snippets.

@m0n5t3r
Last active November 29, 2022 07:50
Show Gist options
  • Save m0n5t3r/fdd267c81b4e4059a4b409890a019fa3 to your computer and use it in GitHub Desktop.
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/
// ==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