Skip to content

Instantly share code, notes, and snippets.

@drguildo
Last active June 30, 2017 19:42
Show Gist options
  • Save drguildo/6ea585ee8e03ad5567c305c6ddbd2e88 to your computer and use it in GitHub Desktop.
Save drguildo/6ea585ee8e03ad5567c305c6ddbd2e88 to your computer and use it in GitHub Desktop.
Greasemonkey/Tampermonkey script to convert Steam's decimal time played (e.g. "4.7 hrs") to hours and minutes
// ==UserScript==
// @name Sane Steam Playtimes
// @namespace http://sjm.io/
// @version 0.1
// @description Convert Steam's decimal time played (e.g. "4.7 hrs") to hours and minutes
// @author Simon Morgan
// @match http://steamcommunity.com/id/*
// @grant none
// ==/UserScript==
(function () {
"use strict";
let timeString = /\d+\.\d\s+hrs/;
let hoursString = /\d+\.\d/;
function decimalToHoursMinutes(decimalTime) {
let hours = Math.floor(decimalTime);
let minutes = Math.floor((decimalTime % 1) * 60);
return hours + " hrs" + (minutes > 0 ? ", " + minutes + " mins" : "");
}
function processElement(e) {
if (timeString.test(e.innerHTML)) {
let hours = e.innerHTML.match(hoursString);
e.innerHTML = e.innerHTML.replace(timeString, decimalToHoursMinutes(
hours[0]));
}
}
let gameDetailsElements = document.querySelectorAll(
"div.game_info > div.game_info_details");
gameDetailsElements.forEach(processElement);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment