|
// ==UserScript== |
|
// @name Steam Total Hours |
|
// @namespace https://gist.github.com/bobpaw |
|
// @version 3.0.2 |
|
// @author Aiden Woodruff |
|
// @description Adds a total hours textbox summing the total gameplay hours for a Steam account. |
|
// @source https://gist.github.com/bobpaw/0b4ad6cb8070546bdd3aac9b341d2ad3 |
|
// @updateURL https://gist.githubusercontent.com/bobpaw/0b4ad6cb8070546bdd3aac9b341d2ad3/raw/steam_totalhours.user.js |
|
// @downloadURL https://gist.githubusercontent.com/bobpaw/0b4ad6cb8070546bdd3aac9b341d2ad3/raw/steam_totalhours.user.js |
|
// @match https://steamcommunity.com/id/*/games/* |
|
// @match https://steamcommunity.com/profiles/*/games/* |
|
// @grant none |
|
// @run-at document-idle |
|
// ==/UserScript== |
|
|
|
(function() { |
|
"use strict"; |
|
let total_hours_span = document.createElement("span"); |
|
total_hours_span.appendChild(document.createTextNode("Total hours: ")); |
|
let total_hours = document.createTextNode("Calculating..."); |
|
total_hours_span.appendChild(total_hours); |
|
total_hours_span.style.paddingLeft = "1em"; |
|
document.querySelector(".profile_small_header_text").appendChild(total_hours_span); |
|
|
|
// Make sure all games are loaded. |
|
let timeout_handle = window.setInterval(function () { |
|
const activeTab = document.getElementsByClassName("sectionTab active"); |
|
if (activeTab.length === 0) {console.error("No active tab found"); return;} |
|
// Get the number of games. |
|
const num_text = activeTab[0].innerText; |
|
// Silently error if we are not on the All Games tab. |
|
if (!num_text.startsWith("All Games (") || !num_text.endsWith(")")) {console.error("Not on all games tab. on " + num_text); return;} |
|
const num_games = parseInt(num_text.substring(11, num_text.length - 1)); |
|
|
|
const game_items = document.getElementsByClassName("gameslistitems_GamesListItemContainer_29H3o"); |
|
if (num_games === game_items.length) { |
|
window.clearInterval(timeout_handle); |
|
total_hours.textContent = Array.from(document.getElementsByClassName("gameslistitems_Hours_26nl3")) |
|
.map(x => parseFloat(x.lastChild.textContent)) |
|
.filter(x => !isNaN(x)) |
|
.reduce((x, y) => x + y, 0) |
|
.toFixed(1); |
|
} else { |
|
console.error("Wanted " + num_games + ". got " + game_items.length); |
|
} |
|
}, 500); |
|
})(); |