Remove existing stylesheets when changing themes

This commit is contained in:
RMidhunSuresh 2022-04-25 16:33:31 +05:30
parent 12a70469eb
commit af9cbd727f
2 changed files with 6 additions and 8 deletions

View File

@ -229,7 +229,7 @@ module.exports = function buildThemes(options) {
type: "text/css", type: "text/css",
media: "(prefers-color-scheme: dark)", media: "(prefers-color-scheme: dark)",
href: `./${darkThemeLocation}`, href: `./${darkThemeLocation}`,
class: "default-theme", class: "theme",
} }
}, },
{ {
@ -239,7 +239,7 @@ module.exports = function buildThemes(options) {
type: "text/css", type: "text/css",
media: "(prefers-color-scheme: light)", media: "(prefers-color-scheme: light)",
href: `./${lightThemeLocation}`, href: `./${lightThemeLocation}`,
class: "default-theme", class: "theme",
} }
}, },
]; ];

View File

@ -345,17 +345,15 @@ export class Platform {
} }
_replaceStylesheet(newPath) { _replaceStylesheet(newPath) {
// remove default theme
const defaultStylesheets = document.getElementsByClassName("default-theme");
for (const tag of defaultStylesheets) {
tag.remove();
}
// add new theme
const head = document.querySelector("head"); const head = document.querySelector("head");
// remove default theme
document.querySelectorAll(".theme").forEach(e => e.remove());
// add new theme
const styleTag = document.createElement("link"); const styleTag = document.createElement("link");
styleTag.href = `./${newPath}`; styleTag.href = `./${newPath}`;
styleTag.rel = "stylesheet"; styleTag.rel = "stylesheet";
styleTag.type = "text/css"; styleTag.type = "text/css";
styleTag.className = "theme";
head.appendChild(styleTag); head.appendChild(styleTag);
} }