Guest User

Untitled

a guest
May 12th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name FL images
  3. // @match http://www.thefreshloaf.com/*
  4. // ==/UserScript==
  5. //
  6. // Return a "hash" of k
  7. function h(k) {
  8.   return k.src;
  9. }
  10.  
  11. var styleFile = new RegExp('http://www.thefreshloaf.com/files/styles/.*');
  12. var socialFile = new RegExp('http://www.thefreshloaf.com/sites/.*');
  13. var amazonFile = new RegExp('http://images.amazon.com/.*');
  14. // returns whether an image should be shrinkable
  15. function shrinkable(k) {
  16.   var s = k.src;
  17.   if (!(styleFile.exec(s) || socialFile.exec(s) || amazonFile.exec(s))  ||  (styleFile.exec(s) && k.className == "adaptive-image")) {
  18.     return true;
  19.   } else {
  20.     return false;
  21.   }
  22. }
  23.  
  24. var images = document.getElementsByTagName('img');
  25. var shrunken = {}; // stores whether images are shrunken or not
  26. var widths = {}; // stores original image widths
  27. var shrunkenSize = 50; // size to resize to
  28. var defaultUnshrunkenWidth = 500;
  29. // increasing timeout fixes some images not expanding to the right width
  30. // right now, it's set to 1 so that anchors will work properly
  31. setTimeout(setUp, 1);
  32.  
  33. // set up for all shrinkable images
  34. function setUp() {
  35. for (var i = 0; i < images.length; i++) {
  36.   var img = images[i];
  37.   if (shrinkable(img)) {
  38.     // spotlight images don't have specified widths
  39.     if (img.className == "spotlight" || img.className == "adaptive-image") {
  40.       widths[h(img)] = defaultUnshrunkenWidth;
  41.     } else {
  42.       widths[h(img)] = img.width;
  43.     }
  44.     shrunken[h(img)] = true;
  45.     img.width = shrunkenSize;
  46.     img.onclick=function(){
  47.       if (shrunken[h(this)] == true) {
  48.         this.width=widths[h(this)];
  49.       } else {
  50.         this.width=shrunkenSize;
  51.       }
  52.       shrunken[h(this)] = !shrunken[h(this)];
  53.     };
  54.   }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment