Automatic Nitter Quota & Error Redirector

Automatically redirects to another Nitter instance if the one you're directed to has reached its rate limit/quota or has an error.

目前為 2024-09-07 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Automatic Nitter Quota & Error Redirector
// @namespace    happyviking
// @version      1.0.0
// @grant        none
// @run-at       document-end
// @license      MIT
// @description  Automatically redirects to another Nitter instance if the one you're directed to has reached its rate limit/quota or has an error.
// @icon         https://upload.wikimedia.org/wikipedia/commons/thumb/e/ed/Nitter_logo.svg/1024px-Nitter_logo.svg.png
// @author       HappyViking

// <<INSTANCES START HERE>>
// @match nitter.com/*
// <<INSTANCES END HERE>>

// ==/UserScript==

function tryNewInstance(messageHolder) {
    const addedMessage = document.createElement("p")
    addedMessage.textContent = "Redirecting you to new instance..."
    messageHolder.appendChild(addedMessage)
    location.replace('https://farside.link/nitter/' + window.location.pathname + window.location.search);
}

function checkForRateLimit() {
    const errorPanel = document.getElementsByClassName("error-panel").item(0)
    if (!errorPanel) return;
    const errorMessage = errorPanel.querySelector("span")?.innerHTML
    if (!errorMessage) return
    if (errorMessage.includes("Instance has been rate limited.")) {
        tryNewInstance(errorPanel)
    }
}

function checkFor429() {
    const centerPanel = document.querySelector("center")
    if (!centerPanel) return
    const errorMessage = centerPanel.querySelector("h1")?.innerHTML
    if (!errorMessage) return
    if (errorMessage.includes("429 Too Many Requests")) {
        tryNewInstance(centerPanel)
    }
}

checkForRateLimit()
checkFor429()