Steam_Spoiler_Scraper

Steam 隐藏内容刮刀

目前為 2021-12-21 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name:zh-CN      Steam隐藏内容刮刀
// @name            Steam_Spoiler_Scraper
// @namespace       https://blog.chrxw.com
// @supportURL      https://blog.chrxw.com/scripts.html
// @contributionURL https://afdian.net/@chr233
// @version         1.2
// @description     Steam 隐藏内容刮刀
// @author          Chr_
// @include         /https://steamcommunity\.com/sharedfiles/filedetails/\?id=\d+?$/
// @license         AGPL-3.0
// @icon            https://blog.chrxw.com/favicon.ico
// ==/UserScript==

// 初始化
(() => {
    "use strict";
    addPanel();
    addFunction();

    // 添加按钮
    function addPanel() {
        function genBtn(name, foo, tooltip, id) {
            let s = document.createElement("span");
            s.className = "general_btn tooltip";
            s.title = tooltip;
            s.textContent = name;
            s.addEventListener("click", foo);
            if (id) { s.id = id; }
            return s;
        }
        let btnReport = document.getElementById("ReportItemBtn");
        if (btnReport != null) {
            let btnDiv = btnReport.parentElement;
            let btnShow = genBtn("刮开", () => { scratchAll(true); }, "刮开所有隐藏", "btnShow");
            let btnHide = genBtn("恢复", () => { scratchAll(false); }, "恢复所有隐藏", "btnHide");
            btnDiv.appendChild(btnShow);
            btnDiv.appendChild(btnHide);
        }
    }
    // 为每个隐藏绑定函数
    function addFunction() {
        for (let ele of document.querySelectorAll(".bb_spoiler")) {
            ele.addEventListener("click", scratch);
        }
    }
    // 刮开单个隐藏
    function scratch(ele) {
        let s = ele.currentTarget;
        console.log(s.getAttribute("scratch"))
        if (s.getAttribute("scratch") != "on") {
            for (let e of s.querySelectorAll("*")) {
                e.style.cssText = "visibility:visible;color:#fff;";
            }
            s.setAttribute("scratch", "on");
        } else {
            for (let e of s.querySelectorAll("*")) {
                e.style.cssText = "";
            }
            s.removeAttribute("scratch");
        }
    }
    // 刮开所有隐藏
    function scratchAll(show = true) {
        for (let ele of document.querySelectorAll(".bb_spoiler")) {
            if ((ele.getAttribute("scratch") != "on") === show) {
                ele.click();
            }
        }
    }
})();