|
|
@ -4,16 +4,32 @@ function changeTheme(e) { |
|
|
|
theme = 'default'; |
|
|
|
theme = 'default'; |
|
|
|
} |
|
|
|
} |
|
|
|
localStorage.setItem('theme', theme); |
|
|
|
localStorage.setItem('theme', theme); |
|
|
|
var themeLink = document.getElementById('theme'); |
|
|
|
var custom = document.getElementById('customtheme'); |
|
|
|
//if somebody makes a theme file named "default", it wont work. so just dont.
|
|
|
|
|
|
|
|
if (theme === 'default') { |
|
|
|
if (theme === 'default') { |
|
|
|
var defaultTheme = themeLink.dataset.theme; |
|
|
|
if (custom) { |
|
|
|
var defaultHref = '/css/themes/'+defaultTheme+'.css'; |
|
|
|
custom.remove(); |
|
|
|
if (themeLink.href !== defaultHref) { |
|
|
|
} |
|
|
|
themeLink.href = '/css/themes/'+defaultTheme+'.css'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
themeLink.href = '/css/themes/'+theme+'.css'; |
|
|
|
var path = '/css/themes/'+theme+'.css'; |
|
|
|
|
|
|
|
var css = localStorage.getItem(path); |
|
|
|
|
|
|
|
if (!custom) { |
|
|
|
|
|
|
|
custom = document.createElement('style'); |
|
|
|
|
|
|
|
custom.id = 'customtheme'; |
|
|
|
|
|
|
|
document.head.appendChild(custom); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (css) { |
|
|
|
|
|
|
|
custom.innerHTML = css; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var tempLink = document.createElement('link'); |
|
|
|
|
|
|
|
tempLink.rel = 'stylesheet'; |
|
|
|
|
|
|
|
tempLink.onload = function() { |
|
|
|
|
|
|
|
css = tempLink.sheet.rules[0].cssText; |
|
|
|
|
|
|
|
localStorage.setItem(path, css); |
|
|
|
|
|
|
|
custom.innerHTML = css; |
|
|
|
|
|
|
|
tempLink.remove(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tempLink.href = path; |
|
|
|
|
|
|
|
document.head.appendChild(tempLink); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|