Steam_Spoiler_Scraper

Steam 隐藏内容刮刀

  1. // ==UserScript==
  2. // @name:zh-CN Steam隐藏内容刮刀
  3. // @name Steam_Spoiler_Scraper
  4. // @namespace https://blog.chrxw.com
  5. // @supportURL https://blog.chrxw.com/scripts.html
  6. // @contributionURL https://afdian.net/@chr233
  7. // @version 1.3
  8. // @description Steam 隐藏内容刮刀
  9. // @author Chr_
  10. // @match https://steamcommunity.com/*
  11. // @license AGPL-3.0
  12. // @icon https://blog.chrxw.com/favicon.ico
  13. // ==/UserScript==
  14.  
  15. // 初始化
  16. (() => {
  17. "use strict";
  18. addPanel();
  19. addFunction();
  20.  
  21. // 添加按钮
  22. function addPanel() {
  23. function genBtn(name, foo, tooltip, id) {
  24. let s = document.createElement("span");
  25. s.className = "general_btn tooltip";
  26. s.title = tooltip;
  27. s.textContent = name;
  28. s.addEventListener("click", foo);
  29. if (id) { s.id = id; }
  30. return s;
  31. }
  32. let btnReport = document.getElementById("ReportItemBtn");
  33. if (btnReport != null) {
  34. let btnDiv = btnReport.parentElement;
  35. let btnShow = genBtn("刮开", () => { scratchAll(true); }, "刮开所有隐藏", "btnShow");
  36. let btnHide = genBtn("恢复", () => { scratchAll(false); }, "恢复所有隐藏", "btnHide");
  37. btnDiv.appendChild(btnShow);
  38. btnDiv.appendChild(btnHide);
  39. }
  40. }
  41. // 为每个隐藏绑定函数
  42. function addFunction() {
  43. for (let ele of document.querySelectorAll(".bb_spoiler")) {
  44. ele.addEventListener("click", scratch);
  45. }
  46. }
  47. // 刮开单个隐藏
  48. function scratch(ele) {
  49. let s = ele.currentTarget;
  50. console.log(s.getAttribute("scratch"));
  51. if (s.getAttribute("scratch") != "on") {
  52. for (let e of s.querySelectorAll("*")) {
  53. e.style.cssText = "visibility:visible;color:#fff;";
  54. }
  55. s.setAttribute("scratch", "on");
  56. } else {
  57. for (let e of s.querySelectorAll("*")) {
  58. e.style.cssText = "";
  59. }
  60. s.removeAttribute("scratch");
  61. }
  62. }
  63. // 刮开所有隐藏
  64. function scratchAll(show = true) {
  65. for (let ele of document.querySelectorAll(".bb_spoiler")) {
  66. if ((ele.getAttribute("scratch") != "on") === show) {
  67. ele.click();
  68. }
  69. }
  70. }
  71. })();