// ==UserScript==
// @name Bundle Helper
// @namespace iFantz7E.BundleHelper
// @version 0.06
// @description Add tools for many bundle sites.
// @match *://www.hrkgame.com/*
// @match *://www.bundlestars.com/*/bundle/*
// @match *://www.reddit.com/r/*/comments/*
// @match *://groupees.com/*
// @match *://www.indiegala.com/*
// @match *://cubicbundle.com/*
// @match *://www.dailyindiegame.com/*
// @match *://dailyindiegame.com/*
// @match *://www.bundlekings.com/*
// @match *://www.orlygift.com/*
// @match *://otakumaker.com/*
// @match *://www.otakumaker.com/*
// @match *://www.superduperbundle.com/*
// @match *://www.humblebundle.com/*
// @match *://store.steampowered.com/widget/*
// @match *://www.gamebundle.com/*
// @match *://steamcompanion.com/gifts/*
// @run-at document-start
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @icon http://store.steampowered.com/favicon.ico
// @copyright 2016, 7-elephant
// ==/UserScript==
(function ()
{
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 clickToSelect(ele)
{
if (ele != null)
{
var range = document.createRange();
range.setStartBefore(ele.firstChild);
range.setEndAfter(ele.lastChild);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
}
function markOwned(query, getLabelCallback)
{
var apps = [];
var eleApps = document.querySelectorAll(query);
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);
});
console.log("Apps: " + apps.length);
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);
var countOwned = 0;
var eleApps = document.querySelectorAll(query);
for (var i = 0; i < eleApps.length; i++)
{
var appUrl = eleApps[i].getAttribute("href");
if (appUrl.indexOf("http://store.steampowered.com/app/") > -1)
{
var app = /[0-9]+/.exec(appUrl);
if (app != null)
{
if (typeof dataRes[app] !== "undefined")
{
if (dataRes[app].success)
{
if (dataRes[app].data.is_owned)
{
var eleLabel = getLabelCallback(eleApps[i]);
eleLabel.classList.add("bh_owned");
countOwned++;
}
else
{
console.log("App: not owned - http://store.steampowered.com/app/" + app + "/");
}
}
else
{
console.log("App: not success - https://steamdb.info/app/" + app + "/");
}
}
}
}
}
console.log("Apps: owned - " + countOwned);
} // End onload
});
}
function main()
{
// #8BC349
// #6EA028
// #2ECC71
// #92B300
GM_addStyle(
" .bh_button { "
+ " border-radius: 2px; border: medium none; padding: 10px; display: inline-block; "
+ " cursor: pointer; background: #67C1F5 none repeat scroll 0% 0%; "
+ " position: fixed; right: 20px; bottom: 20px; z-index:3; } "
+ " .bh_button a { "
+ " text-decoration: none !important; color: #FFF !important; "
+ " padding: 0px 2px; } "
+ " .bh_button:hover a { "
+ " color: #0079BF !important; } "
+ " .bh_button, .bh_button a { "
+ " font-family: Verdana; font-size: 12px; "
+ " line-height: 16px; } "
+ " .bh_owned { background-color: #7CA156 !important; "
+ " transition: all 500ms ease 0s; } "
);
var url = document.documentURI;
if (url.indexOf("hrkgame.com") > -1)
{
GM_addStyle(
" .bh_owned { background-color: #5C7836 !important; } "
);
if (url.indexOf("/randomkeyshop/make-bundle") > -1)
{
// Add load button
{
var divButton = document.createElement("div");
divButton.classList.add("bh_button");
divButton.id = "bh_loadAll";
divButton.setAttribute("style", "bottom: 80px;");
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 = "bh_markOwned";
var eleA = document.createElement("a");
eleA.setAttribute("onclick", "return false;");
eleA.textContent = "Mark Owned";
divButton.appendChild(eleA);
document.body.appendChild(divButton);
divButton.addEventListener("click", function()
{
markOwned(".add-to-cart-product[href*='http://store.steampowered.com/app/']", function(ele)
{
return ele.nextElementSibling;
});
});
}
}
else if (url.indexOf("/library") > -1)
{
var clientScript = ' \
confirm = function() \
{ \
return true; \
}; \
';
var eleClientScript = document.createElement("script");
eleClientScript.innerHTML = clientScript;
document.head.appendChild(eleClientScript);
}
}
else if (url.indexOf("bundlestars.com") > -1)
{
GM_addStyle(
//" .bh_owned { background-color: #A7CC00 !important; } "
" .bh_owned { background-color: #D0FE00 !important; } "
+ " .bh_owned:hover { background-color: #BBE500 !important; } "
+ " .bh_owned * { color: #444 !important; } "
+ " .bh_owned .was, .bh_owned .was * { color: #777 !important; } "
+ " #launcher { bottom: 100px !important; } "
);
// Add mark button
{
var divButton = document.createElement("div");
divButton.classList.add("bh_button");
divButton.id = "bh_markOwned";
var eleA = document.createElement("a");
eleA.setAttribute("onclick", "return false;");
eleA.textContent = "Mark Owned";
divButton.appendChild(eleA);
document.body.appendChild(divButton);
divButton.addEventListener("click", function()
{
markOwned(".bundle-accordian a.btn-bundle-more[href*='http://store.steampowered.com/app/']", function(ele)
{
return ele.parentElement.parentElement
.parentElement.parentElement.parentElement
.parentElement.parentElement.parentElement
.parentElement.firstElementChild;
});
});
}
}
else if (url.indexOf("reddit.com") > -1)
{
GM_addStyle(
" .bh_owned , .md .bh_owned code { background-color: #DFF0D8 !important; } "
);
// Add mark button
{
var divButton = document.createElement("div");
divButton.classList.add("bh_button");
divButton.id = "bh_markOwned";
var eleA = document.createElement("a");
eleA.setAttribute("onclick", "return false;");
eleA.textContent = "Mark Owned";
divButton.appendChild(eleA);
document.body.appendChild(divButton);
divButton.addEventListener("click", function()
{
markOwned("td > a[href*='http://store.steampowered.com/app/']", function(ele)
{
return ele.parentElement.parentElement;
});
});
}
}
else if (url.indexOf("groupees.com") > -1)
{
GM_addStyle(
" .bh_owned { background-color: #DFF0D8 !important; } "
+ " #subscribe-form { display: none; } "
+ " input[name='search'] { position: fixed; z-index: 1099; left: 18%; top: 16px; } "
+ " button[role='show3dKeyModal'] { position: fixed; z-index: 1099; left: 72%; top: 16px; } "
+ " .cancel-spin { position: fixed !important; z-index: 1099 !important; left: 39.5% !important; top: 22px !important; } "
);
/*
var a = document.querySelector("input[name='search']");
var b = document.querySelector("#subscribe-form");
b.parentElement.insertBefore(a,b);
b.parentElement.removeChild(b);
*/
// Add mark button
{
var divButton = document.createElement("div");
divButton.classList.add("bh_button");
divButton.id = "bh_markOwned";
var eleA = document.createElement("a");
eleA.setAttribute("onclick", "return false;");
eleA.textContent = "Mark Owned";
divButton.appendChild(eleA);
document.body.appendChild(divButton);
divButton.addEventListener("click", function()
{
var apps = [];
var eleApps = document.querySelectorAll(".bundle > .products .info .description a[href^='http://store.steampowered.com/app/']"
+ ", .expanded .product-info a[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);
var countOwned = 0;
var elePrds = document.querySelectorAll(".bundle > .products .product h3"
+ ", .expanded .details");
var eleApps = document.querySelectorAll(".bundle > .products .info"
+ ", .expanded .details");
for (var i = 0; i < eleApps.length; i++)
{
var eleApp = eleApps[i].querySelector(".description a[href^='http://store.steampowered.com/app/']"
+ ", .product-info a[href^='http://store.steampowered.com/app/']");
if (eleApp != null)
{
var app = /[0-9]+/.exec(eleApp.getAttribute("href"));
if (app != null)
{
if (typeof dataRes[app] !== "undefined")
{
if (dataRes[app].success)
{
if (dataRes[app].data.is_owned)
{
var eleLabel = elePrds[i];
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
});
});
}
}
else if (url.indexOf("indiegala.com") > -1)
{
GM_addStyle(
" .bh_owned { background-color: rgba(125, 174, 45, 0.9) !important; } "
+ " .bundle-item-trading-cards-cont span { opacity: 0.7; } "
+ " .span-title .title_game, .span-title .title_drm, .span-title .title_music { "
+ " line-height: 43px !important; margin: 10px 0px 10px 15px !important; "
+ " padding-left: 10px !important; border-radius: 3px !important; } "
);
// Add mark button
{
var divButton = document.createElement("div");
divButton.classList.add("bh_button");
divButton.id = "bh_markOwned";
var eleA = document.createElement("a");
eleA.setAttribute("onclick", "return false;");
eleA.textContent = "Mark Owned";
divButton.appendChild(eleA);
document.body.appendChild(divButton);
divButton.addEventListener("click", function()
{
var apps = [];
var eleApps = document.querySelectorAll(".game-opened-switcher a[href*='http://store.steampowered.com/app/']"
+ ", .in .in .in .game-steam-url[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);
var countOwned = 0;
var elePrds = document.querySelectorAll(".bundle-item-link, .in .in .in .game-steam-url");
var eleApps = document.querySelectorAll(".game-opened-switcher a[href*='http://store.steampowered.com/app/']:not(.game-steam-url), .in .in .in .game-steam-url");
for (var i = 0; i < eleApps.length; i++)
{
var appUrl = eleApps[i].getAttribute("href");
if (appUrl.indexOf("http://store.steampowered.com/app/") > -1)
{
var app = /[0-9]+/.exec(appUrl);
if (app != null)
{
if (typeof dataRes[app] !== "undefined")
{
if (dataRes[app].success)
{
if (dataRes[app].data.is_owned)
{
var eleLabel = elePrds[i].parentElement;
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
});
});
}
// Change title
var elesPrice = document.querySelectorAll(".bundle-claim-phrase");
for (var i = elesPrice.length - 1; i > -1; i--)
{
var elePrice = elesPrice[i].querySelector("span");
if (elePrice != null)
{
var price = elePrice.textContent.trim();
if (price.indexOf("$") == 0)
{
document.title = price + " " + document.title;
break;
}
}
}
}
else if (url.indexOf("orlygift.com") > -1)
{
if (window.self != window.top)
return;
// Add mark button
{
var divButton = document.createElement("div");
divButton.classList.add("bh_button");
divButton.id = "bh_markOwned";
var eleA = document.createElement("a");
eleA.textContent = "Mark Owned";
divButton.appendChild(eleA);
document.body.appendChild(divButton);
divButton.addEventListener("click", function()
{
var apps = [];
var eleApps = document.querySelectorAll("div[id^='game-detail-'] a.btn-primary[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);
var countOwned = 0;
var elePrds = document.querySelectorAll(".box-game");
var eleApps = document.querySelectorAll("div[id^='game-detail-']");
for (var i = 0; i < eleApps.length; i++)
{
var eleApp = eleApps[i].querySelector("a.btn-primary[href^='http://store.steampowered.com/app/']");
if (eleApp != null)
{
var app = /[0-9]+/.exec(eleApp.getAttribute("href"));
if (app != null)
{
if (typeof dataRes[app] !== "undefined")
{
if (dataRes[app].success)
{
if (dataRes[app].data.is_owned)
{
var eleLabel = elePrds[i];
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
});
});
}
}
else if (url.indexOf("cubicbundle.com") > -1)
{
GM_addStyle(
" .bh_owned { background-color: #91BA07 !important; } "
);
// Add mark button
{
var divButton = document.createElement("div");
divButton.classList.add("bh_button");
divButton.id = "bh_markOwned";
var eleA = document.createElement("a");
eleA.setAttribute("onclick", "return false;");
eleA.textContent = "Mark Owned";
divButton.appendChild(eleA);
document.body.appendChild(divButton);
divButton.addEventListener("click", function()
{
markOwned(".price a[href*='http://store.steampowered.com/app/']", function(ele)
{
return ele.parentElement.parentElement.parentElement;
});
});
}
}
else if (url.indexOf("dailyindiegame.com") > -1)
{
// Add mark button
{
var divButton = document.createElement("div");
divButton.classList.add("bh_button");
divButton.id = "bh_markOwned";
var eleA = document.createElement("a");
eleA.setAttribute("onclick", "return false;");
eleA.textContent = "Mark Owned";
divButton.appendChild(eleA);
document.body.appendChild(divButton);
divButton.addEventListener("click", function()
{
if (document.querySelectorAll(".DIG-content a[href*='http://store.steampowered.com/app/']").length > 0)
{
markOwned(".DIG-content a[href*='http://store.steampowered.com/app/']", function(ele)
{
return ele.parentElement
.parentElement.parentElement
.parentElement.parentElement;
});
}
else
{
markOwned(".DIG2content a[href*='http://store.steampowered.com/app/']", function(ele)
{
return ele.parentElement
.parentElement;
});
}
});
}
}
else if (url.indexOf("bundlekings.com") > -1)
{
// Add mark button
{
var divButton = document.createElement("div");
divButton.classList.add("bh_button");
divButton.id = "bh_markOwned";
var eleA = document.createElement("a");
eleA.setAttribute("onclick", "return false;");
eleA.textContent = "Mark Owned";
divButton.appendChild(eleA);
document.body.appendChild(divButton);
divButton.addEventListener("click", function()
{
markOwned(".content-wrap a[href*='http://store.steampowered.com/app/']", function(ele)
{
return ele.parentElement.parentElement.parentElement;
});
});
}
}
else if (url.indexOf("otakumaker.com") > -1)
{
GM_addStyle(
" .bh_owned { background-color: #91BA07 !important; } "
);
// Add mark button
{
var divButton = document.createElement("div");
divButton.classList.add("bh_button");
divButton.id = "bh_markOwned";
var eleA = document.createElement("a");
eleA.setAttribute("onclick", "return false;");
eleA.textContent = "Mark Owned";
divButton.appendChild(eleA);
document.body.appendChild(divButton);
divButton.addEventListener("click", function()
{
markOwned(".gantry-width-spacer a[href*='http://store.steampowered.com/app/']", function(ele)
{
return ele.parentElement.parentElement;
});
});
}
}
else if (url.indexOf("superduperbundle.com") > -1)
{
// Add mark button
{
var divButton = document.createElement("div");
divButton.classList.add("bh_button");
divButton.id = "bh_markOwned";
var eleA = document.createElement("a");
eleA.setAttribute("onclick", "return false;");
eleA.textContent = "Mark Owned";
divButton.appendChild(eleA);
document.body.appendChild(divButton);
divButton.addEventListener("click", function()
{
markOwned("#gameslist a[href*='http://store.steampowered.com/app/']", function(ele)
{
return ele.parentElement.parentElement;
});
});
}
}
else if (url.indexOf("gamebundle.com") > -1)
{
GM_addStyle(
" .bh_owned { background-color: #A0CC41 !important; border-bottom: 45px solid rgba(233, 233, 233, 0.5);} "
);
// Add mark button
{
var divButton = document.createElement("div");
divButton.classList.add("bh_button");
divButton.id = "bh_markOwned";
var eleA = document.createElement("a");
eleA.setAttribute("onclick", "return false;");
eleA.textContent = "Mark Owned";
divButton.appendChild(eleA);
document.body.appendChild(divButton);
divButton.addEventListener("click", function()
{
markOwned(".activebundle_game_section_full a[href*='http://store.steampowered.com/app/']", function(ele)
{
return ele.parentElement;
});
});
}
}
else if (url.indexOf("humblebundle.com") > -1)
{
var elePrice = document.querySelector(".section-heading.bta");
if (elePrice != null)
{
var price = elePrice.textContent.trim()
.replace("Pay more than the average of ", "")
.replace(" to also unlock!", "").trim();
if (price.indexOf("$") == 0)
{
document.title = price + " " + document.title;
}
}
var eleSold = document.querySelector(".heading-bundles-sold .mini-digit-holder");
if (eleSold != null)
{
var sold = eleSold.getAttribute("data-initial-value") || "";
eleSold.parentElement.parentElement.setAttribute("title", sold);
}
if (url.indexOf("/downloads") > -1)
{
setTimeout(function()
{
var elesKey = document.querySelectorAll(".sr-redeemed-bubble");
for (var i = 0; i < elesKey.length; i++)
{
elesKey[i].addEventListener("click", function (e)
{
var ele = e.target;
clickToSelect(ele);
});
}
}, 3000);
}
}
else if (url.indexOf("steamcompanion.com") > -1)
{
GM_addStyle(
" .bh_owned.banner { margin-bottom: 5px !important; margin-top: 35px !important; "
+ " padding-bottom: 15px !important; padding-top: 15px !important; } "
+ " .bh_owned.giveaway-links { opacity: 0.75; } "
);
markOwned("#hero a[href*='http://store.steampowered.com/app/']", function(ele)
{
return ele;
});
// Mark
{
var query = ".giveaway-links img[src^='https://steamcdn-a.akamaihd.net/steam/apps/']";
var getLabelCallback = function(ele)
{
return ele.parentElement.parentElement.parentElement;
};
var apps = [];
var eleApps = document.querySelectorAll(query);
for (var i = 0; i < eleApps.length; i++)
{
var app = /[0-9]+/.exec(eleApps[i].getAttribute("src"));
if (app != null)
{
apps.push(app[0]);
}
}
apps = apps.filter(function(elem, index, self)
{
return index == self.indexOf(elem);
});
console.log("Apps: " + apps.length);
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);
var countOwned = 0;
var eleApps = document.querySelectorAll(query);
for (var i = 0; i < eleApps.length; i++)
{
var appUrl = eleApps[i].getAttribute("src");
if (appUrl.indexOf("https://steamcdn-a.akamaihd.net/steam/apps/") > -1)
{
var app = /[0-9]+/.exec(appUrl);
if (app != null)
{
if (typeof dataRes[app] !== "undefined")
{
if (dataRes[app].success)
{
if (dataRes[app].data.is_owned)
{
var eleLabel = getLabelCallback(eleApps[i]);
eleLabel.classList.add("bh_owned");
countOwned++;
}
else
{
//console.log("App: not owned - http://store.steampowered.com/app/" + app + "/");
}
}
else
{
//console.log("App: not success - https://steamdb.info/app/" + app + "/");
}
}
}
}
}
console.log("Apps: owned - " + countOwned);
} // End onload
});
}
}
else if (url.indexOf("steampowered.com") > -1)
{
GM_addStyle(
" .bh_owned { background-color: transparent !important; } "
+ " .bh_owned a { color: #71A034 !important; }"
);
markOwned(".main_text a[href*='http://store.steampowered.com/app/']", function(ele)
{
return ele.parentElement;
});
}
}
attachOnReady(main);
})();