HLTB in Backloggd Lists

HLTB times in Backloggd Lists

目前为 2024-01-04 提交的版本。查看 最新版本

// ==UserScript==
// @name         HLTB in Backloggd Lists
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  HLTB times in Backloggd Lists
// @author       Siev
// @license      MIT
// @match        *://backloggd.com/*/list/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=backloggd.com
// @grant        GM_xmlhttpRequest
// ==/UserScript==

var hltbTime;
var bgcolor;

(function() {
    //'use strict';

    // Grab Steam game name (and get rid of symbols)
    let hltbUrl = "https://howlongtobeat.com/api/search/";

// Set POST string w/ correct game name


    for (var game of document.getElementsByClassName("card")) {
        let gameName = game.getElementsByClassName("game-text-centered")[0].textContent;
        let hltbQuery = '{"searchType":"games","searchTerms":["'+gameName+'"],"size":100}';

        GM_xmlhttpRequest({
            context: game,
            method: "POST",
            url: hltbUrl,
            data: hltbQuery,
            headers: {
                "Content-Type": "application/json",
                "origin": "https://howlongtobeat.com",
                "referer": "https://howlongtobeat.com"
            },
            onload: function (response) {

                let game = response.context;
                        // Grab response
                let hltb = JSON.parse(response.responseText);

                //Determine if data is present in response by checking the page count.  If no data, set default HLTB button.
                let hltbPages = hltb['pageTotal'];
                if(hltbPages == 0) {
                    hltbTime = "HLTB";
                    bgcolor = "ff8c00";
                    //console.log("\x1b[36m[HLTB-Response]: \x1b[37mNo Response");
                } else {

                    //If data is present in response, let's rock!
                    //Show response in console for debugging purposes (or comment to hide)
                    let hltbstring = JSON.stringify(hltb);
                    //console.log("\x1b[36m[HLTB-Response]: \x1b[37m" + hltbstring);

                    //Make sure you have the right game_name (if possible, otherwise just use first result from response)
                    let n = 0;
                    let loop = hltb['count'];
                    for (let i = 0; i < loop; i++) {
                        let hltbName = hltb['data'][i]['game_name'];
                        if (hltbName.toLowerCase() == gameName.toLowerCase()) {
                            //console.log("\x1b[36m[HLTB-GameName]: \x1b[37m" + hltbName);
                            n = i;
                            break;
                        }
                    }

                    // Extract time for "Main Story" and convert into hours
                    hltbTime = hltb['data'][n]['comp_main'];
                    hltbTime = hltbTime/60/60;                            // Convert to hours
                    hltbTime = Math.round(hltbTime*2)/2;                  // Round to closes .5
                    hltbTime = hltbTime.toString() .replace(".5","½");    // Convert .5 to ½ to be consistent with HLTB
                    //console.log("\x1b[36m[HLTB-MainTime]: \x1b[37m" + hltbTime);

                }

                game.parentNode.append(hltbTime + " Hours");


        }});

    }

})();

QingJ © 2025

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