Sonkwo_Steam_Search

快捷搜索steam商店

目前为 2024-10-13 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name:zh-CN 杉果Steam快捷搜索
  3. // @name Sonkwo_Steam_Search
  4. // @namespace https://blog.chrxw.com/
  5. // @supportURL https://blog.chrxw.com/scripts.html
  6. // @contributionURL https://afdian.net/@chr233
  7. // @icon https://blog.chrxw.com/favicon.ico
  8. // @version 2.4
  9. // @description 快捷搜索steam商店
  10. // @description:zh-CN 快捷搜索steam商店
  11. // @author Chr_
  12. // @license AGPL-3.0
  13. // @connect steampowered.com
  14. // @match https://www.sonkwo.com/sku/*
  15. // @match https://www.sonkwo.hk/sku/*
  16. // @require https://gf.qytechs.cn/scripts/431430-search-steam-store/code/Search_Steam_Store.js
  17. // @grant GM_xmlhttpRequest
  18. // @grant GM_addStyle
  19. // @grant GM_registerMenuCommand
  20. // ==/UserScript==
  21.  
  22. (() => {
  23. "use strict";
  24. const auto = window.localStorage["ss_auto"] ?? "关";
  25.  
  26. let GdivResult = null; //控件数组
  27.  
  28. let t = setInterval(() => {
  29. const container = document.querySelector("div.main-content");
  30. if (container !== null) {
  31. clearInterval(t);
  32. container.addEventListener("DOMNodeInserted", ({ relatedNode }) => {
  33. const ele = document.querySelector("h5.typical-name-2") || document.querySelector("h3.typical-name-1");
  34. if (ele.querySelector("button.btnSearch") === null) {
  35. init(ele);
  36. }
  37. });
  38. }
  39. }, 500);
  40.  
  41. //显示搜索按钮
  42. function init(ele) {
  43. const keyword = ele.textContent.replace(/[-+=:;:;""‘’“”]/g, " ");
  44. const btnSearch = document.createElement("button");
  45. btnSearch.className = "btnSearch";
  46. btnSearch.textContent = "🔎";
  47. btnSearch.addEventListener("mouseover", () => { btnSearch.textContent = "🔎 搜索Steam"; });
  48. btnSearch.addEventListener("mouseout", () => { btnSearch.textContent = "🔎"; });
  49. btnSearch.addEventListener("click", () => { showResult(keyword); });
  50.  
  51. ele.appendChild(btnSearch);
  52. const divResult = document.createElement("div");
  53. divResult.className = "divResult";
  54. ele.appendChild(divResult);
  55.  
  56. GdivResult = divResult;
  57.  
  58. if (auto === "开") {
  59. btnSearch.click();
  60. }
  61. }
  62.  
  63. //显示搜索结果
  64. function showResult(keyword) {
  65. searchStore(keyword, "CN")
  66. .then((result) => {
  67. GdivResult.innerHTML = "";
  68. if (result.length === 0) {
  69. const btnRst = document.createElement("button");
  70. btnRst.textContent = "【快速搜索无结果,点击前往steam搜索页】";
  71. btnRst.addEventListener("click", () => { window.open(`https://store.steampowered.com/search/?term=${keyword}`); });
  72. GdivResult.appendChild(btnRst);
  73. return;
  74. }
  75. for (const { appID, isBundle, appName, appPrice, appUrl, appImg } of result) {
  76. const btnRst = document.createElement("button");
  77. btnRst.title = `${isBundle ? "bundle" : "app"}/${appID}`;
  78. btnRst.addEventListener("click", () => { window.open(appUrl); });
  79.  
  80. const btnName = document.createElement("p");
  81. btnName.textContent = `${appName}【${appPrice}】`;
  82. btnRst.appendChild(btnName);
  83. btnRst.appendChild(document.createElement("br"));
  84.  
  85. const btnImg = new Image();
  86. btnImg.src = appImg;
  87.  
  88. btnRst.appendChild(btnImg);
  89. GdivResult.appendChild(btnRst);
  90. }
  91. })
  92. .catch((reason) => {
  93. alert(reason);
  94. });
  95. }
  96.  
  97. GM_registerMenuCommand(`自动搜索:【${auto}】`, () => {
  98. window.localStorage["ss_auto"] = auto === "开" ? "关" : "开";
  99. });
  100. })();
  101.  
  102.  
  103. //CSS表
  104. GM_addStyle(`
  105. .divResult {
  106. top: -180px;
  107. position: relative;
  108. width: 100%;
  109. overflow-y: hidden;
  110. white-space: nowrap;
  111. }
  112. .divResult > button {
  113. cursor: pointer;
  114. }
  115. .divResult > button:not(:last-child) {
  116. margin-right: 5px;
  117. }
  118. .divResult > button > p {
  119. display: inline;
  120. margin-left: 6px;
  121. }
  122. .divResult > button > img {
  123. zoom: 1.5;
  124. margin-top: 2px;
  125. }
  126. .btnSearch {
  127. padding: 0 5px;
  128. margin-left: 5px;
  129. }
  130.  
  131. `);

QingJ © 2025

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