From 4cbd5c516ad090c004a3bca84bdf7c10a439ba7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9B=AE=E6=A3=83?= Date: Sat, 1 Feb 2025 11:26:59 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E8=A7=A3=E6=9E=90=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/linkParser.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/utils/linkParser.ts b/src/utils/linkParser.ts index e7476fd7..5e437d01 100644 --- a/src/utils/linkParser.ts +++ b/src/utils/linkParser.ts @@ -1,7 +1,7 @@ /** * @file src/utils/linkParser.ts * @description 处理链接 - * @since Beta v0.6.7 + * @since Beta v0.6.9 */ import showDialog from "@comp/func/dialog.js"; @@ -15,7 +15,7 @@ import TGBbs from "@/utils/TGBbs.js"; /** * @function parsePost - * @since Beta v0.5.5 + * @since Beta v0.6.9 * @description 处理帖子 * @param {string} link * @returns {Promise} - 处理情况,或者转换后的链接 @@ -24,17 +24,17 @@ export async function parsePost(link: string): Promise { const url = new URL(link); if (url.protocol !== "https:" && url.protocol !== "http:") { if (url.protocol === "mihoyobbs:") { - if (url.pathname.startsWith("//article/")) { + if (url.hostname === "article") { const postId = url.pathname.split("/").pop(); if (!postId) return false; return postId; } - if (url.pathname === "//webview" && url.search.startsWith("?link=")) { + if (url.hostname === "webview" && url.search.startsWith("?link=")) { const urlTransform = decodeURIComponent(url.search.replace("?link=", "")); return await parsePost(urlTransform); } // 不保证转换后的链接可用 - if (url.pathname === "//openURL" && url.search.startsWith("?url=")) { + if (url.hostname === "openURL" && url.search.startsWith("?url=")) { const urlTransform = decodeURIComponent(url.search.replace("?url=", "")); return await parsePost(urlTransform); } @@ -57,7 +57,7 @@ export async function parsePost(link: string): Promise { /** * @function parseLink - * @since Beta v0.6.5 + * @since Beta v0.6.9 * @description 处理链接 * @param {string} link - 链接 * @param {boolean} useInner - 是否采用内置 JSBridge 打开 @@ -70,30 +70,30 @@ export async function parseLink( const url = new URL(link); if (url.protocol !== "https:" && url.protocol !== "http:") { if (url.protocol === "mihoyobbs:") { - if (url.pathname.startsWith("//article/")) { + if (url.hostname === "article") { const postId = url.pathname.split("/").pop(); if (!postId) return false; await createPost(postId); return true; } - if (url.pathname === "//webview" && url.search.startsWith("?link=")) { + if (url.hostname === "webview" && url.search.startsWith("?link=")) { const urlTransform = decodeURIComponent(url.search.replace("?link=", "")); return await parseLink(urlTransform, useInner); } // 不保证转换后的链接可用 - if (url.pathname === "//openURL" && url.search.startsWith("?url=")) { + if (url.hostname === "openURL" && url.search.startsWith("?url=")) { const urlTransform = decodeURIComponent(url.search.replace("?url=", "")); return await parseLink(urlTransform, useInner); } - console.log(url.pathname, url.search); + console.log(url); // 处理特定路径 - if (url.pathname.startsWith("//discussion")) { + if (url.hostname === "discussion") { const gid = url.pathname.split("/").pop(); const forum = url.searchParams.get("forum_id"); await emit("active_deep_link", `router?path=/posts/forum/${gid}/${forum}`); return true; } - if (url.pathname.startsWith("//homeForum")) { + if (url.hostname === "homeForum") { const game_id = url.searchParams.get("game_id"); const tab_type = url.searchParams.get("tab_type"); if (game_id && tab_type) {