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.

  1. // ==UserScript==
  2. // @name Force HTML 5 for Imgur and Gfycat on Reddit
  3. // @namespace https://reddit.com/
  4. // @version 1.3.1
  5. // @description Converts giant.gfycat.com hyperlinks to their HTML 5 video counterpart and Imgur links to their HTML 5 video counterpart.
  6. // @include https://*.reddit.*
  7. // @include *imgur.com/*
  8. // @copyright 2017
  9. // @grant metadata
  10. // ==/UserScript==
  11.  
  12. document.addEventListener('DOMContentLoaded', changeGif, false);
  13. if (document.readyState === 'complete') {
  14. changeGif();
  15. }
  16.  
  17. document.addEventListener("contextmenu", changeGif);
  18. document.addEventListener("click", changeGif);
  19.  
  20. function changeGif() {
  21.  
  22. Array.forEach(document.links, function (a) {
  23. a.href = a.href.replace(/giant\.(.*)\.gif/i, '$1');
  24. a.href = a.href.replace(/giant\.(.*)\.webm/i, '$1');
  25. a.href = a.href.replace(/giant\.(.*)\.mp4/i, '$1');
  26. a.href = a.href.replace(/fat\.(.*)\.gif/i, '$1');
  27. a.href = a.href.replace('/gifs/detail/', '/');
  28. if(a.href.indexOf(".imgur.com")>-1 || a.href.indexOf("/imgur.com")>-1){
  29. a.href = a.href.replace('.gif', '.gifv');
  30. a.href = a.href.replace('.gifvv', '.gifv');
  31. a.href = a.href.replace('.mp4', '.gifv');
  32. }
  33. });
  34. }