mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-06 08:48:49 +01:00
🎨 Improve theme switching (#15054)
This commit is contained in:
parent
e0fe3361d2
commit
b70e06e72f
1 changed files with 13 additions and 1 deletions
|
|
@ -28,7 +28,19 @@ export const loadAssets = (data: Config.IAppearance) => {
|
|||
const defaultThemeAddress = `/appearance/themes/${data.mode === 1 ? "midnight" : "daylight"}/theme.css?v=${Constants.SIYUAN_VERSION}`;
|
||||
if (defaultStyleElement) {
|
||||
if (!defaultStyleElement.getAttribute("href").startsWith(defaultThemeAddress)) {
|
||||
defaultStyleElement.setAttribute("href", defaultThemeAddress);
|
||||
const newStyleElement = document.createElement("link");
|
||||
newStyleElement.id = "themeDefaultStyleNew";
|
||||
newStyleElement.rel = "stylesheet";
|
||||
newStyleElement.href = defaultThemeAddress;
|
||||
|
||||
// 等待新样式表加载完成再移除旧样式表
|
||||
new Promise((resolve) => {
|
||||
newStyleElement.onload = resolve;
|
||||
defaultStyleElement.parentNode.insertBefore(newStyleElement, defaultStyleElement);
|
||||
}).then(() => {
|
||||
defaultStyleElement.remove();
|
||||
newStyleElement.id = "themeDefaultStyle";
|
||||
});
|
||||
}
|
||||
} else {
|
||||
addStyle(defaultThemeAddress, "themeDefaultStyle");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue