Bundle Helper

Add tools for many bundle sites.

当前为 2016-01-10 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Bundle Helper
// @namespace   iFantz7E.BundleHelper
// @version     0.01
// @description Add tools for many bundle sites.
// @match      	https://www.hrkgame.com/randomkeyshop/make-bundle/
// @run-at		document-start
// @grant       GM_addStyle
// @grant       GM_xmlhttpRequest
// @icon      	http://store.steampowered.com/favicon.ico
// @copyright	2016, 7-elephant
// ==/UserScript==

(function ()
{
	GM_addStyle(
		"   .bh_button { "
		+ "	  border-radius: 2px; border: medium none; padding: 10px; display: inline-block; cursor: pointer; "
		+ "   text-decoration: none !important; color: #67C1F5 !important; "
		+ "   background: rgba(103, 193, 245, 1) none repeat scroll 0% 0%; } "
		+ " .bh_owned { background-color: #5c7836 !important; } "
	);
	
	function attachOnLoad(callback)
	{
		window.addEventListener("load", function (e) 
		{
			callback();
		});
	}

	function attachOnReady(callback) 
	{
		document.addEventListener("DOMContentLoaded", function (e) 
		{
			callback();
		});
	}

	function insertBeforeElement(newNode, referenceNode) 
	{
		referenceNode.parentNode.insertBefore(newNode, referenceNode);
	}

	function insertAfterElement(newNode, referenceNode) 
	{
		referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
	}

	function reload()
	{
		window.location = window.location.href;
	}

	function getQueryByName(name, url) 
	{
		if (url == null)
			url = location.search;
		name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
		var regex = new RegExp("[\\?&]" + name + "=([^&#]*)");
		var results = regex.exec(url);
		return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
	}

	function main()
	{
		// Add autoscroll button
		{
			var divButton = document.createElement("div");
			divButton.classList.add("bh_button");
			divButton.id = "divAutoscroll";
			divButton.style = "position: fixed; right: 20px; bottom: 80px; z-index:3;";
			divButton.innerHTML = "<a href='#' onclick=' \
				var idx = setInterval(function() \
				{ \
					var eleLoad = document.querySelector(\".loadmore\"); \
					if (eleLoad != null) \
					{ \
						window.scrollTo(0,document.body.scrollHeight); \
					} \
					else \
					{ \
						clearInterval(idx); \
					} \
				}, 500); \
				this.parentElement.style.display=\"none\"; \
				return false;'>Load All</a>";
			document.body.appendChild(divButton);
		}
		
		// Add mark button
		{
			var divButton = document.createElement("div");
			divButton.classList.add("bh_button");
			divButton.id = "divAutoscroll";
			divButton.style = "position: fixed; right: 20px; bottom: 20px; z-index:3;";
			
			var eleA = document.createElement("a");
			eleA.setAttribute("href", "#");
			eleA.setAttribute("onclick", "return false;");
			eleA.textContent = "Mark Owned";
			
			
			eleA.addEventListener("click", function()
			{				
				var apps = [];
				
				var eleApps = document.querySelectorAll(".add-to-cart-product[href^='http://store.steampowered.com/app/']");
				console.log("Apps: " + eleApps.length);
				
				for (var i = 0; i < eleApps.length; i++)
				{
					var app = /[0-9]+/.exec(eleApps[i].getAttribute("href"));
					if (app != null)
					{
						apps.push(app[0]);
					}
				}
				
				apps = apps.filter(function(elem, index, self) 
				{
					return index == self.indexOf(elem);
				});
				
				var appAll = apps.join(",");
				
				GM_xmlhttpRequest(
				{
					method: "GET",
					headers: 
					{
						"Cache-Control": "max-age=0"
					},
					url: "http://store.steampowered.com/api/appuserdetails/?appids=" + appAll,
					onload: function(response) 
					{
						var dataRes = JSON.parse(response.responseText);
						//console.log("Response: " + Object.keys(dataRes).length);
						
						var countOwned = 0;
						
						var eleApps = document.querySelectorAll(".add-to-cart-product[href^='http://store.steampowered.com/app/']");
						for (var i = 0; i < eleApps.length; i++)
						{
							var app = /[0-9]+/.exec(eleApps[i].getAttribute("href"));
							if (app != null)
							{
								if (typeof dataRes[app] !== "undefined")
								{
									if (dataRes[app].success)
									{
										if (dataRes[app].data.is_owned)
										{
											var eleLabel = eleApps[i].nextElementSibling;
											eleLabel.classList.add("bh_owned");
											countOwned++;
										}
										else
										{
											console.log("App: not owned - " + app);
										}
									}
									else
									{
										console.log("App: not success - " + app);
									}
								}
							}
						}
						
						console.log("Apps: owned - " + countOwned);
						
					} // End onload
				});
				
			});
			
			divButton.appendChild(eleA);
			document.body.appendChild(divButton);
		}
	}

	attachOnReady(main);
	
})();