gavin19

Reddit - Replace imgur with filmot

Sep 14th, 2011
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Reddit - Replace imgur links with filmot
  3. // @namespace     http://userscripts.org/scripts/show/105715
  4. // @author        gavin19
  5. // @description    Replaces imgur links with filmot mirror ones.
  6. // @match          http://*.reddit.com/*
  7. // @include          http://*.reddit.com/*
  8. // @version    1.12
  9. // ==/UserScript==
  10.  
  11. var replaceImgur = {
  12.  
  13.     repLinks: function (ele) {
  14.         for (var i = 0, len = ele.length; i < len; i += 1) {
  15.             ele[i].href = ele[i].href.replace('imgur', 'filmot');
  16.             if (ele[i].srcurl) {
  17.                 ele[i].srcurl = ele[i].srcurl.replace('imgur', 'filmot');
  18.             }
  19.         }
  20.     },
  21.  
  22.     init: function() {
  23.         var ele, loc = window.location.href;
  24.         if (loc.match(/\/comments\//i)) {
  25.             ele = document.querySelectorAll('.commentarea:not(.side) .sitetable .md a');
  26.             this.repLinks(ele);
  27.             document.body.addEventListener('DOMNodeInserted', function(event) {
  28.              if ((event.target.tagName == 'DIV') && (/even/ig.test(event.target.getAttribute('class')))) {
  29.                     var ele = event.target.querySelectorAll('.md a');
  30.                     replaceImgur.repLinks(ele);
  31.                 }
  32.             }, false);
  33.         } else {
  34.             ele = document.querySelectorAll('.sitetable .thing a.title');
  35.             this.repLinks(ele);
  36.             document.body.addEventListener('DOMNodeInserted', function(event) {
  37.                 if ((event.target.tagName == 'DIV') && (event.target.getAttribute('id') && event.target.getAttribute('id').indexOf('siteTable') != -1)) {
  38.                     ele = event.target.querySelectorAll('.thing a');
  39.                     replaceImgur.repLinks(ele);
  40.                 }
  41.             }, true);
  42.         }
  43.     }
  44. };
  45.  
  46. if (document.body) {
  47.     setTimeout(function() {
  48.         replaceImgur.init();
  49.     }, 3000);
  50. }
  51. else {
  52.     window.addEventListener("load", function() {
  53.         replaceImgur.init();
  54.     }, false);
  55. }
Add Comment
Please, Sign In to add comment