Imgur Mirror

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

2016-05-02 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

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        Imgur Mirror
// @description Switches all imgur links to the mirror site http://kageurufu.net/imgur
// @include     *
// @version     1.0.3
// @grant        none
// @require https://greasyfork.org/scripts/5679-wait-for-elements/code/Wait%20For%20Elements.js?version=122976
// @namespace https://greasyfork.org/users/649
// ==/UserScript==

var regex = /imgur\.com\/((?!a\/|gallery\/))([a-z0-9]+(\.+[a-z0-9]+)?)/i;

var getNewLink = function(imgurLink, useGif) {
    var file = imgurLink.split('/').pop();
    var exreg = /(?:\.([^.]+))?$/;
    var extension = exreg.exec(file)[1];
    file = file.replace(exreg, '');
    if (!extension) {
        extension = 'png';
    } else if (extension === 'gifv' || extension === 'gif') {
        extension = 'webm';
    }
    if (useGif && extension === 'webm') {
        extension = 'gif';
    }
    return 'http://kageurufu.net/imgur/?' + file + '.' + extension;
};

waitForElems('a', function(link) {
   if (link.href.match(regex)) {
       link.href = getNewLink(link.href, false);
   } 
});

waitForElems('img', function(img) {
    if (img.src.match(regex)) {
        img.src = getNewLink(img.src, true);
    }
});