Bundle Helper

Add tools for many bundle sites.

目前為 2016-01-10 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
	
})();