Skip to content

Instantly share code, notes, and snippets.

@Lexaire
Last active August 22, 2017 15:51
Show Gist options
  • Save Lexaire/2214001ef448c17221aba3bd8c084d4c to your computer and use it in GitHub Desktop.
Save Lexaire/2214001ef448c17221aba3bd8c084d4c to your computer and use it in GitHub Desktop.
Game Owned Checker userscript with added card icon function.
// ==UserScript==
// @name Steam Store - Game Owned Checker
// @icon http://store.steampowered.com/favicon.ico
// @namespace Royalgamer06
// @author Royalgamer06
// @contributor Black3ird
// @contributor Lex
// @version 1.5.2.2
// @description Check every web page for game, dlc and package links to the steam store and mark if it's owned, unowned, ignored (not interested), removed/delisted (decommissioned) or wishlisted.
// @include /^https?\:\/\/.+/
// @exclude /^https?\:\/\/(.+\.steampowered|steamcommunity)\.com.*/
// @exclude /^https?\:\/\/barter\.vg.*/
// @exclude /^https?\:\/\/(www\.)?steamgifts\.com\/giveaway\/.*/
// @exclude /sgtools\.info\/nonactivated\/.*/
// @grant GM_xmlhttpRequest
// @grant GM_openInTab
// @grant GM_info
// @grant GM_getValue
// @grant GM_setValue
// @run-at document-start
// @connect store.steampowered.com
// @connect steam-tracker.com
// @connect cdn.steam.tools
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// @supportURL https://www.steamgifts.com/discussion/y9vVm/
// ==/UserScript==
// ==Configuration==
const prefix = false; // Prefix (true) instead of suffix (false) position icon.
const wantIgnores = true; // Wether (true) or not (false) you want to display an extra icon for ignored (not interested) apps.
const wantDecommissioned = true; // Wether (true) or not (false) you want to display an extra icon for removed or delisted (decommissioned) apps.
const wantCards = true; // Whether (true) or not (false) you want to display an extra icon for apps with cards.
const linkCardIcon = true; // Link the card icon to SteamCardExchange.net
const ignoredIcon = "🚫︎"; // HTML entity code for '🛇' (default).
const ignoredColor = "grey"; // Color of the icon for ignored (not interested) apps.
const wishlistIcon = "❤"; // HTML entity code for '❤' (default).
const wishlistColor = "hotpink"; // Color of the icon for wishlisted apps.
const ownedIcon = "✔"; // HTML entity code for '✔' (default).
const ownedColor = "green"; // Color of the icon for owned apps and subs.
const unownedIcon = "✘"; // HTML entity code for '✘' (default).
const unownedColor = "red"; // Color of the icon for unowned apps and subs.
const decommissionedIcon = "🗑"; // HTML entity code for '🗑' (default).
const decommissionedColor = "initial"; // Color of the icon for removed or delisted apps and subs.
const cardIcon = "&#x1F0A1"; // HTML entity code for ' ' (default).
const cardColor = "#4B72D4"; // Color of the icon for cards.
const cardRefreshInterval = 60*24*3; // Refresh card data once every 3 days
const refreshInterval = 15; // Number of minutes to wait to refesh cached data. 0 = always stay up-to-date.
// ==/Configuration==
// ==Code==
this.$ = this.jQuery = jQuery.noConflict(true);
$.expr[':'].regex = function(elem, index, match) {
var matchParams = match[3].split(','),
validLabels = /^(data|css):/,
attr = {
method: matchParams[0].match(validLabels) ? matchParams[0].split(':')[0] : 'attr',
property: matchParams.shift().replace(validLabels,'')
},
regexFlags = 'ig',
regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
return regex.test(jQuery(elem)[attr.method](attr.property));
};
var cachedCards = JSON.parse(GM_getValue("goc_cards", null));
var cachedJson = GM_getValue("goc_data", null);
var lastCached = GM_getValue("goc_last", 0);
if (Date.now() - lastCached >= refreshInterval * 60000 || !JSON.parse(cachedJson).rgDecommissionedApps) {
var v = parseInt(GM_getValue("goc_v", "1")) + 1;
GM_setValue("goc_v", v);
GM_xmlhttpRequest({
method: "GET",
url: "http://store.steampowered.com/dynamicstore/userdata/?v=" + v,
ignoreCache: true,
onload: function(response) {
var dujson = JSON.parse(response.responseText);
GM_xmlhttpRequest({
method: "GET",
url: "https://steam-tracker.com/api?action=GetAppListV2",
ignoreCache: true,
onload: function(response) {
var stjson = JSON.parse(response.responseText);
if (stjson.success) {
dujson.rgDecommissionedApps = stjson.removed_apps;
refreshCards(function(){ init(JSON.stringify(dujson)); });
} else {
refreshCards(function(){ init(cachedJson); });
}
}
});
}
});
} else {
refreshCards(function(){ init(cachedJson); });
}
function refreshCards(callback) {
const lastCachedCards = GM_getValue("goc_cards_last", 0);
if (wantCards && (Date.now() - lastCachedCards >= cardRefreshInterval * 60000 || !cachedCards || cachedCards.length < 7000)) {
GM_xmlhttpRequest({
method: "GET",
url: "http://cdn.steam.tools/data/set_data.json",
ignoreCache: true,
onload: function(response) {
const jresp = JSON.parse(response.responseText);
cachedCards = jresp.sets.map((s) => parseInt(s.appid));
if (cachedCards.length > 7000) { // sanity check
GM_setValue("goc_cards", JSON.stringify(cachedCards));
GM_setValue("goc_cards_last", Date.now());
}
callback();
}
});
} else {
callback();
}
}
function init(jsonText) {
var json = JSON.parse(jsonText);
var ignoredApps = json.rgIgnoredApps;
var ownedApps = json.rgOwnedApps;
var ownedPackages = json.rgOwnedPackages;
var wishlist = json.rgWishlist;
var decommissioned = json.rgDecommissionedApps;
if (ownedApps.length === 0 && ownedPackages.length && ignoredApps.length === 0 && wishlist.length === 0 && cachedJson === null && !GM_info.isIncognito) {
if (confirm("Userscript '" +
GM_info.script.name +
"' did not work properly: Could not get user data and no cached data was available.\nPlease make sure you are logged in to the Steam Store and dynamic store userdata is loaded.\n" +
"Login first, then keep refreshing the dynamic store userdata page untill the data is loaded.\nDo you want to attempt to fix this now?")) {
GM_openInTab("http://store.steampowered.com/dynamicstore/userdata/", false);
GM_openInTab("http://store.steampowered.com/login/", false);
}
} else {
if (ownedApps.length === 0 && ownedPackages.length === 0 && ignoredApps.length === 0 && wishlist.length === 0) {
var parsedCachedJson = JSON.parse(cachedJson);
ignoredApps = parsedCachedJson.rgIgnoredApps;
ownedApps = parsedCachedJson.rgOwnedApps;
ownedPackages = parsedCachedJson.rgOwnedPackages;
wishlist = parsedCachedJson.rgWishlist;
} else {
lastCached = Date.now();
GM_setValue("goc_last", lastCached);
GM_setValue("goc_data", jsonText);
}
var lcs = (new Date(lastCached)).toLocaleString();
var appSelector = ":regex(href, ^(https?:)?\/\/(store\.steampowered\.com|steamcommunity\.com|steamdb\.info)\/(agecheck\/)?app\/[0-9]+), img[src*='cdn.akamai.steamstatic.com/steam/apps/'], img[src*='steamcdn-a.akamaihd.net/steam/apps/']";
var subSelector = ":regex(href, ^(https?:)?\/\/(store\.steampowered\.com|steamdb\.info)\/sub\/[0-9]+)";
$(document).on("DOMSubtreeModified", appSelector, function() {
doApp(this, wishlist, ownedApps, ignoredApps, decommissioned, lcs);
}).on("DOMSubtreeModified", subSelector, function() {
doSub(this, wishlist, ownedPackages, lcs);
}).ready(function() {
$(appSelector).each(function() {
doApp(this, wishlist, ownedApps, ignoredApps, decommissioned, lcs);
});
$(subSelector).each(function() {
doSub(this, wishlist, ownedPackages, lcs);
});
});
}
}
function doApp(elem, wishlist, ownedApps, ignoredApps, decommissioned, lcs) {
if (!$(elem).hasClass("goc")) {
$(elem).addClass("goc");
setTimeout(function() {
var appID = elem.href ? parseInt(elem.href.split("app/")[1].split("/")[0].split("?")[0].split("#")[0]) : parseInt(elem.src.split("apps/")[1].split("/")[0].split("?")[0].split("#")[0]);
var html;
if ($.inArray(appID, ownedApps) > -1) { //if owned
html = "<span style='color: " + ownedColor + "; cursor: help;' title='Game or DLC (" + appID + ") owned on Steam\nLast cached: " + lcs + "'> " + ownedIcon + "</span>"; //✔
} else { //else not owned
if ($.inArray(appID, wishlist) > -1) { //if wishlisted
html = "<span style='color: " + wishlistColor + "; cursor: help;' title='Game or DLC (" + appID + ") wishlisted on Steam\nLast cached: " + lcs + "'> " + wishlistIcon + "</span>"; //❤
} else { //else not wishlisted
html = "<span style='color: " + unownedColor + "; cursor: help;' title='Game or DLC (" + appID + ") not owned on Steam\nLast cached: " + lcs + "'> " + unownedIcon + "</span>"; //✘
}
}
if ($.inArray(appID, ignoredApps) > -1 && wantIgnores) { //if ignored and enabled
html += "<span style='color: " + ignoredColor + "; cursor: help;' title='Game or DLC (" + appID + ") ignored on Steam\nLast cached: " + lcs + "'> " + ignoredIcon + "</span>"; //🛇
}
var app = decommissioned.filter(function(obj) { return obj.appid === appID.toString(); })[0];
if (app && wantDecommissioned) { //if decommissioned and enabled
html += "<span style='color: " + decommissionedColor + "; cursor: help;' title='The " + app.type + " \"" + app.name.replace(/'/g, "") + "\" (" + appID + ") is " +
app.category.toLowerCase() + " and has only " + app.count + " confirmed owners on Steam\nLast cached: " + lcs + "'> " + decommissionedIcon + "</span>"; //🗑
}
if (wantCards && cachedCards.indexOf(appID) != -1) { //if has cards and enabled
let preLink = "";
let postLink = "";
if (linkCardIcon) {
preLink = `<a href="http://www.steamcardexchange.net/index.php?gamepage-appid-${appID}">`;
postLink = `</a>`;
}
html += `<span style='color: ${cardColor}; cursor: help;' title='The game (${appID}) has cards'> ${preLink}${cardIcon}${postLink}</span>`;
}
/*$(elem).html(prefix ?
html + $(elem).html() :
$(elem).html() + html);*/
if (prefix) {
$(elem).before(html);
} else {
$(elem).after(html);
}
$(elem).parent().css("overflow", "visible");
}, 0);
}
}
function doSub(elem, wishlist, ownedPackages, lcs) {
if (!$(elem).hasClass("goc")) {
$(elem).addClass("goc");
setTimeout(function() {
var subID = parseInt(elem.href.split("sub/")[1].split("/")[0].split("?")[0].split("#")[0]);
var html;
if ($.inArray(subID, ownedPackages) > -1) { //if owned
html = "<span style='color: " + ownedColor + "; cursor: help;' title='Package owned on Steam\nLast cached: " + lcs + "'> " + ownedIcon + "</span>"; //✔
} else { //else not owned
html = "<span style='color: " + unownedColor + "; cursor: help;' title='Package not owned on Steam\nLast cached: " + lcs + "'> " + unownedIcon + "</span>"; //✖
}
/*$(elem).html(prefix ?
html + $(elem).html() :
$(elem).html() + html);*/
if (prefix) {
$(elem).before(html);
} else {
$(elem).after(html);
}
$(elem).parent().css("overflow", "visible");
}, 0);
}
}
// ==/Code==
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment