perf:代码优化

This commit is contained in:
weifashi 2023-08-22 02:06:36 +08:00
parent e928ff1fce
commit c11f946979
2 changed files with 18 additions and 10 deletions

View File

@ -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();
});

View File

@ -734,18 +734,23 @@
text = text.replace(atReg, `<span class="mention me" data-id="${userid}">`)
// 处理内容连接
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<a href=\"$2\" target=\"_blank\">$2</a>")
}
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("")
}