500px.com Download Photo

Add button to download photo.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name 500px.com Download Photo
// @namespace 06msNqk7e1ub45dZ
// @description Add button to download photo.
// @version 1.3
// @author Reek | reeksite.com
// @license Creative Commons BY-NC-SA
// @include http*://500px.com/*
// @grant none
// @run-at document-start
// ==/UserScript==

(function () {

  var addBtnDownload = function (src) {
    var el = document.querySelector('.main_container .sidebar_region .photo_sidebar .actions_region');
    el.insertAdjacentHTML('afterEnd', '<a href="' + src + '" target="_blank" download class="button medium submit">Download</a>');
  };

  var eventHandler = function (event) {
    // doc: http://help.dottoro.com/ljdchxcl.php
    // tm: https://github.com/derjanb/tampermonkey/issues/18
    if (event.target.tagName == 'IMG' && event.target.className == 'photo') {
      if ('attrChange' in event) { // Firefox, Opera, Internet Explorer from version 9
        if (event.attrChange && event.attrName == 'src' && event.newValue != event.oldValue) {
          if (event.newValue.indexOf('h%3D300') == -1) { // exclude thumbnail
            addBtnDownload(event.newValue);
            //console.log(event.target, event.attrChange, event.attrName, event.newValue);
          }
        }
      }
    }
  };

  window.addEventListener('DOMAttrModified', eventHandler, false);

})();