Export SteamDB Search

Adds a button to export current search in SteamDB as TSV

目前为 2025-01-12 提交的版本。查看 最新版本

// 👋 Hola, usa 🐒Tampermonkey 👇
// https://www.tampermonkey.net/

// ==UserScript==
// @name            Export SteamDB Search
// @name:es         Exportar Busquedas de SteamDB
// @name:it         Esporta Ricerca SteamDB
// @name:fr         Exporter les recherches SteamDB
// @name:de         SteamDB-Suchen exportieren
// @namespace       https://jlcareglio.github.io/
// @version         2.3.1
// @description     Adds a button to export current search in SteamDB as TSV
// @description:es  Agrega un botón para exportar como TSV el listado de busqueda en SteamDB
// @description:it  Aggiunge un pulsante per esportare la ricerca corrente in SteamDB come TSV
// @description:fr  Ajoute un bouton pour exporter la recherche actuelle dans SteamDB en TSV
// @description:de  Fügt eine Schaltfläche hinzu, um die aktuelle Suche in SteamDB als TSV zu exportieren
// @icon            https://www.google.com/s2/favicons?sz=64&domain=steamdb.info
// @grant           none
// @author          Jesús Lautaro Careglio Albornoz
// @source          https://gist.githubusercontent.com/JLCareglio/3d9c4694430b181d2de2780aa2479572/raw/
// @match           https://steamdb.info/search*
// @supportURL      https://gist.githubusercontent.com/JLCareglio/3d9c4694430b181d2de2780aa2479572/
// ==/UserScript==

(async () => {
  async function HandlerClick() {
    btnExport.innerText = "Exporting, please wait...";
    await new Promise((resolve) => setTimeout(resolve, 50));
    try {
      const shown = document.querySelector("#dt-length-0");
      shown.value = -1;
      shown.dispatchEvent(new Event("change"));
    } catch (error) {
      console.error(error);
      btnExport.style.color = "red";
      btnExport.innerText = "Error, please click the search button first";
      return;
    }

    const rows = Array.from(
      document.querySelectorAll("#table-sortable tbody tr")
    );
    const tsvRows = [];
    // console.log({ rows });

    for (const row of rows) {
      // console.log({ row });
      const app_id = row.dataset.appid;
      const name = row
        .querySelector("td:nth-child(3) > a")
        .textContent.replaceAll("#", String.raw`\#`);
      let lastUpdate = row.querySelector("td.timeago").dataset.time;
      let lastUpdateUTC = new Date(lastUpdate).toUTCString();

      tsvRows.push([app_id, name, lastUpdateUTC]);
    }

    const headers = ["AppID", "Name", "Last Update (UTC)"];
    const tsvContent = [headers, ...tsvRows]
      .map((row) => row.join("\t"))
      .join("\n");
    DownloadTsvFile(tsvContent, "SteamDB_Search.tsv");
    btnExport.innerText = "Export TSV";
  }

  function DownloadTsvFile(data, filename) {
    const blob = new Blob([data], { type: "text/tab-separated-values" });
    const url = URL.createObjectURL(blob);
    const link = document.createElement("a");
    link.href = url;
    link.download = filename;
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
    URL.revokeObjectURL(url);
  }

  const btnExport = document.createElement("a");
  btnExport.classList.value = "btn btn-link";
  btnExport.style.padding = "11px";
  btnExport.innerText = "Export TSV";
  btnExport.onclick = HandlerClick;

  document
    .querySelector("#apps > form > dl:nth-child(6) > dd")
    .appendChild(btnExport);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址