Imgur Mirror

Switches all imgur links to the mirror site http://kageurufu.net/imgur

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Imgur Mirror
// @namespace    https://greasyfork.org/users/649
// @version      1.1.7
// @description  Switches all imgur links to the mirror site http://kageurufu.net/imgur
// @author       Adrien Pyke
// @include      http*
// @require      https://cdn.jsdelivr.net/gh/fuzetsu/userscripts@ec863aa92cea78a20431f92e80ac0e93262136df/wait-for-elements/wait-for-elements.js
// @grant        none
// ==/UserScript==

(() => {
  'use strict';

  const regex =
    /imgur\.com\/(?!a\/|gallery\/)(?:r\/[a-z0-9_]+\/)?([a-z0-9]+)(\.+[a-z0-9]+)?/iu;
  const extensions = [
    '.jpg',
    '.jpeg',
    '.png',
    '.gif',
    '.gifv',
    '.webm',
    '.mp4'
  ];

  const getNewLink = function (imgurLink, useGif) {
    const match = imgurLink.match(regex);
    if (match) {
      const file = match[1];
      let extension = match[2].toLowerCase();
      if (!extension || !extensions.includes(extension)) {
        extension = '.png';
      } else if (
        extension === '.gifv' ||
        extension === '.gif' ||
        extension === '.webm'
      ) {
        extension = '.mp4';
      }
      if (useGif && extension === '.mp4') {
        extension = '.gif';
      }
      return `http://kageurufu.net/imgur/?${file + extension}`;
    } else {
      return null;
    }
  };

  waitForElems({
    sel: 'img,a',
    onmatch(node) {
      const isImg = node.nodeName === 'IMG';
      const prop = isImg ? 'src' : 'href';
      const newLink = getNewLink(node[prop], isImg);
      if (newLink) {
        node[prop] = newLink;
        if (node.dataset.hrefUrl) {
          node.dataset.hrefUrl = newLink;
        }
        if (node.dataset.outboundUrl) {
          node.dataset.outboundUrl = newLink;
        }
      }
    }
  });
})();