// ==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 // @downloadURL none // ==/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 = "Load All"; 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); })();