lewisje

SmartWool Image Saver UserScript

Jun 26th, 2015
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @author James Edward Lewis II
  3. // @description This allows full-sized preview images to be saved on smartwool.com even though the site disables the right-click context menu.
  4. // @name SmartWool Image Saver
  5. // @namespace greasyfork.org
  6. // @version 0.1
  7. // @icon https://www.smartwool.com/skin/frontend/smartwool/default/favicon.ico
  8. // @include http://smartwool.com/*
  9. // @include http://*.smartwool.com/*
  10. // @include https://smartwool.com/*
  11. // @include https://*.smartwool.com/*
  12. // @license MIT
  13. // @grant none
  14. // @run-at document-end
  15. // @copyright 2015 James Edward Lewis II
  16. // ==/UserScript==
  17. (function (window, undefined) {
  18.   'use strict';
  19.   var header = document.getElementById('header');
  20.   function grabImage() {
  21.     var imgs = document.querySelectorAll('img[src*="$SWALT2$"]'),
  22.       inj = document.getElementById('injected'), str = [], img, i;
  23.     if (typeof inj === 'object' && inj) header.removeChild(inj);
  24.     if (typeof imgs !== 'object' || !imgs || !imgs.length) return;
  25.     for (i = imgs.length; i--;) {
  26.       img = imgs[i].src;
  27.       img = img.substring(0, img.indexOf('$SWALT2$'));
  28.       img += '$SWZOOM2$" target="_blank">Download ' + i;
  29.       if (str.indexOf(img) < 0) str.unshift(img);
  30.     }
  31.     str = '<ul id="injected"><li><a href="' + str.join('</a></li><li><a href="') + '</a></li></ul>';
  32.     header.innerHTML += str;
  33.     imgs = inj = str = img = i = null;
  34.   }
  35.   document.addEventListener('DOMContentLoaded', grabImage, false);
  36.   window.addEventListener('load', grabImage, false);
  37. })(window);
Advertisement
Add Comment
Please, Sign In to add comment