Skip to content

Instantly share code, notes, and snippets.

@exp111
Last active January 14, 2024 07:38
Show Gist options
  • Save exp111/61c0aa63bd53bf4ec7f9ba037d7a96ca to your computer and use it in GitHub Desktop.
Save exp111/61c0aa63bd53bf4ec7f9ba037d7a96ca to your computer and use it in GitHub Desktop.
Steam Collection Download Size Calculator
// ==UserScript==
// @name Steam Collection Download Size Calculator
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Calculates the download size in mb
// @author Exp
// @match http://steamcommunity.com/sharedfiles/filedetails/?id=*
// @match https://steamcommunity.com/sharedfiles/filedetails/?id=*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// First of all, is this an applicable Workshop page? The @match isn't enough
// So, are we...
// 1. A collection?
var navigation = document.getElementsByClassName("breadcrumbs")[0];
if (navigation.children[2].href.search("collections") == -1)
{
return;
}
var total = 0;
var items = document.getElementsByClassName("collectionItemDetails");
var parentLeft = document.getElementsByClassName("detailsStatsContainerLeft")[0];
var parentRight = document.getElementsByClassName("detailsStatsContainerRight")[0];
var shitRight = document.createElement("div");
shitRight.className = "detailsStatRight";
shitRight.innerText = "Total Download Size";
parentRight.appendChild(shitRight);
var myMB = document.createElement("div");
myMB.className = "detailsStatLeft";
myMB.innerText = "0 MB";
parentLeft.appendChild(myMB);
for (var i = 0; i < items.length; i++)
{
var item = items[i];
var link = item.firstElementChild.href;
fetch(link)
.then(function(response) {
return response.text();
})
.then(function(body) {
var target = document.createElement("html"); //create a new html element (so we can insert the booty into it)
target.innerHTML = body;
var stat = target.getElementsByClassName("detailsStatRight")[0];
if (stat == undefined)
{
return;
}
var mb = stat.innerText.slice(0, 6);
total += Number(mb);
myMB.innerText = total.toFixed(2) + " MB";
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment