steamgifts rating and platforms

Show rating and supported platforms on sitesteamgifts.com according information from store.steampowered.com

当前为 2016-07-29 提交的版本,查看 最新版本

// ==UserScript==
// @name         steamgifts rating and platforms
// @namespace    Gidden
// @version      1.1
// @description  Show rating and supported platforms on sitesteamgifts.com according information from store.steampowered.com
// @require      http://code.jquery.com/jquery.min.js
// @author       Gidden
// @match        http://www.steamgifts.com/
// @match        http://www.steamgifts.com/giveaways/search?*
// @match        https://www.steamgifts.com/
// @match        https://www.steamgifts.com/giveaways/search?*
// @grant        GM_xmlhttpRequest
// ==/UserScript==

function supports_html5_storage() {
  try {
    return 'localStorage' in window && window.localStorage !== null;
  } catch (e) {
    return false;
  }
}

function getColor(value){
    //value from 0 to 1
    var hue=((value)*120).toString(10);
    return ["hsl(",hue,",100%,42%)"].join("");
}

var platforms = ["win", "mac", "linux", "steamplay"];

function getFilterCfg(myItem)
{
    if (myItem == "percentage") {
        myValue = 0;
    } else {
        myValue = 1;
    }
    if (supports_html5_storage()) {
        if (localStorage.getItem(myItem) !== null) {
            myValue = localStorage.getItem(myItem);
        }
    }
    return myValue;
}

var filterFunction = "" +
"var platforms = [\"win\", \"mac\", \"linux\", \"steamplay\"];" +
"function supports_html5_storage() {" +
"  try {" +
"    return 'localStorage' in window && window.localStorage !== null;" +
"  } catch (e) {" +
"    return false;" +
"  }" +
"}" +
"function saveFilterCfg()" +
"{" +
"    if (supports_html5_storage()) {" +
"        for (var x in platforms){" +
"            platform = platforms[x];" +
"            if (document.getElementById(\"filter_\" + platform).checked) {" +
"                localStorage.setItem(platform, 1);" +
"            } else {" +
"                localStorage.setItem(platform, 0);" +
"            }" +
"        }" +
"    if (document.getElementById(\"filter_level\").checked) {" +
"        localStorage.setItem(\"level\", 1);" +
"    } else {" +
"        localStorage.setItem(\"level\", 0);" +
"    }" +
"        localStorage.setItem(\"percentage\", document.getElementById(\"filter_percentage\").value);" +
"    }" +
"}" +
"function changeFilter(){" +
"" +
"    platformCheck = [];" +
"    for (var x in platforms){" +
"        platform = platforms[x];" +
"        if (document.getElementById(\"filter_\" + platform).checked) {" +
"            platformCheck.push(platform);" +
"        }" +
"    }" +
"    percCheck = document.getElementById(\"filter_percentage\").value;" +
"" +
"    var headers = $(\"div.giveaway__summary h2.giveaway__heading\");" +
"" +
"    headers.each(function() {" +
"        var header = $(this);" +
"        var showEl = true;" +
"" +
"        if (document.getElementById(\"filter_level\").checked){" +
"            if (header.parent().find(\"div.giveaway__column--contributor-level--negative\").length) {" +
"                header.parent().parent().parent().hide();" +
"                return;" +
"            }" +
"        }" +
"" +
"        percE = header.find(\"span.percentage\");" +
"" +
"        if (percE.length)" +
"        {" +
"            perc = percE[0].getAttribute(\"perc\");" +
"            if (perc < percCheck){" +
"                showEl = false;" +
"            } else {" +
"                showEl = false;" +
"                for (var x in platformCheck){" +
"                    actPlatformCheck = platformCheck[x];" +
"                    if (header.find(\"span.\"+actPlatformCheck).length) {" +
"                       showEl = true;" +
"                    }" +
"                }" +
"            }" +
"        }" +
"" +
"        if (showEl) {" +
"            header.parent().parent().parent().show();" +
"        } else {" +
"            header.parent().parent().parent().hide();" +
"        }" +
"    });" +
"    saveFilterCfg();" +
"}";

var checkboxes = "";

for (var x in platforms){
    platform = platforms[x];
    var checked = "";
    if (getFilterCfg(platform) == 1) {
        checked = "checked";
    }
    checkboxes += "<input class=\"filter_checkboxes\" type=\"checkbox\" name=\"filter_" + platform + "\" id=\"filter_" + platform + "\" onclick=\"changeFilter();\" " + checked + "><label class=\"checkboxes\" for=\"filter_" + platform + "\"><span class=\"platform_img " + platform + "\"></span></label>";
}


$("head link:last")
.after("<link rel=stylesheet type=text/css href=https://steamstore-a.akamaihd.net/public/css/v6/store.css>")
.after("<style>span.platform_img {background-color: black; height:20px; display: inline-block; opacity: 0.35;} input.filter_checkboxes {height:15px; width:20px;} input.filter_percentage {height:18px; width:40px; margin:5px; padding:0px 10px;} label.checkboxes {margin-right:5px;}</style>")
.after("<style>h2.giveaway__heading {position:relative;} span img {width: 20px; height: 16px;} span.right_allign {position:absolute; right: 0;}</style>")
.after("<script type=\"text/javascript\">" + filterFunction + "</script>");

var checkedLevel = "";
if (getFilterCfg("level") == 1) {
    checkedLevel = "checked";
}

filterPanel = "<h3 class=\"sidebar__heading\">Filter</h3><div style=\"margin-left:10px;\">" +
    " <span style=\"font-weight: bold;\">Game</span> &gt;= <input type=\"text\" class=\"filter_percentage\" id=\"filter_percentage\" value=\"" + getFilterCfg("percentage") + "\" onchange=\"changeFilter()\" onkeyup=\"changeFilter()\">% <br>" +
    checkboxes + "</br>" +
    "<input type=\"checkbox\" class=\"filter_checkboxes\" id=\"filter_level\" onclick=\"changeFilter();\" " + checkedLevel + "><label class=\"checkboxes\" for=\"filter_level\"><span style=\"font-weight: bold;\">Hide higher level</span></label>" +
    "</div>";

$("div.sidebar__search-container").after(filterPanel);

var headers = $("div.giveaway__summary h2.giveaway__heading");

headers.each(function() {
    var header = $(this);
    var steamURL = header.find( "a.giveaway__icon").attr("href").trim();

    if ((getFilterCfg("level") == 1) && (header.parent().find("div.giveaway__column--contributor-level--negative").length)) {
        header.parent().parent().parent().hide();
    }

    GM_xmlhttpRequest({
        method: "GET",
        url: steamURL,
        onload: function(response) {
            a_tag = header.find( "a.giveaway__icon" );
            i_tag = header.find( "i.giveaway__icon" );
            a_tag.attr("style", "opacity:1");

            var ppl = false;
            var perc = false;


            var ratingFull = $(response.responseText).find("div.glance_ctn div[itemprop=aggregateRating]").attr("data-store-tooltip");
            if (ratingFull.length > 0) {
                ratingFull = ratingFull.trim().split(" ");
                $.each(ratingFull, function(i, val) {
                    var rat = val.replace(",", ".");
                    if ($.isNumeric(rat)) {
                        ppl = rat;}
                    if (rat.slice(-1) == "%") {
                        perc = rat.slice(0,-1);
                    }
                });
                rating = perc + '%(' + ppl + ')';
                a_tag.append(" <span style=\"color:" + getColor(perc /100.0) + "\" class=\"percentage\" perc=\"" + perc + "\">" + rating + "</span>");
            }

            var platform = $(response.responseText).find("div.game_area_purchase_platform");
            if (platform.length) {
                a_tag.append(" <span>" + platform.html() + "</span>");
            }

            if (platform.length) {
                var cards = $(response.responseText).find("a[href*='http://store.steampowered.com/search/?category2=29']");
                if (cards.length) {
                    i_tag.after("<span class=\"platform_img right_allign\"><img src=\"http://store.akamai.steamstatic.com/public/images/v6/ico/ico_cards.png\"></span>");
                }
            }

            if ((perc < getFilterCfg("percentage"))) {
                header.parent().parent().parent().hide();
            }

            hide = true;
            for (var x in platforms) {
                platformCheck = platforms[x];
                if (platform.find("span."+platformCheck).length && (getFilterCfg(platformCheck) == 1)) {
                    hide = false;
                }
            }
            if (hide) {
                header.parent().parent().parent().hide();
            }
        }
    });
});

QingJ © 2025

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