PageSourceSearch

https://yaoonion.fun/js/theme.js

js yaoonion.fun collected 2026-10-06 13:16:49 UTC 1,626 bytes, 50 lines download raw bytes

1// 主题切换功能
2function toggleTheme(isDark) {
3    document.documentElement.setAttribute('data-theme', isDark ? 'dark' : 'light');
4    localStorage.setItem('theme-preference', isDark ? 'dark' : 'light');
5    
6    // 更新主题图标
7    const themeIcon = document.getElementById('theme-icon');
8    if (themeIcon) {
9        themeIcon.className = isDark ? 'ri-sun-line' : 'ri-moon-line';
10    }
11}
12
13// 检查并设置主题
14function checkAndSetTheme() {
15    const savedTheme = localStorage.getItem('theme-preference');
16    if (savedTheme) {
17        toggleTheme(savedTheme === 'dark');
18    } else {
19        // 根据东八区(北京时间)自动设置
20        const hour = (new Date().getUTCHours() + 8) % 24;
21        const isDayTime = hour >= 6 && hour < 18;
22        toggleTheme(!isDayTime);
23    }
24}
25
26// 手动切换主题
27function manualToggleTheme() {
28    const currentTheme = document.documentElement.getAttribute('data-theme');
29    toggleTheme(currentTheme === 'light');
30}
31
32// 初始化主题
33checkAndSetTheme();
34
35// 初始化主题图标
36document.addEventListener('DOMContentLoaded', () => {
37    const currentTheme = document.documentElement.getAttribute('data-theme');
38    const themeIcon = document.getElementById('theme-icon');
39    if (themeIcon) {
40        themeIcon.className = currentTheme === 'dark' ? 'ri-sun-line' : 'ri-moon-line';
41    }
42});
43
44// 每小时检查一次时间并更新主题(仅当用户没有手动设置主题时)
45setInterval(() => {
46    if (!localStorage.getItem('theme-preference')) {
47        checkAndSetTheme();
48    }
49}, 3600000);
50

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.