fixed 昼夜切换模式逻辑

This commit is contained in:
Vaica committed 2026-01-26 23:29:29 +08:00
1 parent b95baf09bc
commit 1c3168c024
2 files changed
+39

No files matched your search

+14
View File
@@ -260,8 +260,22 @@
}
}
// 判断是否为移动端
function isMobile() {
if (window.innerWidth < 768) {
return true;
}
return window.navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i);
}
// 加载弹幕主函数
async function loadBarrager() {
// 移动端不加载弹幕
if (isMobile()) {
console.log('[Barrage] 移动端已禁用弹幕');
return;
}
try {
const commentsData = await initArtalkAndGetComments();
if (commentsData) {
+25
View File
@@ -231,6 +231,31 @@ function toggleTheme() {
}
}
// Listen for system theme changes
try {
const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
const handleSystemThemeChange = (e) => {
// Only follow system if user hasn't manually set a preference
if (!localStorage.getItem('theme')) {
const newTheme = e.matches ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', newTheme);
if (window.Artalk) {
Artalk.setDarkMode(newTheme === 'dark');
}
}
};
// Modern browsers
if (mediaQuery.addEventListener) {
mediaQuery.addEventListener('change', handleSystemThemeChange);
} else if (mediaQuery.addListener) {
// Old Safari/IE
mediaQuery.addListener(handleSystemThemeChange);
}
} catch (e) {
console.warn('System theme detection not supported', e);
}
// Update Floating Tools Visibility based on current page
function updateFloatingToolsVisibility() {
const tools = document.querySelector('.floating-tools');