SteamTrades - Have List Filter

Check if you own the games from someone's have list (instant Compare2Steam)

目前為 2017-02-03 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         SteamTrades - Have List Filter
// @namespace    Royalgamer06
// @version      1.3
// @description  Check if you own the games from someone's have list (instant Compare2Steam)
// @author       Royalgamer06
// @match        https://www.steamtrades.com/trade/*
// @grant        GM_xmlhttpRequest
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_setClipboard
// @support      https://www.steamgifts.com/discussion/fN8vR/userscript-steamgifts-trades-have-list-filter-compare2steam-alternative
// @connect      steamcommunity.com
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// ==/UserScript==

//If you want to set your/another SteamID64 manually, state it here between brackets. (For example, to check owned games from someone else)
var manual_steamID = "";

//Set your steam sync interval in hours. (Set to 0 if you want to force a sync)
var sync_interval = 6;

//Set link to search game to SteamDB instead of the Steam Store? (SteamDB finds removed games from the steam store and gives better results overall)
var steamdb_instead = false;

//Do not touch below :)
this.$ = this.jQuery = jQuery.noConflict(true);
$(document).ready(function() {
    $(".have").parent().find(".trade_heading").first().html("I have... (<a href='javascript:void(0)' id='filter' style='text-decoration:underline;color:rgb(120,169,71)' title='Check have-list for owned games. \n" +
                                                            "Warning: It may become unresponsive for a while.'>Filter</a>)");
    $("#filter").click(function() {
        $("#filter").removeAttr("style").html("<i class='fa fa-spin fa-circle-o-notch' />");
        if (manual_steamID.length == 17) {
            syncHandler(manual_steamID);
        } else if (GM_getValue("steamID") !== undefined) {
            syncHandler(GM_getValue("steamID"));
        } else {
            if ($(".nav_avatar").length > 0) {
                var steamID = $(".nav_avatar").attr("href").split("user/")[1];
                if (steamID.length == 17) {
                    GM_setValue("steamID", steamID);
                    syncHandler(steamID);
                } else {
                    alert("[Have List Filter] ERROR: Invalid SteamID. Refresh the page to try again, or set manual SteamID");
                }
            } else {
                alert("[Have List Filter] ERROR: Could not fetch SteamID automatically. Refresh the page to try again, or set manual SteamID");
            }
        }
    });
});

function syncHandler(steamID) {
    var now = new Date().valueOf();
    var last = GM_getValue("lastsync");
    if (last === undefined) {
        GM_setValue("lastsync", now);
        syncHandler(steamID);
    } else if ((now - last) / 3600000 > sync_interval || GM_getValue("ownedSteamGames") === undefined || GM_getValue("wlSteamGames") === undefined) {
        GM_xmlhttpRequest({
            method: "GET",
            url: "http://steamcommunity.com/profiles/" + steamID + "/games/?xml=1",
            onload: function(gdata) {
                var xml = $.parseXML(gdata.responseText);
                var ownedSteamGames = [];
                $("name", xml).each(function() {
                    ownedSteamGames.push($(this).text().toLowerCase().replace(/\:|\-|\–|\\|\/|\™|\®| |\'|\.|\?|\!/g, ""));
                });
                GM_setValue("ownedSteamGames", ownedSteamGames.join("-"));
                GM_xmlhttpRequest({
                    method: "GET",
                    url: "http://steamcommunity.com/profiles/" + steamID + "/wishlist",
                    onload: function(wldata) {
                        var wlSteamGames = [];
                        $("#wishlist_items h4", wldata.responseText).each(function() {
                            wlSteamGames.push($(this).text().toLowerCase().replace(/\:|\-|\–|\\|\/|\™|\®| |\'|\.|\?|\!/g, ""));
                        });
                        GM_setValue("wlSteamGames", wlSteamGames.join("-"));
                        GM_setValue("lastsync", now);
                        console.log("[Have List Filter] Synced with steam!");
                        filterHaveList(ownedSteamGames, wlSteamGames);
                    }
                });
            }
        });
    } else {
        var ownedSteamGames = GM_getValue("ownedSteamGames");
        var wlSteamGames = GM_getValue("wlSteamGames");
        filterHaveList(ownedSteamGames.split("-"), wlSteamGames.split("-"));
    }
}

function filterHaveList(ownedSteamGames, wlSteamGames) {
    if (!document.getElementsByClassName("have")[0].getElementsByTagName('table').length) {
        var have = document.getElementsByClassName("have")[0].innerText.split("\n");
    } else {
        var have = $('.have tr td:first-child').map(function(a,b){return $(b).text(); }).toArray();
    }
    var have_unowned = "";
    var have_unowned_raw = "";
    have.forEach(function(game) {
        if (game.length > 1 && game.length < 80) {
            // Ignoring everything between and including brackets, and also these symbols: :, -, –, \, /, ™, ®,  , ', ., ? and ! (Better suggestions? Please contact me)
            if ($.inArray(game.toLowerCase().replace(/( *\[[^)]*\] *)|( *\([^)]*\) *)|\=.*|\:|\-|\–|\\|\/|\™|\®| |\'|\.|\?|\!/g, ""), wlSteamGames) > -1) { //Game is wishlisted
                //console.log (game + ": wishlisted");
                $(".have").html($(".have").html().replace(game, "<i class='fa icon-purple fa-heart' style='color:purple;' title='You have this game wishlisted on steam'></i> " + game));
            }
            if ($.inArray(game.toLowerCase().replace(/( *\[[^)]*\] *)|( *\([^)]*\) *)|\=.*|\:|\-|\–|\\|\/|\™|\®| |\'|\.|\?|\!/g, ""), ownedSteamGames) > -1) { //Game is owned
                //console.log (game + ": owned");
                $(".have").html($(".have").html().replace(game, "<i class='fa icon-green fa-check-circle' style='color:green;' title='You own this game on steam'></i> " + game));
            } else { //Game is not owned or unknown game
                //console.log (game + ": not owned");
                $(".have").html($(".have").html().replace(game.replace(/( *\[[^)]*\] *)|( *\([^)]*\) *)|\=.*/g,""),
                                                          "<i class='fa icon-red fa-times-circle' style='color:red;' title='You do not own this game on steam, or unknown game: \nPlease check manually'></i> " +
                                                          game.replace(/( *\[[^)]*\] *)|( *\([^)]*\) *)|\=.*/g,"") + " <a href='" +
                                                          (steamdb_instead ? "https://steamdb.info/search/?a=app&q=" : "https://store.steampowered.com/search/?term=") +
                                                          encodeURIComponent(game.replace(/( *\([^)]*\) *)/g,"")) +
                                                          "' target='_blank'><i class='fa icon-grey fa-external-link' title='Search game on " +
                                                          (steamdb_instead ? "SteamDB" : "Steam") +
                                                          "'></i></a> "));
                have_unowned += game.replace(/(\"|\')|\=.*/g, '') + "&#013;";
                have_unowned_raw += game + "\n";
            }
        }
    });
    $(".trade_heading").first().html("<i id='clip' data-clipboard-text='" + have_unowned + "' class='icon_to_clipboard fa fa-fw fa-copy' style='cursor: pointer' title='Copy unowned/unknown games to clipboard'></i> I have...");
    $("#clip").click(function() {
        GM_setClipboard(have_unowned_raw);
        alert("Successfully copied unowned have-list games to clipboard!");
    });
}