Advertisement
Guest User

SA_replace_read_images.js

a guest
Feb 18th, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name read gifs to links
  3. // @description Make gifs in read messages into links on some of Something Awful's image heavy threads
  4. // @include http://forums.somethingawful.com/showthread.php*threadid=3457178*
  5. // ==/UserScript==
  6. /*jslint browser: true, maxerr: 50, indent: 4, plusplus: true */
  7. /* Instead of downloading the 200 megs of gifs that you've already seen,
  8.    it should only download the 20 megs of gifs that you haven't seen yet. (or old gifs someone quotes)
  9.    WORKSFORME WONTFIX
  10. */
  11. window.addEventListener('DOMContentLoaded', function () {
  12.     "use strict";
  13.     var readImgs = document.querySelectorAll(".post .seen2 .postbody img, .post .seen1 .postbody img"),
  14.         i,
  15.         img,
  16.         a,
  17.         sa_pattern = /https?:\/\/\w*\.?somethingawful\.com\//,
  18.         src;
  19.  
  20.     for (i = 0; i < readImgs.length; i++) {
  21.         img = readImgs[i];
  22.         if (sa_pattern.test(img.src)) { // skip emoticons and avatars
  23.             continue;
  24.         }
  25.         src = img.src;
  26.         delete img.src;
  27.  
  28.         a = document.createElement('a');
  29.         a.href = src;
  30.  
  31.         a.target = '_blank';
  32.         a.appendChild(document.createTextNode(src));
  33.         img.parentNode.replaceChild(a, img);
  34.     }
  35. }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement