WorkshopEnhance

一个简单的工作坊网址替换脚本,为网址添加 searchtext=<标题>

  1. // ==UserScript==
  2. // @name WorkshopEnhance
  3. // @version 2025/07/06
  4. // @author Canaan HS
  5. // @description 一個簡單的工作坊網址替換腳本,為網址添加 searchtext=<標題>
  6. // @description:zh-TW 一個簡單的工作坊網址替換腳本,為網址添加 searchtext=<標題>
  7. // @description:zh-CN 一个简单的工作坊网址替换脚本,为网址添加 searchtext=<标题>
  8. // @description:en A simple workshop URL replacement script that adds searchtext=<title> to the URL
  9.  
  10. // @license MPL-2.0
  11. // @match *://steamcommunity.com/*
  12. // @icon https://cdn-icons-png.flaticon.com/512/220/220608.png
  13.  
  14. // @noframes
  15. // @grant none
  16.  
  17. // @run-at document-start
  18. // @namespace https://gf.qytechs.cn/users/989635
  19. // ==/UserScript==
  20.  
  21. (async () => {
  22.  
  23. const url = location.href;
  24. const app = /^https:\/\/steamcommunity\.com\/app\/\d+/;
  25. const workshop = /^https:\/\/steamcommunity\.com\/workshop\/browse\/\?appid=\d+/;
  26. const sharedfiles = /^https:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=\d+/;
  27.  
  28. if (app.test(url)) {
  29. WaitElem(".workshop_home_content", content => {
  30. content.querySelectorAll("a.workshop_item_link").forEach(a => {
  31. const title = a.querySelector(".workshop_item_title")?.textContent;
  32. title && ReUri(a, title);
  33. })
  34. })
  35. } else if (workshop.test(url)) {
  36. WaitElem(".workshopBrowseItems", items => {
  37. WaitLoad(items, 300, () => {
  38. items.querySelectorAll(".workshopItem").forEach(div => {
  39. const title = div.querySelector(".workshopItemTitle")?.textContent;
  40. title && div.querySelectorAll("a:not(.workshop_author_link)").forEach(a => ReUri(a, title));
  41. })
  42. })
  43. })
  44.  
  45. WaitElem(".pagebtn", buttons => {
  46. if (buttons.length === 2) {
  47. let Jump = false;
  48.  
  49. const TurnPage = (Url) => {
  50. Jump = true;
  51. location.assign(Url);
  52. };
  53.  
  54. window.addEventListener("keydown", event => {
  55. const key = event.key;
  56. if (key === "ArrowLeft" && buttons[0].hasAttribute("href") && !Jump) {
  57. TurnPage(buttons[0].href);
  58. } else if (key === "ArrowRight" && buttons[1].hasAttribute("href") && !Jump) {
  59. TurnPage(buttons[1].href);
  60. }
  61. }, { capture: true });
  62. }
  63. }, true)
  64. } else if (sharedfiles.test(url)) {
  65. WaitElem(".workshopItemTitle", title => ReUri(url, title?.textContent ?? ""));
  66. }
  67.  
  68. function Debounce(func, delay) {
  69. let timer = null;
  70. return (...args) => {
  71. clearTimeout(timer);
  72. timer = setTimeout(function () {
  73. func(...args);
  74. }, delay);
  75. }
  76. };
  77.  
  78. function ReUri(uri, title) {
  79. const isElement = uri instanceof Element;
  80. const Uri = isElement ? uri.href : uri;
  81.  
  82. const newUri = Uri.includes("&searchtext=")
  83. ? Uri.replace(/(&searchtext=)(.*)?/, `$1${title}`)
  84. : `${Uri}&searchtext=${title}`;
  85.  
  86. isElement ? uri.href = newUri : history.replaceState(null, '', newUri);
  87. };
  88.  
  89. function WaitLoad(container, debounce, run) {
  90. const observer = new MutationObserver(Debounce(() => { run() }, debounce));
  91. observer.observe(container, { subtree: true, childList: true, attributes: true, characterData: true });
  92. };
  93.  
  94. function WaitElem(selector, found, all = false) {
  95. const observer = new MutationObserver(() => {
  96. const result = all ? document.querySelectorAll(selector) : document.querySelector(selector);
  97. if (all ? result.length > 0 : result) {
  98. observer.disconnect();
  99. found(result);
  100. }
  101. });
  102. observer.observe(document, { subtree: true, childList: true });
  103. };
  104.  
  105. })();

QingJ © 2025

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