Steam Workshop Items File Size

Adds file size to Steam Workshop items

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Steam Workshop Items File Size
// @namespace    steam-workshop-itens-file-size
// @version      1.02
// @description  Adds file size to Steam Workshop items
// @author       Pedro Henrique
// @match        https://steamcommunity.com/workshop/browse*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    // Função para obter o tamanho do arquivo de um URL
    function getFileSize(url) {
        return fetch(url)
            .then(response => response.text())
            .then(html => {
                const parser = new DOMParser();
                const doc = parser.parseFromString(html, "text/html");
                const fileSize = doc.getElementsByClassName("detailsStatRight")[0].innerHTML;

                return fileSize;
            })
            .catch(error => {
                console.error("Error getting file size:", error);
                return "N/A";
            });
    }

    // Função para adicionar o tamanho do arquivo abaixo de cada item
    function addFileSizeToItems() {
        const items = document.getElementsByClassName("workshopItem");

        for (let i = 0; i < items.length; i++) {
            const item = items[i];
            const link = item.getElementsByTagName("a")[0];
            const url = link.href;
            getFileSize(url)
                .then(fileSize => {
                    const fileSizeElement = document.createElement("div");
                    fileSizeElement.className = "workshopItemFileSize";
                    fileSizeElement.innerHTML = "Size: " + fileSize;
                    item.appendChild(fileSizeElement);
                });
        }
    }

    // Aguarda o carregamento completo da página e adiciona o tamanho do arquivo aos itens
    window.addEventListener("load", () => {
        addFileSizeToItems();
    });

})();