imgur to rimgo image redirector

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

当前为 2025-09-30 提交的版本,查看 最新版本

// ==UserScript==
// @name         imgur to rimgo image redirector
// @namespace    http://tampermonkey.net/
// @version      2025-09-30-beta
// @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

(function() {
    'use strict';

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

  var eligible = {};

  var broken = [
      "rimgo.proxik.cloud",
      "imgur.010032.xyz",
      "rimgo.aketawi.space",
      "projectsegfau.lt",
      "rimgo.darkness.services",
      "rimgo.totaldarkness.net",
      "rmgur.com",
      "rimgo.quantenzitrone.eu",
      "rimgo.frylo.net",
      "r.opnxng.com", //has anubis check
      "imgur.artemislena.eu", //has anubis check
      "rimgo.fascinated.cc",
      "rimgo.reallyaweso.me",
      "rimgo.thebunny.zone",
      "rimgo.bloat.cat", //has anubis check
  ];// 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 redirectimgs = () => {
      Array.from(document.getElementsByTagName("img")).forEach((img) => {
          const imgsrc = img.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}`;
              img.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)
        redirectimgs()
      } 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);
    }
  });

    const intervalimgs = setInterval(redirectimgs, 5000)

})();