Imgur to Rimgo redirect

Redirect Imgur links to a random Rimgo instance

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Imgur to Rimgo redirect
// @namespace    0b9
// @version      0.1.4
// @description  Redirect Imgur links to a random Rimgo instance
// @author       0b9
// @match        https://imgur.com/*
// @match        https://i.imgur.com/*
// @match        https://imgur.io/*
// @match        https://*.imgur.io/*
// @exclude      https://imgur.com/user/*
// @exclude      https://imgur.com/signin
// @exclude      https://imgur.com/register
// @exclude      https://imgur.com/arcade
// @exclude      https://imgur.com/upload
// @exclude      https://imgur.com/meme-generator
// @exclude      https://imgur.com/privacy
// @exclude      https://imgur.com/rules
// @exclude      https://imgur.com/emerald
// @exclude      https://imgur.com/ccpa
// @exclude      https://imgur.com/tos
// @exclude      https://imgur.com/about
// @exclude      https://imgur.com/apps
// @icon         data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='512' height='512'%3E%3Cpath d='M349.15 398.825v-250m-235.975 13.992h250' fill='none' stroke='%23000' stroke-width='28'/%3E%3Ccircle cx='364.039' cy='147.961' r='34.785' fill='%231e88e5'/%3E%3C/svg%3E
// @grant        GM_xmlhttpRequest
// @connect      rimgo.codeberg.page
// ==/UserScript==

(function () {
  'use strict';

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

  const redirectTo = (instanceUrl) => {
    const path = window.location.href.substring(window.location.href.indexOf("/", 8));
    const newUrl = `${instanceUrl}/${path.startsWith("/") ? path.slice(1) : path}`;
    window.location.replace(newUrl);
  };

  GM_xmlhttpRequest({
    method: "GET",
    url: apiUrl,
    onload: function (response) {
      try {
        const data = JSON.parse(response.responseText);
        const eligible = data.clearnet.filter(inst => inst.note.includes("✅ Data not collected"));
        const instance = eligible.length
          ? eligible[Math.floor(Math.random() * eligible.length)].url
          : instancediscovery;
        redirectTo(instance);
      } catch (e) {
        console.error("JSON parsing failed, redirecting to Rimgo instace list page", e);
        redirectTo(instancediscovery);
      }
    },
    onerror: function (err) {
      console.error("Request failed, redirecting to Rimgo instace list page", err);
      redirectTo(instancediscovery);
    }
  });
})();