Steam Workshop Itens File Size

Adiciona tamanho de arquivo aos itens do Steam Workshop

目前為 2023-07-04 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Steam Workshop Itens File Size
// @namespace    steam-workshop-itens-file-size
// @version      1.0
// @description  Adiciona tamanho de arquivo aos itens do Steam Workshop
// @author       Pedro Henrique
// @match        https://steamcommunity.com/workshop/browse/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    // Este codigo foi feito com ajuda 99% do ChatGPT em questão de segundos, portanto não tem direitos autorais, o codigo pode ser seu, você pode fazer o que quiser.



    // 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;
                    console.log(fileSizeElement.innerHTML);

                    item.appendChild(fileSizeElement);
                });
        }
    }

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

})();