fixed: flash of unstyled content when switching dark/light theme
This commit is contained in:
parent
94030d326c
commit
fb9cf148e8
|
@ -100,7 +100,19 @@ function applyBackground(data: BackgroundData, list: Background[]) {
|
|||
const prev = $('body').data('theme');
|
||||
$('body').data('theme', key);
|
||||
$('link[href*=".' + prev + '."]').each(function(this: HTMLElement) {
|
||||
$(this).attr('href', $(this).attr('href').replace('.' + prev + '.', '.' + key + '.')).appendTo('head');
|
||||
var link = document.createElement('link');
|
||||
link.type = 'text/css';
|
||||
link.rel = 'stylesheet';
|
||||
link.href = $(this).attr('href').replace('.' + prev + '.', '.' + key + '.');
|
||||
link.onload = () => {
|
||||
var selector = this.getAttribute('href');
|
||||
if (selector) selector = selector.split(/(light|dark|transp)/)[2];
|
||||
setTimeout(() => {
|
||||
var prevLink = document.querySelector("link[href$=\'light"+selector+"\'], link[href$=\'dark"+selector+"\'], link[href$=\'transp"+selector+"\']");
|
||||
if (prevLink) prevLink.remove();
|
||||
}, 100);
|
||||
}
|
||||
document.head.appendChild(link);
|
||||
});
|
||||
|
||||
if (key === 'transp') {
|
||||
|
|
Loading…
Reference in a new issue