500px Download button and enable right click

This script will add a gren Download button to the Photo page on 500px.com and also enable right clicking the photo.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name 500px Download button and enable right click
// @version 20160828.02
// @author Dizzy69
// @description  This script will add a gren Download button to the Photo page on 500px.com and also enable right clicking the photo.
// @include http*://500px.com/*
// @include http*://www.500px.com/*
// @grant GM_addStyle
// @namespace https://greasyfork.org/users/22540
// ==/UserScript==

(function () {

	//Enable the right click:
	GM_addStyle("img.photo { z-index:999 !important; }");
	
	// The rest
	/**
	var src = $("#preload img").attr("src");

	if (src.indexOf('/h%3D300/') == -1) {
	$( ".photo_sidebar .actions_region" ).append( '<DIV class="actions_region section"><a href="' + src + '" target="_blank"  title="Download..." download class="button medium submit">下载图片</a></DIV>' );
	}
	 **/
	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 (events) {
		events.forEach(function (event) {
			if (event.type == "attributes" && event.attributeName == 'src') {
				if (event.target.src.indexOf('h%3D300/') ==  - 1 && event.target.alt != "" && event.target.className == "photo") {
					addBtnDownload(event.target.src);
					//console.log(event.target, event.attrChange, event.attrName, event.newValue);
				}
			}
		});
	}

	var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;

	var target = document.querySelector('body');

	var observer = new MutationObserver(eventHandler);

	var config = {
		attributes : true,
		//attributeFilter : ["src"],
		//attributeOldValue : false,
		//childList : true,
		subtree : true
	}

	observer.observe(target, config);

	//	observer.disconnect();

})();