From c11f9469791d667ba9fad33801eed579f0dce7da Mon Sep 17 00:00:00 2001 From: weifashi <605403358@qq.com> Date: Tue, 22 Aug 2023 02:06:36 +0800 Subject: [PATCH] =?UTF-8?q?perf=EF=BC=9A=E4=BB=A3=E7=A0=81=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/assets/js/app.js | 13 ++++++++----- resources/assets/js/functions/web.js | 15 ++++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/resources/assets/js/app.js b/resources/assets/js/app.js index 3d31862bd..6ac06f3f5 100644 --- a/resources/assets/js/app.js +++ b/resources/assets/js/app.js @@ -94,12 +94,15 @@ if (!isElectron && !isEEUiApp) { ViewUI.LoadingBar.start(); }, 300) if (to.query?.theme) { - store.dispatch("setTheme", to.query?.theme) + store.dispatch("setTheme", typeof to.query?.theme == 'string' ? to.query?.theme : to.query?.theme[0]) } - if (to.query?.lang && window.localStorage.getItem("__language:type__") != to.query?.lang) { - window.localStorage.setItem("__language:type__", to.query?.lang); - window.location.reload(); - return false; + if (to.query?.lang) { + let lang = typeof to.query?.lang == 'string' ? to.query?.lang : to.query?.lang[0] + if (window.localStorage.getItem("__language:type__") != lang) { + window.localStorage.setItem("__language:type__", to.query?.lang); + window.location.reload(); + return false; + } } next(); }); diff --git a/resources/assets/js/functions/web.js b/resources/assets/js/functions/web.js index 4a7802dc2..f0c67d752 100755 --- a/resources/assets/js/functions/web.js +++ b/resources/assets/js/functions/web.js @@ -734,18 +734,23 @@ text = text.replace(atReg, ``) // 处理内容连接 if (/https*:\/\//.test(text)) { - const match = $.apiUrl('').match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/im); + const urlMatch = $.apiUrl('../').match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/im); const theme = window.localStorage.getItem("__theme:mode__") const lang = window.localStorage.getItem("__language:type__") text = text.split(/(<[^>]*>)/g).map(string => { if (string && !/<[^>]*>/.test(string)) { string = string.replace(/(^|[^'"])((https*:\/\/)((\w|=|\?|\.|\/|&|-|:|\+|%|;|#|@|,|!)+))/g, "$1$2") } - if (match && match[1] && string.indexOf(match[1]) !== -1) { - if (string.indexOf("?") == -1) { - string = string.replace(/(href="[^"]*)/g, (string.indexOf("?") == -1 ? '$1?' : '$1&') + `theme=${theme}&lang=${lang}`); - } + // + const href = string.match(/href="([^"]+)"/)?.[1] || '' + if (urlMatch?.[1] && href.indexOf(urlMatch[1]) !== -1) { + const searchParams = new URLSearchParams() + href.indexOf("theme=") === -1 && searchParams.append('theme', theme); + href.indexOf("lang=") === -1 && searchParams.append('lang', lang); + const prefix = searchParams.toString() ? (href.indexOf("?") === -1 ? '?' : '&') : ''; + string = string.replace(/(href="[^"]*)/g, '$1' + prefix + searchParams.toString()) } + // return string; }).join("") }