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.

目前為 2017-04-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Steam Store - Game Owned Checker
// @icon         http://store.steampowered.com/favicon.ico
// @namespace    Royalgamer06
// @version      1.4.1
// @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 '✖'
const refreshInterval = 0;       // 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 cachedJson = GM_getValue("goc_data", null);
var lastCached = GM_getValue("goc_last", 0);
if (Date.now() - lastCached >= refreshInterval * 60000) {
    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: init
    });
} else {
    init(cachedJson);
}

function init(response) {
    var json = JSON.parse(response.responseText);
    var ownedApps = json.rgOwnedApps;
    var ownedPackages = json.rgOwnedPackages;
    var wishlist = json.rgWishlist;
    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) {
            cachedJson = JSON.parse(cachedJson);
            ownedApps = cachedJson.rgOwnedApps;
            ownedPackages = cachedJson.rgOwnedPackages;
            wishlist = cachedJson.rgWishlist;
        } else {
            lastCached = Date.now();
            GM_setValue("goc_last", lastCached);
            GM_setValue("goc_data", response);
        }
        var lcs = (new Date(lastCached)).toLocaleString();
        var appSelector = ":regex(href, ^(https?:)?\/\/(store\.steampowered\.com|steamcommunity\.com|steamdb\.info)\/(agecheck\/)?app\/[0-9]+(\/[\W].*|\/?)$)";
        var subSelector = ":regex(href, ^(https?:)?\/\/(store\.steampowered\.com|steamdb\.info)\/sub\/[0-9]+(\/[\W].*|\/?)$)";
        $(document).on("DOMSubtreeModified", appSelector, function() {
            doApp(this, wishlist, ownedApps, lcs);
        }).on("DOMSubtreeModified", subSelector, function() {
            doSub(this, wishlist, ownedPackages, lcs);
        }).ready(function() {
            $(appSelector).each(function() {
                doApp(this, wishlist, ownedApps, lcs);
            });
            $(subSelector).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==