Steam Workshop Items File Size

Adds file size to Steam Workshop items

  1. // ==UserScript==
  2. // @name Steam Workshop Items File Size
  3. // @namespace steam-workshop-itens-file-size
  4. // @version 1.02
  5. // @description Adds file size to Steam Workshop items
  6. // @author Pedro Henrique
  7. // @match https://steamcommunity.com/workshop/browse*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14. // Função para obter o tamanho do arquivo de um URL
  15. function getFileSize(url) {
  16. return fetch(url)
  17. .then(response => response.text())
  18. .then(html => {
  19. const parser = new DOMParser();
  20. const doc = parser.parseFromString(html, "text/html");
  21. const fileSize = doc.getElementsByClassName("detailsStatRight")[0].innerHTML;
  22.  
  23. return fileSize;
  24. })
  25. .catch(error => {
  26. console.error("Error getting file size:", error);
  27. return "N/A";
  28. });
  29. }
  30.  
  31. // Função para adicionar o tamanho do arquivo abaixo de cada item
  32. function addFileSizeToItems() {
  33. const items = document.getElementsByClassName("workshopItem");
  34.  
  35. for (let i = 0; i < items.length; i++) {
  36. const item = items[i];
  37. const link = item.getElementsByTagName("a")[0];
  38. const url = link.href;
  39. getFileSize(url)
  40. .then(fileSize => {
  41. const fileSizeElement = document.createElement("div");
  42. fileSizeElement.className = "workshopItemFileSize";
  43. fileSizeElement.innerHTML = "Size: " + fileSize;
  44. item.appendChild(fileSizeElement);
  45. });
  46. }
  47. }
  48.  
  49. // Aguarda o carregamento completo da página e adiciona o tamanho do arquivo aos itens
  50. window.addEventListener("load", () => {
  51. addFileSizeToItems();
  52. });
  53.  
  54. })();