added:昼夜模式,毛玻璃特效
This commit is contained in:
1 parent
739c8056d6
commit
c83c28fb9c
9 files changed
+696
-185
No files matched your search
@@ -145,4 +145,72 @@ function flattenComments(comments) {
|
||||
// 调用异步的弹幕加载函数
|
||||
if (document.querySelector("#Comments") && !isMobile()) {
|
||||
loadBarrager()
|
||||
}
|
||||
}
|
||||
|
||||
function getCurrentTheme() {
|
||||
var theme = document.documentElement.getAttribute('data-theme');
|
||||
if (!theme) {
|
||||
theme = 'light';
|
||||
}
|
||||
return theme;
|
||||
}
|
||||
|
||||
function applyTheme(theme) {
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
try {
|
||||
localStorage.setItem('theme', theme);
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
function updateThemeToggle(theme) {
|
||||
var button = document.getElementById('theme-toggle');
|
||||
if (theme === 'dark') {
|
||||
if (button) {
|
||||
button.textContent = '日间';
|
||||
}
|
||||
} else {
|
||||
if (button) {
|
||||
button.textContent = '夜间';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function toggleTheme() {
|
||||
var current = getCurrentTheme();
|
||||
var next = current === 'dark' ? 'light' : 'dark';
|
||||
applyTheme(next);
|
||||
updateThemeToggle(next);
|
||||
if (window.Artalk && window.Artalk.get) {
|
||||
try {
|
||||
var ctx = Artalk.get('#Comments');
|
||||
if (ctx && ctx.setDarkMode) {
|
||||
ctx.setDarkMode(next === 'dark');
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
var theme = getCurrentTheme();
|
||||
updateThemeToggle(theme);
|
||||
var button = document.getElementById('theme-toggle');
|
||||
if (button) {
|
||||
button.addEventListener('click', toggleTheme);
|
||||
}
|
||||
var avatarWrapper = document.querySelector('.head_author_img');
|
||||
var avatarTip = document.querySelector('.avatar-theme-tip');
|
||||
if (avatarWrapper) {
|
||||
avatarWrapper.style.cursor = 'pointer';
|
||||
avatarWrapper.addEventListener('click', toggleTheme);
|
||||
}
|
||||
if (avatarTip) {
|
||||
avatarTip.classList.add('is-visible');
|
||||
var hideOnce = function () {
|
||||
avatarTip.classList.add('is-hidden');
|
||||
};
|
||||
setTimeout(hideOnce, 9000);
|
||||
if (avatarWrapper) {
|
||||
avatarWrapper.addEventListener('click', hideOnce);
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user