create new css link to smoothly transition between themes
Previously, directly editing the <link> tag with the new file would cause the page to have no stylesheet for a moment while the new file is downloaded. A new element is now appended below the original instead, which smoothens out the transition.
This commit is contained in:
+13
-2
@@ -19,14 +19,25 @@ var transitionEndEvent = whichTransitionEvent();
|
||||
|
||||
// Toggles between light and dark themes
|
||||
function toggleCSS() {
|
||||
let cssEl = document.querySelectorAll('link[rel="stylesheet"][type="text/css"]')[0];
|
||||
let Els = document.querySelectorAll('link[rel="stylesheet"][type="text/css"]');
|
||||
let cssEl = Els[0]
|
||||
let remove = false;
|
||||
if (Els.length != 1) {
|
||||
cssEl = Els[1]
|
||||
remove = true
|
||||
}
|
||||
let href = "bs" + bsVersion;
|
||||
if (cssEl.href.includes(href + "-jf")) {
|
||||
href += ".css";
|
||||
} else {
|
||||
href += "-jf.css";
|
||||
}
|
||||
cssEl.href = href
|
||||
let newEl = cssEl.cloneNode(true);
|
||||
newEl.href = href
|
||||
cssEl.parentNode.insertBefore(newEl, cssEl.nextSibling);
|
||||
if (remove) {
|
||||
Els[0].remove()
|
||||
}
|
||||
document.cookie = "css=" + href;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user