Force HTML 5 for Imgur and Gfycat on Reddit

Converts giant.gfycat.com hyperlinks to their HTML 5 video counterpart and Imgur links to their HTML 5 video counterpart.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name       Force HTML 5 for Imgur and Gfycat on Reddit
// @namespace  https://reddit.com/
// @version    1.3.1
// @description Converts giant.gfycat.com hyperlinks to their HTML 5 video counterpart and Imgur links to their HTML 5 video counterpart.
// @include    https://*.reddit.*
// @include    *imgur.com/*
// @copyright  2017
// @grant metadata
// ==/UserScript==

document.addEventListener('DOMContentLoaded', changeGif, false);
if (document.readyState === 'complete') {
  changeGif();
}

document.addEventListener("contextmenu", changeGif);
document.addEventListener("click", changeGif);

function changeGif() {

  Array.forEach(document.links, function (a) {
   a.href = a.href.replace(/giant\.(.*)\.gif/i, '$1');
   a.href = a.href.replace(/giant\.(.*)\.webm/i, '$1');
   a.href = a.href.replace(/giant\.(.*)\.mp4/i, '$1');
   a.href = a.href.replace(/fat\.(.*)\.gif/i, '$1');
   a.href = a.href.replace('/gifs/detail/', '/');
    
   if(a.href.indexOf(".imgur.com")>-1 || a.href.indexOf("/imgur.com")>-1){
    a.href = a.href.replace('.gif', '.gifv');
    a.href = a.href.replace('.gifvv', '.gifv');
    a.href = a.href.replace('.mp4', '.gifv');
   }
  });
}