imgur to rimgo image redirector

redirects imgur <img> tags to a randomly selected rimgo instance

当前为 2025-10-21 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         imgur to rimgo image redirector
// @namespace    http://tampermonkey.net/
// @version      2025-10-21
// @description  redirects imgur <img> tags to a randomly selected rimgo instance
// @author       infinitysnapz
// @match        *://*/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=imgur.com
// @license     MIT; http://opensource.org/licenses/MIT
// @grant        GM_xmlhttpRequest
// ==/UserScript==

// based on:
//Imgur to Rimgo redirect v0.1.4 by 0b9
//https://gist.github.com/wont-work/e1f00fcc6c44b05a312573379b649afa#file-free-overjoyed-anywhere-you-go-user-js by kopper

(function() {
    'use strict';

    const apiUrl = 'https://rimgo.codeberg.page/api.json';
    const instancediscovery = 'https://rimgo.codeberg.page';

    var eligible = {};

    var broken = [

        "imgur.010032.xyz", // dead domain
        "projectsegfau.lt", // invalid certificate
        "rimgo.totaldarkness.net", // dead domain
        "rmgur.com", // dead domain
        "rimgo.frylo.net", // dead domain
        "rimgo.fascinated.cc", // 404 not found
        "rimgo.reallyaweso.me", // no response
        "imgur.sudovanilla.org", // times out for some reason

        "rimgo.lunar.icu", // 502 bad gateway
        "rimgo.privacyredirect.com", // 502 bad gateway
        // these could be related to the amazon AWS outage..

        "rimgo.darkness.services", // has anubis check
        "r.opnxng.com", // has anubis check
        "imgur.artemislena.eu", // has anubis check
        "rimgo.bloat.cat", // has anubis check
        "imgur.nerdvpn.de", // has anubis check
        "rg.kuuro.net", // has anubis check
        "rimgo.aketawi.space", // has anubis check
        // as amazing as anubis is in the fight against bots and AI, it means we cannot embed images from these sites properly.

        "drgns.space", //under maintenance, will check back later
        //temporary dead domains

        //"rimgo.thebunny.zone",                      //second chance!
        //"rimgo.quantenzitrone.eu",                  //second chance!
        //"rimgo.proxik.cloud",                       //second chance!
        //second chancers, domains that were down, but are back now!

    ];// soo many broken instances wtf

    const generateHash = (string) => { // hash, to allow us to cache images easier and reduce load on
        let hash = 0;
        for (const char of string) {
            hash = (hash << 5) - hash + char.charCodeAt(0);
            hash |= 0; // Constrain to 32bit integer
        }
        return hash;
    };

    const observer = new MutationObserver((mutations) => {
        for (const mutation of mutations) {
            for (const node of mutation.addedNodes) {
                walk(node);
            }
        }
    });

    /**
 * @param {Node} root
 */
    function walk(root) {
        if (!root.ownerDocument) throw "assertion falied: no owner document";

        const walker = root.ownerDocument.createNodeIterator(
            root,
            NodeFilter.SHOW_ELEMENT,
            (node) => {
                if (node.nodeType == Node.ELEMENT_NODE && node.shadowRoot) {return NodeFilter.FILTER_ACCEPT};

                if (node.nodeName == "STYLE" || node.nodeName == "SCRIPT") {return NodeFilter.FILTER_REJECT};

                if (node.nodeName == "IMG"){return NodeFilter.FILTER_ACCEPT};


                return NodeFilter.FILTER_SKIP;
            });

        /** @type {Node|null} */let node;
        node = walker.nextNode();
        while ((node = walker.nextNode())) {
            if (node.shadowRoot) {
                for (const child of node.shadowRoot.children) {
                    if (child.nodeName == "STYLE" || child.nodeName == "SCRIPT") continue;
                    walk(child);
                }

                observer.observe(node.shadowRoot, observerConfig);
                continue;
            };

            if (!node.nodeName == "IMG") continue;
            redirectImg(node);

        }
    }

    const observerConfig = {
        childList: true,
        subtree: true,
    };

    const redirectImg = (elem) => {
          const imgsrc = elem.src
          if (/https?:\/\/(\w+\.)?imgur.com\/(\w*)+(\.[a-zA-Z]{3,4})/.test(imgsrc)){
              const path = imgsrc.substring(imgsrc.indexOf("/", 8));
              const instanceUrl = eligible[Math.abs(generateHash(path) % eligible.length)].url
              const newUrl = `${instanceUrl}/${path.startsWith("/") ? path.slice(1) : path}`;
              elem.src = newUrl;
          };
    };

    GM_xmlhttpRequest({
        method: "GET",
        url: apiUrl,
        onload: function (response) {
            try {
                const data = JSON.parse(response.responseText);
                eligible = data.clearnet.filter(inst => inst.note.includes("✅ Data not collected"));
                eligible = eligible.filter(inst => !(new RegExp( '\\b' + broken.join('\\b|\\b') + '\\b') ).test(inst.url) );
                console.log(eligible)
                walk(document.body)
                observer.observe(document.body, observerConfig);
            } catch (e) {
                console.error("JSON parsing failed, no image redirecting will occur.", e);
            }
        },
        onerror: function (err) {
            console.error("Request failed, no image redirecting will occur.", err);
        }
    });

})();