lewisje icon

SmartWool Image Saver UserScript

lewisje | PRO | 06/26/15 09:37:47 PM UTC | 0 ⭐ | 332 👁️ | Never ⏰ | []
JavaScript |

1.53 KB

|

None

|

0 👍

/

0 👎

// ==UserScript==
// @author James Edward Lewis II
// @description This allows full-sized preview images to be saved on smartwool.com even though the site disables the right-click context menu.
// @name SmartWool Image Saver
// @namespace greasyfork.org
// @version 0.1
// @icon https://www.smartwool.com/skin/frontend/smartwool/default/favicon.ico
// @include http://smartwool.com/*
// @include http://*.smartwool.com/*
// @include https://smartwool.com/*
// @include https://*.smartwool.com/*
// @license MIT
// @grant none
// @run-at document-end
// @copyright 2015 James Edward Lewis II
// ==/UserScript==
(function (window, undefined) {
  'use strict';
  var header = document.getElementById('header');
  function grabImage() {
    var imgs = document.querySelectorAll('img[src*="$SWALT2$"]'),
      inj = document.getElementById('injected'), str = [], img, i;
    if (typeof inj === 'object' && inj) header.removeChild(inj);
    if (typeof imgs !== 'object' || !imgs || !imgs.length) return;
    for (i = imgs.length; i--;) {
      img = imgs[i].src;
      img = img.substring(0, img.indexOf('$SWALT2$'));
      img += '$SWZOOM2$" target="_blank">Download ' + i;
      if (str.indexOf(img) < 0) str.unshift(img);
    }
    str = '<ul id="injected"><li><a href="' + str.join('</a></li><li><a href="') + '</a></li></ul>';
    header.innerHTML += str;
    imgs = inj = str = img = i = null;
  }
  document.addEventListener('DOMContentLoaded', grabImage, false);
  window.addEventListener('load', grabImage, false);
})(window);

Comments