500px.com Userscript Experiment

Gets you to the real image!

当前为 2015-12-11 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name 500px.com Userscript Experiment
// @namespace github.com/hrxn
// @description Gets you to the real image!
// @version 0.2
// @author Hrxn <github.com/hrxn>
// @license Creative Commons BY-NC-SA
// @include http*://500px.com/*
// @grant none
// @icon https://assetcdn.500px.org/assets/favicon-1e8257b93fb787f8ceb66b5522ee853c.ico
// ==/UserScript==

(function ()
{
	var path = window.location.pathname.split("/");
	var name = path[3];
	var addElements = function (src)
	{
		var el = document.querySelector('.main_container .sidebar_region .photo_sidebar .actions_region');
		el.insertAdjacentHTML('afterEnd', '<a href="' + src + '" target="_blank"> [ View... ] </a> | <a href="' + src + '" download="' + name + '"> [ 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")
				{
					addElements(event.target.src);
					// < Console debug output   :
					// statements go here, e.g. :
					// console.log(event.target, event.target.src);
					// console.log(window.location.pathname.split("/"));
					// console.log(name);
					// Console debug output >
				}
			}
		});
	}
	var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
	var target = document.querySelector('body');
	var observer = new MutationObserver(eventHandler);
	var config = 
	{
		attributes : true,
		subtree : true
	}

	observer.observe(target, config);
	
})();