MCPcopy Index your code
hub / github.com/scriptscat/scriptcat / getMoreScriptWindowOpen

Function getMoreScriptWindowOpen

src/pages/popup/App.tsx:75–108  ·  view source on GitHub ↗
(currentUrl: string, provider: ScriptProvider)

Source from the content-addressed store, hash-verified

73type ScriptProvider = "scriptcat" | "greasyfork" | "openuserjs";
74
75const getMoreScriptWindowOpen = (currentUrl: string, provider: ScriptProvider) => {
76 let urlHost = "";
77 if (currentUrl) {
78 try {
79 const url = new URL(currentUrl);
80 if (url.hostname && url.protocol.startsWith("http")) {
81 urlHost = url.hostname;
82 }
83 } catch (e: any) {
84 console.warn(e); // 容错:URL 解析失败时忽略错误(不影响后续 UI)
85 }
86 }
87 let link = "";
88 if (provider === "greasyfork") {
89 // www.google.com -> google.com
90 urlHost = /[^.]+\.[^.]+$/.exec(urlHost)?.[0] || urlHost;
91 }
92 switch (provider) {
93 case "scriptcat":
94 link = !urlHost
95 ? "https://scriptcat.org/search"
96 : `https://scriptcat.org/search?domain=${encodeURIComponent(urlHost)}`;
97 break;
98 case "greasyfork":
99 link = !urlHost
100 ? "https://greasyfork.org/scripts/"
101 : `https://greasyfork.org/scripts/by-site/${encodeURI(urlHost)}`;
102 break;
103 case "openuserjs":
104 link = !urlHost ? "https://openuserjs.org/" : `https://openuserjs.org/?q=${encodeURIComponent(urlHost)}`;
105 break;
106 }
107 window.open(link, "_blank");
108};
109
110function App() {
111 const [loading, setLoading] = useState(true);

Callers 2

handleMenuClickFunction · 0.85
AppFunction · 0.85

Calls 2

warnMethod · 0.80
openMethod · 0.65

Tested by

no test coverage detected