您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
HLTB times in Backloggd Lists
当前为
// ==UserScript== // @name HLTB in Backloggd Lists // @namespace http://tampermonkey.net/ // @version 0.1 // @description HLTB times in Backloggd Lists // @author Siev // @license MIT // @match *://backloggd.com/*/list/*/grid/ // @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"); }}); } })();