Skip to content

Instantly share code, notes, and snippets.

@sergiosusa
Created April 10, 2018 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sergiosusa/4c9d6cb3001e152353a7d089496d3038 to your computer and use it in GitHub Desktop.
Save sergiosusa/4c9d6cb3001e152353a7d089496d3038 to your computer and use it in GitHub Desktop.
Check if you own on your configured account the games of a bundle on Humble Bundle, IndieGala, Fanatical and GoGoBundle
// ==UserScript==
// @name Own Game Bundle Checker
// @namespace http://sergiosusa.com/
// @version 0.1
// @description try to take over the world!
// @author Sergio Susa (sergio@sergiosusa.com)
// @match https://www.gogobundle.com/latest/bundles/*
// @match https://www.humblebundle.com/games/*
// @match https://www.indiegala.com/*
// @match https://www.fanatical.com/*/bundle/*
// @grant none
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// ==/UserScript==
var steamApiId = "SteamApiKey";
var steamUserId = "UserSteamId64";
var gamesURL = "https://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?key=" + steamApiId + "&steamid=" + steamUserId + "&include_appinfo=1";
/***** CONSTANTS *****/
const PAGE_GO_GO_BUNDLE = 'gogobundle.com/latest/bundles/';
const PAGE_INDIE_GALA = 'www.indiegala.com';
const PAGE_HUMBLE_BUNDLE = 'www.humblebundle.com/games/';
const PAGE_FANATICAL = 'www.fanatical.com/en/bundle/';
(function() {
'use strict';
$.noConflict();
jQuery.ajax({
url: gamesURL,
dataType: 'JSONP',
type: 'GET',
jsonp: 'jsonp',
success: function(data){
localStorage.setItem(steamUserId, JSON.stringify(data.response));
}
});
jQuery( document ).ready(function() {
setTimeout(
function(){
var url = getCurrentUrl();
var myGames = JSON.parse(localStorage.getItem(steamUserId));
if (url.includes(PAGE_GO_GO_BUNDLE)){
checkOwnGoGoBundle(myGames);
} else if (url.includes(PAGE_INDIE_GALA)){
checkOwnIndieGala(myGames);
} else if (url.includes(PAGE_HUMBLE_BUNDLE)){
checkOwnHumbleBundle(myGames);
} else if (url.includes(PAGE_FANATICAL)){
checkOwnFanatical(myGames);
} else if (url.includes(PAGE_GROUPEES)){
checkOwnGroupees(myGames);
} else {
// not support this site.
}
}, 2500
);
});
})();
/***********************************************************
* Fanatical
**********************************************************/
function checkOwnFanatical(myGames) {
var games = document.getElementsByClassName('bundle-row');
checkOwn(games, myGames, addResultFanatical, getTrimInnerTextFanatical);
}
function getTrimInnerTextFanatical(item) {
var node = item.getElementsByTagName('div')[1].children[0];
var textNode = node.innerHTML;
textNode = textNode.substring(textNode.indexOf('-->'));
var title = textNode.substring(textNode.indexOf('-->') + 3, textNode.indexOf('<!--'));
return title;
}
function addResultFanatical(item, color, text)
{
var node = item.getElementsByTagName('div')[1].children[0];
jQuery(item).parent().css('border-color', color);
jQuery(item).parent().css('border-bottom-style', 'solid');
var start = jQuery(node).html().substring(0, jQuery(node).html().indexOf('<!-- /react-text -->'));
var end = jQuery(node).html().substring(jQuery(node).html().indexOf('<!-- /react-text -->'));
jQuery(node).html(start + getHtmlSpanResult(color, text) + end);
}
/***********************************************************
* Go Go Bundle
**********************************************************/
function checkOwnGoGoBundle(myGames) {
var games = jQuery("#hikashop_product_left_part > div > div > div > h5 > span");
checkOwn(games, myGames, addResultGoGoBundle, getTrimInnerText);
}
function addResultGoGoBundle(item, color, text)
{
jQuery(item).parent().css('border-color', color);
jQuery(item).parent().css('border-bottom-style', 'solid');
jQuery(item).html(jQuery(item).html() + getHtmlSpanResult(color, text) );
}
/***********************************************************
* Indie Gala
**********************************************************/
function checkOwnIndieGala(myGames)
{
if (!isIndieGalaBundlePage()){
return;
}
var games = jQuery('.bundle-item-trading-cards-cont');
checkOwn(games, myGames, addResultIndieGala, getTrimInnerText);
}
function isIndieGalaBundlePage()
{
if (jQuery('#buttonPurchase').length > 0) {
return true;
}
return false;
}
function addResultIndieGala(item, color, text)
{
jQuery(item).css('border-color', color);
jQuery(item).css('border-bottom-style', 'solid');
jQuery(item).html(jQuery(item).html() + getHtmlSpanResult(color, text) );
}
/***********************************************************
* Humble Bundle
**********************************************************/
function checkOwnHumbleBundle(myGames)
{
var games = jQuery(".dd-image-box-white");
checkOwn(games, myGames, addResultHumbleBundle, getTrimInnerText);
}
function addResultHumbleBundle(item, color, text)
{
jQuery(item).parent().css('border-color', color);
jQuery(item).parent().css('border-bottom-style', 'solid');
jQuery(item).html(jQuery(item).html() + getHtmlSpanResult(color, text) );
}
/***********************************************************
* Utility Functions
**********************************************************/
function checkOwn(games, myGames, addResult, getGameTitle)
{
jQuery.each(games, function(index, item){
var found = false;
for(var i=0; i < myGames.game_count; i++){
if (myGames.games[i].name == getGameTitle(item)){
addResult(item, 'red', 'Own');
found = true;
}
}
if (!found){
addResult(item, 'blue', 'Not Own');
}
});
}
function getTrimInnerText(item) {
return item.innerText.trim();
}
function getHtmlSpanResult(color, text)
{
return '<span style="color:'+ color +';margin-left: 5px;font-weight: bold;background:none;display:inline;">('+ text +')</span>';
}
function getCurrentUrl() {
return window.location.href;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment