perf: 复制链接去除主题语言参数

This commit is contained in:
weifashi 2023-11-14 09:49:52 +08:00
parent e43dd53e4f
commit 6ffb458ffc

View File

@ -735,8 +735,8 @@
// 处理内容连接
if (/https*:\/\//.test(text)) {
const urlMatch = $.apiUrl('../').match(/^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n]+)/im);
const theme = window.localStorage.getItem("__theme:mode__")
const lang = window.localStorage.getItem("__language:type__")
// 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<a href=\"$2\" target=\"_blank\">$2</a>")
@ -745,8 +745,8 @@
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);
// 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())
}