🎉 欢迎访问GreasyFork.Org 镜像站!本镜像站由公众号【爱吃馍】搭建,用于分享脚本。联系邮箱📮

Greasy fork 爱吃馍镜像

Greasy Fork is available in English.

📂 缓存分发状态(共享加速已生效)
🕒 页面同步时间:2026/01/05 07:05:22
🔄 下次更新时间:2026/01/05 08:05:22
手动刷新缓存

Twitter/X Nitter Redirect

Redirect twitter.com and x.com links to a random healthy Nitter instance.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

🚀 安装遇到问题?关注公众号获取帮助

公众号二维码

扫码关注【爱吃馍】

回复【脚本】获取最新教程和防失联地址

// ==UserScript==
// @name         Twitter/X Nitter Redirect
// @version      1.0
// @description  Redirect twitter.com and x.com links to a random healthy Nitter instance.
// @author       yodaluca23
// @license      GNU GPLv3
// @match        *://twitter.com/*
// @match        *://www.twitter.com/*
// @match        *://x.com/*
// @match        *://www.x.com/*
// @grant        GM_xmlhttpRequest
// @namespace http://tampermonkey.net/
// ==/UserScript==

(function() {
    'use strict';

    const staticURL = ''; // Set this to an instance if you always want to use a single Nitter instance instead of fetching from API.

    const apiUrl = 'https://status.d420.de/api/v1/instances';

    const profileURLPattern = /^https?:\/\/(www\.)?(twitter\.com|x\.com)\/[A-Za-z0-9_]+(\/.*)?$/;

    let currentURL = window.location.href;

    function fetchNitterInstance(callback) {
        GM_xmlhttpRequest({
            method: 'GET',
            url: apiUrl,
            onload: function(response) {
                try {
                    const data = JSON.parse(response.responseText);

                    if (!data.hosts || !Array.isArray(data.hosts)) {
                        console.error('Unexpected API response format:', data);
                        return;
                    }

                    const healthyInstances = data.hosts.filter(host => host.healthy && !host.is_bad_host);

                    if (healthyInstances.length > 0) {
                        const randomInstance = healthyInstances[Math.floor(Math.random() * healthyInstances.length)];
                        callback(randomInstance.domain);
                    } else {
                        console.warn('No healthy Nitter instances found.');
                    }
                } catch (error) {
                    console.error('Failed to parse Nitter instance data:', error, response.responseText);
                }
            },
            onerror: function(error) {
                console.error('Error fetching Nitter instances:', error);
            }
        });
    }

    function redirectToNitter(nitterDomain) {
        if (profileURLPattern.test(currentURL)) {
            let newURL = currentURL.replace(/(twitter\.com|x\.com)/, nitterDomain);
            console.log('Redirecting to:', newURL);
            if (newURL !== currentURL) {
                window.location.replace(newURL);
            }
        } else {
            console.log('URL does not match profile pattern, no redirection.');
        }
    }
    if (staticURL.length > 1) {
      redirectToNitter(staticURL);
    } else {
      fetchNitterInstance(redirectToNitter);
    }
})();