💄 Add switch theme button function.

This commit is contained in:
凡梦星尘
2022-09-26 21:54:03 +08:00
parent 4037ea0d68
commit d4730f89d2
4 changed files with 44 additions and 3 deletions

View File

@@ -34,6 +34,7 @@ NexT.boot.registerEvents = function() {
NexT.boot.refresh = function() {
NexT.utils.calSiteInfo();
NexT.utils.regSwitchThemeBtn();
if (!NexT.CONFIG.page.isPage) return;

View File

@@ -23,6 +23,16 @@ HTMLElement.prototype.wrap = function(wrapper) {
NexT.utils = {
regSwitchThemeBtn: function() {
const switchThemeBtn = document.getElementById('switch-theme');
if (!switchThemeBtn) return;
switchThemeBtn.addEventListener('click', () => {
const colorTheme = document.documentElement.getAttribute('data-theme');
const theme = colorTheme == null ? 'dark' : colorTheme == 'dark' ? 'light' : 'dark';
document.documentElement.setAttribute('data-theme', theme);
});
},
domAddClass: function(selector, cls) {
const doms = document.querySelectorAll(selector);
if (doms) {