// ==UserScript== // @name Steam 创意工坊增强 // @name:en Steam Workshop Enhancer // @namespace steam-workshop-enhancer // @version 1.4.0 // @description 为新版 Steam 创意工坊补回被改版削掉的信息与批量能力。浏览页:卡片显示订阅数/收藏数/浏览量/文件大小/更新时间、悬浮按钮(复制 ID/SteamCMD/收藏)、已订阅角标、高级排序(星级/订阅数/大小/更新时间/浏览量)、星级筛选(≥N 星 / 仅已评分 / 最低票数,作用于当前页)、跨页看 5★(原生 toprated 排序 + 逐页隐藏非 5★)、原生排序(最受好评/最新更新/最热门,跨页生效)、每页条数 30→200、预览图原图升级、批量勾选订阅/退订、勾选批量导出(ID/链接/CMD/名称/JSON)。收藏夹管理器:搜索/筛选/检查更新/批量导出文件。订阅备份:翻页拉取全部订阅导出 JSON,导入还原自动批量重订。详情页:生命周期订阅数/累计收藏/浏览量/精确时间/完整标签云/复制 ID 与 SteamCMD。艺术作品页(/app/{id}/images/ 与 /screenshots/):卡片显示浏览量/收藏/大小/更新时间、一键下载原图(去尺寸限制,实测 280KB→707KB,完全原图可达 1908×2808)、批量勾选批量下载、复制本页作品链接。核心数据走 Steam 免密钥公开接口 ISteamRemoteStorage/GetPublishedFileDetails(单批 200 条、CORS 直连),不依赖任何私有接口。 // @description:en Restores the information density and bulk tooling that Valve's Workshop redesign removed. Browse page: per-card subscriber/favorite/view counts, file size, update date, hover actions (copy ID / SteamCMD / bookmark), subscribed badges, advanced client-side sorting (star rating included), star-level filtering, per-page 30→200, full-resolution previews, multi-select batch subscribe/unsubscribe, bulk export of selected items (IDs/links/SteamCMD/names/JSON). Bookmark manager: search, filters, update checking, batch export. Subscription backup: fetch all subscriptions page by page into a JSON snapshot, restore by batch re-subscribing. Detail page: lifetime subscriptions, cumulative favorites, views, exact timestamps, full tag cloud, copy ID/SteamCMD. Artwork page: per-card stats, one-click original-image download, multi-select batch download, copy all artwork links. Data comes from Steam's keyless public endpoint ISteamRemoteStorage/GetPublishedFileDetails (200 per batch, CORS-friendly) — no private APIs. // @author SmallRob // @match https://steamcommunity.com/workshop/* // @match https://steamcommunity.com/sharedfiles/* // @match https://steamcommunity.com/my/myworkshopfiles* // @match https://steamcommunity.com/profiles/*/myworkshopfiles* // @match https://steamcommunity.com/app/*/images* // @match https://steamcommunity.com/app/*/screenshots* // @grant GM_getValue // @grant GM_setValue // @grant GM_deleteValue // @grant GM_xmlhttpRequest // @grant GM_addStyle // @grant GM_info // @grant GM_setClipboard // @grant GM_download // @grant unsafeWindow // @connect api.steampowered.com // @connect steamcommunity.com // @connect images.steamusercontent.com // @connect steamuserimages-a.akamaihd.net // @run-at document-idle // @license MIT // @tag Steam // @tag workshop // @icon data:image/svg+xml,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%20100%20100'%3E%3Cdefs%3E%3ClinearGradient%20id%3D'bg'%20x1%3D'0'%20y1%3D'0'%20x2%3D'1'%20y2%3D'1'%3E%3Cstop%20offset%3D'0'%20stop-color%3D'%2318293c'%2F%3E%3Cstop%20offset%3D'1'%20stop-color%3D'%230a131e'%2F%3E%3C%2FlinearGradient%3E%3CradialGradient%20id%3D'halo'%20cx%3D'0.5'%20cy%3D'0.44'%20r%3D'0.6'%3E%3Cstop%20offset%3D'0'%20stop-color%3D'%232f5a86'%2F%3E%3Cstop%20offset%3D'1'%20stop-color%3D'%232f5a86'%20stop-opacity%3D'0'%2F%3E%3C%2FradialGradient%3E%3ClinearGradient%20id%3D'mtnBack'%20x1%3D'0'%20y1%3D'1'%20x2%3D'1'%20y2%3D'0'%3E%3Cstop%20offset%3D'0'%20stop-color%3D'%232b5f8f'%2F%3E%3Cstop%20offset%3D'1'%20stop-color%3D'%235c50b8'%2F%3E%3C%2FlinearGradient%3E%3ClinearGradient%20id%3D'mtnMain'%20x1%3D'0'%20y1%3D'1'%20x2%3D'1'%20y2%3D'0'%3E%3Cstop%20offset%3D'0'%20stop-color%3D'%234fe0ff'%2F%3E%3Cstop%20offset%3D'0.55'%20stop-color%3D'%2366c0f4'%2F%3E%3Cstop%20offset%3D'1'%20stop-color%3D'%23a26bff'%2F%3E%3C%2FlinearGradient%3E%3ClinearGradient%20id%3D'sun'%20x1%3D'0'%20y1%3D'0'%20x2%3D'1'%20y2%3D'1'%3E%3Cstop%20offset%3D'0'%20stop-color%3D'%23ffe082'%2F%3E%3Cstop%20offset%3D'1'%20stop-color%3D'%23ff8f00'%2F%3E%3C%2FlinearGradient%3E%3ClinearGradient%20id%3D'spec'%20x1%3D'0'%20y1%3D'0'%20x2%3D'1'%20y2%3D'0'%3E%3Cstop%20offset%3D'0'%20stop-color%3D'%23ff5c8a'%2F%3E%3Cstop%20offset%3D'0.25'%20stop-color%3D'%23f5a623'%2F%3E%3Cstop%20offset%3D'0.5'%20stop-color%3D'%235cba6f'%2F%3E%3Cstop%20offset%3D'0.75'%20stop-color%3D'%234fe0ff'%2F%3E%3Cstop%20offset%3D'1'%20stop-color%3D'%23a26bff'%2F%3E%3C%2FlinearGradient%3E%3C%2Fdefs%3E%3Crect%20width%3D'100'%20height%3D'100'%20rx%3D'22'%20fill%3D'url(%23bg)'%2F%3E%3Ccircle%20cx%3D'50'%20cy%3D'46'%20r%3D'36'%20fill%3D'url(%23halo)'%2F%3E%3Cpath%20d%3D'M6%2072%20L26%2046%20L38%2061%20L47%2050%20L62%2072%20Z'%20fill%3D'url(%23mtnBack)'%20opacity%3D'0.75'%2F%3E%3Cpath%20d%3D'M16%2072%20L41%2033%20L53%2052%20L64%2039%20L88%2072%20Z'%20fill%3D'url(%23mtnMain)'%2F%3E%3Ccircle%20cx%3D'71'%20cy%3D'25'%20r%3D'11'%20fill%3D'url(%23sun)'%20opacity%3D'0.28'%2F%3E%3Ccircle%20cx%3D'71'%20cy%3D'25'%20r%3D'7'%20fill%3D'url(%23sun)'%2F%3E%3Crect%20x%3D'14'%20y%3D'79'%20width%3D'72'%20height%3D'6'%20rx%3D'3'%20fill%3D'url(%23spec)'%2F%3E%3C%2Fsvg%3E // ==/UserScript== /** * Steam 创意工坊增强 v1.4.0 * * 设计依据:docs/workshop-enhancer-design.md(2026-10-27 实测逆向新版创意工坊) * * 核心事实(实测): * 1. 新版浏览页 /workshop/browse/ 是 React SPA,CSS 类名哈希化(UNowfeldbNg- 之类), * **绝不能靠类名定位**。本脚本只用稳定语义锚点:href 模式 / role / aria / SVG 语义类。 * 2. 条目详情页 /sharedfiles/filedetails/ 仍是经典服务端渲染 HTML,类名稳定。 * 3. ISteamRemoteStorage/GetPublishedFileDetails/v1 免 API Key、POST、CORS 反射 Origin, * 单批可取 200 条,返回订阅数/收藏数/浏览量/文件大小/时间戳/标签——远多于新版 UI 显示。 * 4. 旧 URL 参数仍有 browsesort=toprated / lastupdated / trend、section、requiredtags[]、 * days、p 可用(跨页生效);但 2026-10-30 实测 num_per_page 已被服务端忽略 * (恒定 30 条/页),newest / mostsubscribed / mostdiscussed 会被归一成 trend。 * 因此「原生排序」直接改 URL 实现,不碰私有接口。 * * 纯逻辑(parse / sort / format / query 构造)与 DOM 增强严格分离, * 纯逻辑通过 window.__SWE_TEST_HOOKS__ 暴露给单测。 */ (function (global) { 'use strict'; const VERSION = '1.4.0'; const PREFIX = 'swe'; const API_URL = 'https://api.steampowered.com/ISteamRemoteStorage/GetPublishedFileDetails/v1/'; // 批量上限实测 200 稳定,再大未验证,故取 200 const API_BATCH_MAX = 200; // 卡片数据增强的合并窗口:攒够 8 张或等 200ms 就发一次,避免每张卡一个请求 const CARD_BATCH_SIZE = 8; const CARD_BATCH_WAIT_MS = 200; // 详情缓存 TTL const CACHE_TTL_MS = 6 * 60 * 60 * 1000; // 「最近更新」高亮阈值(天) const RECENT_DAYS = 7; // ============================================================ // 第 1 层:纯逻辑(可单测,不触碰 DOM / GM API) // ============================================================ /** * 从 filedetails 链接里取条目 id。 * 兼容 ?id=123 与 /filedetails/?id=123&... 两种形态。 */ function parseFileIdFromHref(href) { if (!href || typeof href !== 'string') return ''; const m = href.match(/[?&]id=(\d+)/); return m ? m[1] : ''; } /** * 从条目链接里取 appid。 * 形如 /sharedfiles/filedetails/?id=123 本身不含 appid, * 但 /myworkshopfiles/?appid=440 这类创作者链接含,故一并支持。 */ function parseAppIdFromHref(href) { if (!href || typeof href !== 'string') return ''; const m = href.match(/[?&]appid=(\d+)/); return m ? m[1] : ''; } /** * 解析卡片里的星级评分。 * 新版 UI 用 5 个 SVG 表示:SVGIcon_Star_Filled(实心)/ SVGIcon_Star_Unfilled(空心)。 * 半星用含 Half 的类名(若 Valve 后续启用)。 * @returns {{filled:number, half:boolean, max:number, score:number}} score 为 0..max */ function parseStarRating(cardEl) { const res = { filled: 0, half: false, max: 0, score: 0 }; if (!cardEl || typeof cardEl.querySelectorAll !== 'function') return res; const svgs = cardEl.querySelectorAll('svg[class*="Star"]'); if (!svgs.length) return res; let filled = 0, half = false; for (const svg of svgs) { const cls = (svg.getAttribute('class') || ''); if (/Star_Half/i.test(cls)) half = true; else if (/Star_Filled/i.test(cls)) filled++; } res.filled = filled; res.half = half; res.max = svgs.length; res.score = filled + (half ? 0.5 : 0); return res; } /** 星级筛选候选('all' 为关闭;'rated' 隐藏「评分不足」) */ const STAR_FILTER_OPTIONS = [ { key: 'all', label: '全部' }, { key: 'rated', label: '仅已评分' }, { key: '3', label: '≥3 星' }, { key: '4', label: '≥4 星' }, { key: '5', label: '仅 5 星' } ]; /** * 读取浏览页内嵌数据里的星级 / 票数。 * * 每条 `workshop_browse` 结果带 `star_rating`(0–5,**-1 = 评分不足**)与 * `total_votes` —— 这两个字段 GetPublishedFileDetails 拿不到(`includevotes` 不生效), * 只能从页面自身的 React Query 数据里读。 * * 2026-10-30 实测两个来源(按可靠性排序): * 1. `window.SSR.renderContext.queryData`(JSON 字符串)→ `queries` → * `queryKey[0] === 'workshop_browse'` → `state.data.results`。 * **hydrate 之后只有这份**:`