Steam Store - Game Owned Checker

Check every web page for game, dlc and package links to the steam store and mark if it's owned, unowned or wishlisted.

От 24.04.2017. Виж последната версия.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

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

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name         Steam Store - Game Owned Checker
// @icon         http://store.steampowered.com/favicon.ico
// @namespace    Royalgamer06
// @version      1.3.2
// @description  Check every web page for game, dlc and package links to the steam store and mark if it's owned, unowned or wishlisted.
// @supportURL   https://www.steamgifts.com/discussion/y9vVm/
// @author       Royalgamer06
// @include      /^https?\:\/\/.+/
// @exclude      /^https?\:\/\/.+\.steampowered\.com.*/
// @grant        GM_xmlhttpRequest
// @grant        GM_openInTab
// @grant        GM_info
// @grant        GM_getValue
// @grant        GM_setValue
// @run-at       document-start
// @connect      store.steampowered.com
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// ==/UserScript==

// ==Configuration==
const prefix = false;            // Prefix (true) instead of suffix (false) position icon
const wishlistIcon = "❤"; // HTML entity code for '❤'
const ownedIcon = "✔";    // HTML entity code for '✔'
const unownedIcon = "✖";  // HTML entity code for '✖'
// ==/Configuration==

// ==Code==
this.$ = this.jQuery = jQuery.noConflict(true);
GM_xmlhttpRequest({
    method: "GET",
    url: "http://store.steampowered.com/dynamicstore/userdata/",
    ignoreCache: true,
    onload: init
});

function init(response) {
    var json = JSON.parse(response.responseText);
    var ownedApps = json.rgOwnedApps;
    var ownedPackages = json.rgOwnedPackages;
    var wishlist = json.rgWishlist;
    var cachedJson = JSON.parse(GM_getValue("goc_data", null));
    var lastCached = GM_getValue("goc_last", 0);
    if (ownedApps.length === 0 && ownedPackages.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 && wishlist.length === 0) {
            ownedApps = cachedJson.rgOwnedApps;
            ownedPackages = cachedJson.rgOwnedPackages;
            wishlist = cachedJson.rgWishlist;
        } else {
            lastCached = Date.now();
            GM_setValue("goc_last", lastCached);
            GM_setValue("goc_data", JSON.stringify(json));
        }
        var lcs = (new Date(lastCached)).toLocaleString();
        $(document).on("DOMSubtreeModified", "[href*='//steamcommunity.com/app/'], [href*='//steamdb.info/app/'], [href*='//store.steampowered.com/app/'], [href*='//store.steampowered.com/agecheck/app/']", function() {
            doApp(this, wishlist, ownedApps, lcs);
        }).on("DOMSubtreeModified", "[href*='//store.steampowered.com/sub/'], [href*='//steamdb.info/sub/']", function() {
            doSub(this, wishlist, ownedPackages, lcs);
        }).ready(function() {
            $("[href*='//steamcommunity.com/app/'], [href*='//steamdb.info/app/'], [href*='//store.steampowered.com/app/'], [href*='//store.steampowered.com/agecheck/app/']").each(function() {
                doApp(this, wishlist, ownedApps, lcs);
            });
            $("[href*='//store.steampowered.com/sub/'], [href*='//steamdb.info/sub/']").each(function() {
                doSub(this, wishlist, ownedPackages, lcs);
            });
        });
    }
}

function doApp(elem, wishlist, ownedApps, lcs) {
    if (!$(elem).hasClass("goc")) {
        $(elem).addClass("goc");
        setTimeout(function() {
            var appID = parseInt(elem.href.split("app/")[1].split("/")[0].split("?")[0].split("#")[0]);
            var html;
            if ($.inArray(appID, ownedApps) > -1) { //if owned
                html = "<span style='color: green; cursor: help' title='Game or DLC owned on Steam\nLast cached: " + lcs + "'> " + ownedIcon + "</span>"; //✔
            } else { //else not owned
                if ($.inArray(appID, wishlist) > -1) { //if wishlisted
                    html = "<span style='color: HotPink; cursor: help' title='Game or DLC wishlisted on Steam\nLast cached: " + lcs + "'> " + wishlistIcon + "</span>"; //❤
                } else { //else not wishlisted
                    html = "<span style='color: red; cursor: help' title='Game or DLC not owned on Steam\nLast cached: " + lcs + "'> " + unownedIcon + "</span>"; //✖
                }
            }
            $(elem).html(prefix ?
                         html + $(elem).html() :
                         $(elem).html() + html);
        }, 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: green; cursor: help' title='Package owned on Steam\nLast cached: " + lcs + "'> " + ownedIcon + "</span>"; //✔
            } else { //else not owned
                html = "<span style='color: red; cursor: help' title='Package not owned on Steam\nLast cached: " + lcs + "'> " + unownedIcon + "</span>"; //✖
            }
            $(elem).html(prefix ?
                         html + $(elem).html() :
                         $(elem).html() + html);
        }, 0);
    }
}
// ==/Code==