GMG小绿人Steam快捷搜索

快捷搜索steam商店

目前为 2021-12-21 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name:zh-CN GMG小绿人Steam快捷搜索
  3. // @name GMG_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 1.5
  9. // @description 快捷搜索steam商店
  10. // @description:zh-CN 快捷搜索steam商店
  11. // @author Chr_
  12. // @license AGPL-3.0
  13. // @connect steampowered.com
  14. // @match https://www.greenmangaming.com/*/games/*
  15. // @match https://www.greenmangaming.com/games/*
  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["gs_auto"] ?? "关";
  25.  
  26. const GdivResult = [null, null]; //控件数组
  27. let i = 0;
  28. let t = setInterval(() => {
  29. const title1 = document.querySelector("div[class^=visible]>#pdp-title>h1.notranslate");
  30. const describe1 = document.querySelector("div[class^=visible]>#pdp-title>ul.navigate-options");
  31. const title2 = document.querySelector("div[class*=hidden]>#pdp-title>h1.notranslate");
  32. const describe2 = document.querySelector("div[class*=hidden]>#pdp-title>ul.navigate-options");
  33. if (title1 !== null) {
  34. init(title1, describe1, 0);
  35. }
  36. if (title2 !== null) {
  37. init(title2, describe2, 1);
  38. }
  39. if ((GdivResult[0] !== null && GdivResult[1] !== null) || i++ >= 10) {
  40. clearInterval(t);
  41. }
  42. }, 500);
  43.  
  44. //显示搜索按钮
  45. function init(title, describe, which) {
  46. const keyword = title.textContent.replace(/[-+=:;:;""‘’“”]/g, " ");
  47. const btnSearch = document.createElement("button");
  48. btnSearch.className = "btnSearch";
  49. btnSearch.textContent = "🔎";
  50. btnSearch.addEventListener("mouseover", () => { btnSearch.textContent = "🔎 搜索Steam"; });
  51. btnSearch.addEventListener("mouseout", () => { btnSearch.textContent = "🔎"; });
  52. btnSearch.addEventListener("click", () => { showResult(keyword); });
  53.  
  54. (describe ?? title).appendChild(btnSearch);
  55. const divResult = document.createElement("div");
  56. divResult.className = "divResult";
  57. divResult.style.display = "none";
  58. title.appendChild(divResult);
  59.  
  60. GdivResult[which] = divResult;
  61.  
  62. if (auto === "开" && which == 1) {
  63. btnSearch.click();
  64. }
  65. }
  66.  
  67. //显示搜索结果
  68. function showResult(keyword) {
  69. const [divResult1, divResult2] = GdivResult;
  70. searchStore(keyword, "CN")
  71. .then((result) => {
  72. divResult1.innerHTML = "";
  73. divResult2.innerHTML = "";
  74. divResult1.style.display = "";
  75. divResult2.style.display = "";
  76. if (result.length === 0) {
  77. const btnRst = document.createElement("button");
  78. btnRst.textContent = "【快速搜索无结果,点击前往steam搜索页】";
  79. btnRst.addEventListener("click", () => { window.open(`https://store.steampowered.com/search/?term=${keyword}`); });
  80. divResult1.appendChild(btnRst);
  81. divResult2.appendChild(btnRst);
  82. return;
  83. }
  84. for (const { appID, isBundle, appName, appPrice, appUrl, appImg } of result) {
  85. const btnRst = document.createElement("button");
  86. btnRst.title = `${isBundle ? "bundle" : "app"}/${appID}`;
  87. btnRst.addEventListener("click", () => { window.open(appUrl); });
  88.  
  89. const btnName = document.createElement("p");
  90. btnName.textContent = `${appName}【${appPrice}】`
  91. btnRst.appendChild(btnName);
  92. btnRst.appendChild(document.createElement("br"));
  93.  
  94. const btnImg = new Image();
  95. btnImg.src = appImg;
  96.  
  97. btnRst.appendChild(btnImg);
  98. divResult1.appendChild(btnRst);
  99. divResult2.appendChild(btnRst);
  100. }
  101. })
  102. .catch((reason) => {
  103. alert(reason);
  104. });
  105. }
  106.  
  107. GM_registerMenuCommand(`自动搜索:【${auto}】`, () => {
  108. window.localStorage["gs_auto"] = auto === "开" ? "关" : "开";
  109. });
  110. })();
  111.  
  112.  
  113. //CSS表
  114. GM_addStyle(`
  115. .divResult {
  116. top: 0;
  117. position: relative;
  118. width: 100%;
  119. overflow-x: scroll;
  120. overflow-y: hidden;
  121. white-space: nowrap;
  122. }
  123. .divResult > button {
  124. cursor: pointer;
  125. color: #000;
  126. font-size: 15px;
  127. }
  128. .divResult > button:not(:last-child) {
  129. margin-right: 5px;
  130. }
  131. .divResult > button > p {
  132. display: inline;
  133. margin-left: 6px;
  134. }
  135. .divResult > button > img {
  136. zoom: 1.5;
  137. margin-top: 2px;
  138. }
  139. .btnSearch {
  140. padding: 1px;
  141. color: #000;
  142. font-size: 10px;
  143. }
  144. `);

QingJ © 2025

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