1/** 2 * weather.com.hk â theme.js 3 * Supports dark/light toggle. Default: light. 4 */ 5(function () { 6 // Apply saved theme on load (before paint) 7 var saved = 'light'; 8 try { saved = localStorage.getItem('wchk-theme') || 'light'; } catch(e) {} 9 applyTheme(saved); 10 11 function applyTheme(mode) { 12 var html = document.documentElement; 13 if (mode === 'light') { 14 html.classList.add('light'); 15 html.classList.remove('dark'); 16 } else { 17 html.classList.remove('light'); 18 html.classList.add('dark'); 19 } 20 // Update header toggle button 21 if (document.readyState === 'loading') { 22 document.addEventListener('DOMContentLoaded', updateUI); 23 } else { 24 updateUI(); 25 } 26 function updateUI() { 27 var btn = document.getElementById('theme-toggle-btn'); 28 if (btn) btn.textContent = mode === 'light' ? 'ð' : 'âï¸'; 29 // Sync settings checkbox 30 var cb = document.getElementById('stg-dark-mode-toggle'); 31 if (cb) cb.checked = (mode === 'dark'); 32 } 33 } 34 35 // Global: toggle (called by header button) 36 window.toggleTheme = function () { 37 var html = document.documentElement; 38 var next = html.classList.contains('light') ? 'dark' : 'light'; 39 try { localStorage.setItem('wchk-theme', next); } catch(e) {} 40 applyTheme(next); 41 }; 42 43 // Global: set explicit mode (called by settings checkbox) 44 window.setTheme = function (mode) { 45 try { localStorage.setItem('wchk-theme', mode); } catch(e) {} 46 applyTheme(mode); 47 }; 48 49 // Sync checkbox when settings opens 50 window.syncThemeCheckbox = function () { 51 var html = document.documentElement; 52 var cb = document.getElementById('stg-dark-mode-toggle'); 53 if (cb) cb.checked = html.classList.contains('dark'); 54 }; 55})();
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.