WorkshopEnhance

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

  1. // ==UserScript==
  2. // @name WorkshopEnhance
  3. // @version 2025/03/09
  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. // @run-at document-body
  16. // @grant none
  17. // @namespace https://gf.qytechs.cn/users/989635
  18. // ==/UserScript==
  19.  
  20. (async () => {
  21. const url = location.href;
  22. const app = /^https:\/\/steamcommunity\.com\/app\/\d+/;
  23. const workshop = /^https:\/\/steamcommunity\.com\/workshop\/browse\/\?appid=\d+/;
  24. const sharedfiles = /^https:\/\/steamcommunity\.com\/sharedfiles\/filedetails\/\?id=\d+/;
  25.  
  26. if (app.test(url)) {
  27. WaitElem(".workshop_home_content", content => {
  28. content.querySelectorAll("a.workshop_item_link").forEach(a => {
  29. const title = a.querySelector(".workshop_item_title")?.textContent;
  30. title && ReUri(a, title);
  31. })
  32. })
  33. } else if (workshop.test(url)) {
  34. WaitElem(".workshopBrowseItems", items => {
  35. items.querySelectorAll("div.workshopItem").forEach(div => {
  36. const title = div.querySelector(".workshopItemTitle")?.textContent;
  37. title && div.querySelectorAll("a").forEach(a => ReUri(a, title));
  38. })
  39. })
  40. } else if (sharedfiles.test(url)) {
  41. WaitElem(".workshopItemTitle", title => ReUri(url, title?.textContent ?? ""));
  42. }
  43.  
  44. function ReUri(uri, title) {
  45. const isElement = uri instanceof Element;
  46. const Uri = isElement ? uri.href : uri;
  47.  
  48. const newUri = Uri.includes("&searchtext=")
  49. ? Uri.replace(/(&searchtext=)(.*)?/, `$1${title}`)
  50. : `${Uri}&searchtext=${title}`;
  51.  
  52. isElement ? uri.href = newUri : history.replaceState(null, '', newUri);
  53. };
  54.  
  55. function WaitElem(selector, found) {
  56. const observer = new MutationObserver(() => {
  57. const result = document.querySelector(selector);
  58. if (result) {
  59. observer.disconnect();
  60. found(result);
  61. }
  62. });
  63. observer.observe(document.body, {subtree: true, childList: true});
  64. };
  65. })();

QingJ © 2025

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