Proton db

try to take over the world!

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Proton db
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://store.steampowered.com/app/*
// @grant         GM.xmlHttpRequest
// ==/UserScript==
// SteamPlay Whitelist
// Generated by get_whitelist.py on 2020-04-07

whitelist = [
    2280,
    2290,
    2300,
    2310,
    2360,
    2370,
    2390,
    2990,
    3300,
    3340,
    3980,
    4500,
    4580,
    4900,
    6060,
    6600,
    8200,
    8210,
    8220,
    8230,
    8240,
    8250,
    8260,
    8270,
    8280,
    8290,
    8300,
    9180,
    9450,
    15520,
    16300,
    22100,
    23310,
    24240,
    31220,
    31230,
    31240,
    31250,
    31260,
    31270,
    31280,
    32400,
    32460,
    32510,
    33120,
    38400,
    38410,
    40720,
    40950,
    48720,
    49470,
    57690,
    78000,
    94200,
    94400,
    94590,
    97330,
    104200,
    204360,
    207690,
    209690,
    210970,
    213670,
    215710,
    227000,
    234080,
    236450,
    237630,
    239350,
    246840,
    249050,
    268130,
    268910,
    269050,
    288160,
    314180,
    317280,
    322110,
    322170,
    342890,
    343780,
    344480,
    348250,
    348430,
    348440,
    350080,
    354970,
    355170,
    360380,
    360740,
    363440,
    364930,
    365260,
    366970,
    370060,
    374320,
    375310,
    375530,
    377860,
    379720,
    382900,
    388970,
    389730,
    397430,
    400630,
    412830,
    414700,
    435120,
    447150,
    448510,
    460950,
    462930,
    480640,
    490100,
    502720,
    505330,
    510540,
    511470,
    522470,
    524220,
    532110,
    534550,
    537520,
    540610,
    556180,
    557340,
    557600,
    575330,
    587000,
    588430,
    590380,
    618310,
    620980,
    650000,
    663210,
    674940,
    676820,
    691830,
    698780,
    705220,
    712180,
    717610,
    730820,
    744050,
    744190,
    744810,
    758190,
    764790,
    771070,
    782570,
    788770,
    820040,
    826600,
    887880,
    896420,
    897330,
    898940,
    905200,
    905260,
    909080,
    909110,
    910880,
    922400,
    935880,
    937170,
    952250,
    990400,
    1043180,
]

console.log(GM.xmlHttpRequest);


function calll (appid) {
    var url = "https://www.protondb.com/" + "api/v1/reports/summaries/" + appid + ".json";

    return new Promise((resolve, reject) => {
        GM.xmlHttpRequest({
            method: "GET",
            url: url,
            onload: function(response) {
                resolve(JSON.parse(response.responseText))
            },
            onerror: reject
        })
    }).catch(error => console.log(error))
    ;
}

class ProtonDB {
    static get HOMEPAGE() {return "https://www.protondb.com/";}
    static get API_SUMMARY() {return "api/v1/reports/summaries/";}

    static request_summary(appid, callback) {
        var request = new XMLHttpRequest();
        request.onreadystatechange = function () {
            callback(request);
        }
        request.open("GET", this.HOMEPAGE + this.API_SUMMARY + appid + ".json", true);
        request.send(null);
    }

    static request_rating(appid, callback)
    {
        calll(appid).then(callback);
    }
/*
    bestReportedTier: "platinum"
confidence: "strong"
score: 0.45
tier: "gold"
total: 109
trendingTier: "silver"
*/

    static get_rating_container(rating, whitelisted, key) {
        var container = document.createElement("div");

        container.className = "dev_row protondb_rating_row steam_row";
        container.title = "As seen by the community of ProtonDB.com";

        var link = document.createElement("a");
        link.className = "protondb_rating_link protondb_rating_" + rating[key];

        link.href = ProtonDB.HOMEPAGE + "app/" + Steam.get_app_id(window.location.href);
        link.textContent = rating[key];
        link.target = "_blank"

        if (whitelisted) {
            var star = document.createElement("span");
            star.className = "protondb_rating_whitelisted"
            star.title = "Whitelisted by Valve";
            star.textContent = " ★"

            link.appendChild(star);
        }

        container.appendChild(link);
        return container;
    }
}

class Steam {
    // Return a games appid from the url
    static get_app_id(url) {
        var appid = url.match(/\/(app)\/([0-9]{1,7})/);

        return parseInt(appid[2], 10);
    }

    // Insert the ProtonDB rating below DEVELOPER/PUBLISHER
    static insert_rating(rating, whitelisted, label, key) {
        var element = document.querySelector(".user_reviews");
        var subtitle = document.createElement("div");
        subtitle.className = "subtitle column'";
        subtitle.textContent = label;
        var container = ProtonDB.get_rating_container(rating, whitelisted, key);
        container.prepend(subtitle);

        if (element) {
            element.append(container);
        }
    }
}

// Main
var appid = Steam.get_app_id(window.location.href);
if (document.querySelector("span.platform_img.linux") === null) {
    ProtonDB.request_rating(appid, (rating) => {
        Steam.insert_rating(rating, null, 'ProtonDB score', 'score');
        Steam.insert_rating(rating, null, 'ProtonDB total', 'total');
        Steam.insert_rating(rating, null, 'ProtonDB max', 'bestReportedTier');
        Steam.insert_rating(rating, whitelist.includes(appid) ? true : false, 'ProtonDB Note', 'tier');
    });
} else {
    Steam.insert_rating("native");
}