Barter.vg, Thumbnail

always show thumbnail of game

目前為 2018-04-28 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Barter.vg, Thumbnail
// @namespace    http://tampermonkey.net/
// @version      0.5.1
// @description  always show thumbnail of game
// @author       You
// @match        https://barter.vg/*
// @grant        none
// @run-at       document-end
// @nowrap
// ==/UserScript==
(function() {
    var STORAGE_KEY = "BarterToSteamThumbnailMaps";
    var inBundle = location.pathname.indexOf("/bundles/") == 0;
    var inGiveways = location.pathname.indexOf("/giveways/") == 0;
    var inBrowse = location.pathname.indexOf("/browse/") == 0;
    var inWishlist = location.pathname.indexOf("/w/") > 0;
    var inTradable = location.pathname.indexOf("/t/") > 0;
    var inBlacklist = location.pathname.indexOf("/b/") > 0;
    var inScrachpad = location.pathname.indexOf("/c/") > 0;
    var inLibrary = location.pathname.indexOf("/l/") > 0;
    var inOffer = location.pathname.indexOf("/o/") > 0;
    var inInfo = location.pathname.indexOf("/i/") == 0;
    var inTraded = location.pathname.indexOf("/d/") > 0;
    var inFulfilled = location.pathname.indexOf("/f/") > 0;
    var isMatching = location.pathname.indexOf("/m/") > 0;
    var isEditing = location.pathname.indexOf("/e/") > 0;
    var isTurnOffImage = false;
    var isTurnOffElement = document.querySelector(".platform a[href*='?filter=']");
    if (isTurnOffElement) {
        isTurnOffImage = isTurnOffElement.href.split(",")[3].indexOf("1") == 0;
    }

    console.log({
        w: inWishlist,
        t: inTradable,
        b: inBlacklist,
        c: inScrachpad,
        e: isEditing,
        isTurnOffImage: isTurnOffImage
    });

    var thumbnailsMap = {};
    var map = localStorage[STORAGE_KEY];
    if (map) {
        thumbnailsMap = JSON.parse(map);
    }

    function makeThumbUrl(id) {
        return "https://steamcdn-a.akamaihd.net/steam/apps/" + id + "/capsule_184x69.jpg";
    }

    function tMatching(e, eid) {
        var li = e.parentNode;
        var sid = thumbnailsMap[eid];
        if (sid) {
            var bg = document.createElement("div");
            bg.setAttribute("isMutching", "");
            bg.style.backgroundImage = "url(" + makeThumbUrl(sid) + ")";
            li.insertBefore(bg, e.nextSibling);
            return;
        }

        var mm = document.querySelector("#mutualMatches");
        if (mm) {
            var m = mm.querySelectorAll(".listH a, .listW a");
            for (var j = 0; j < m.length; j++) {
                var a = m[j];
                var bid = a.href.match(/\d+/g)[0];
                if (thumbnailsMap[bid]) continue;

                var mbg = document.createElement("div");
                mbg.setAttribute("isMutching", "");
                mbg.style.backgroundImage = "url(" + makeThumbUrl(thumbnailsMap[bid]) + ")";
                a.appendChild(mbg);
            }
        }
    }

    function tElse(e, eid) {
        if (e.href.indexOf("#") >= 0) return;

        var tr = e.parentNode.parentNode;
        if (isEditing || inOffer) {
            tr = tr.parentNode;
        }
        var td = tr.querySelector("td");

        // console.log(tr, td);
        if (!td) return;

        if (inBundle) {
            tr.setAttribute("inBundle", "");
            td.setAttribute("inBundle", "");
            td.style.backgroundImage = "url(" + makeThumbUrl(eid) + ")";
        } else {
            tr.setAttribute("isTurnOff", "");
            td.setAttribute("isTurnOff", "");
            td.style.backgroundImage = "url(" + makeThumbUrl(eid) + ")";
        }

        var bid = tr.querySelector("a[href^='https://barter.vg/i/']").href.match(/\d+/g)[0];
        thumbnailsMap[bid] = eid;
    }

    function sElse(e, eid) {
        var sid = thumbnailsMap[eid];
        var td = e.parentNode;
        var tr = td.parentNode.parentNode;


        if (sid) {
         //   td.setAttribute("isTurnOff", "");
         //   tr.setAttribute("isTurnOff", "");
         //   td.style.backgroundImage = "url(" + makeThumbUrl(eid) + ")";
        }
    }

    function tOffer(e, eid) {
        if (e.href.indexOf("#") >= 0) return;

        var tr = e.parentNode.parentNode;
        if (tr.tagName.toLowerCase() == "td") {
            tr = tr.parentNode;
        }
        var td = tr.querySelector("td");

        //console.log(tr, td);
        if (!td) return;

        var bg = document.createElement("div");
        bg.setAttribute("inOffer", "");
        bg.style.backgroundImage = "url(" + makeThumbUrl(eid) + ")";
        td.appendChild(bg);
    }

    function main () {
        if (inInfo) {
            var bid = location.pathname.split("/")[2];
            var sid = document.querySelector(".platform a").href.split("/")[4];
            thumbnailsMap[bid] = sid;
        }

        var lines;
        if (inBrowse) {
            return document.querySelectorAll(".collection tr [href^='https://steamcommunity.com/my/gamecards/']");
        } else if (isMatching) {
            lines = document.querySelectorAll(".matchcol li a[href^='https://barter.vg/i/']");
        } else {
            lines = document.querySelectorAll(".collection tr [href^='https://store.steampowered.com/app/']");
        }

        // console.log("lines", lines);

        for (var i = 0; i < lines.length; i++) {
            var e = lines[i];
            var eid = e.href.match(/\d+/g)[0];

            if (inTradable || inWishlist || inBlacklist || inScrachpad || inBundle || inLibrary) {
                if (isMatching) {
                    tMatching(e, eid);
                } else {
                    tElse(e, eid);
                }
            } else if (inTraded || inFulfilled) {
                tElse(e, eid);
            } else if (inOffer) {
                tOffer(e, eid);
            }
        }

        var subs = document.querySelectorAll(".collection tr.included [href^='https://barter.vg/i/']");
        for (var i = 0; i < subs.length; i++) {
            sElse(subs[i], subs[i].href.match(/\d+/g)[0]);
        }

        localStorage[STORAGE_KEY] = JSON.stringify(thumbnailsMap);

        var style = document.createElement("style");
        style.innerHTML = "\
.mh a, .mw a { display: inline-block; position: relative; }\
.matchcol li { position: relative; }\
.matchcol .showMoreArea { margin-top: 2px; }\
.collection tr { position: relative; }\
[isMutching] { position: absolute; width: 190px; left: 150px; top: 0; bottom: 0; z-index: -1;\
opacity: 0.5; background: left center no-repeat; background-size: cover; height: 2em; }\
td[inBundle] { width: 184px; background-repeat: no-repeat !important; }\
td[inBundle]+td { padding-left: 8px; }\
td[isTurnOff] { background-position: 2px center !important; background-repeat: no-repeat !important; padding-left: 190px; }\
tr[isTurnOff] { }\
div[inOffer] { position: absolute; width: 150px; right: 100px; top: 1px; bottom: 0; z-index: 1;\
opacity: 0.5; background: left center no-repeat; background-size: cover !important; }\
.collection th a:visited, .matchcol a:visited { color: #00f !important; }\
#listEdit { z-index: 100; }";
        document.querySelector("head").appendChild(style);
    }
    main();
    // Your code here...
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址