GoogleGifs

Automatically plays gifs on google pages

  1. // ==UserScript==
  2. // @name GoogleGifs
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Automatically plays gifs on google pages
  6. // @author Ian Pearce (@peeinears)
  7. // @match https://www.google.com/*
  8. // @grant MIT
  9. // ==/UserScript==
  10.  
  11.  
  12. // This script is originally from an extension called GoogleGifs by Ian Pearce, hence I have credited him as the author. I have merely turned it into a userscript because the extension was removed from Chrome's webstore.
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. function playGIFs() {
  18. var els, i, a, img, matches, url;
  19. els = document.getElementsByClassName('rg_di');
  20. for (i = 0; i < els.length; i++) {
  21. if (els[i].animated) continue;
  22. els[i].animated = true;
  23. a = els[i].getElementsByTagName('a')[0];
  24. if (!a) continue;
  25. img = els[i].getElementsByTagName('img')[0];
  26. if (!img) continue;
  27. matches = a.href.match(/imgurl=(\S+?)(&|$)/i);
  28. if (matches !== null && matches.length > 1) {
  29. url = unescape(unescape(matches[1]));
  30. if (/\.gif(\?.*)?$/i.test(url)) {
  31. img.src = url;
  32. }
  33. }
  34. }
  35. }
  36.  
  37. // continue to load GIFs added to DOM after initial page load
  38. window.setInterval(playGIFs, 1000);
  39. })();