|
|
| خط ۴: |
خط ۴: |
| document.body.appendChild(ribbon); | | document.body.appendChild(ribbon); |
| }); | | }); |
|
| |
| /* ===== Wikijoo night-mode toggle (2026-05-31) ===== */
| |
| (function () {
| |
| function apply(t) {
| |
| document.documentElement.classList.toggle('wj-night', t === 'dark');
| |
| var b = document.getElementById('wj-theme-btn');
| |
| if (b) {
| |
| b.textContent = (t === 'dark' ? '☀' : '☾');
| |
| b.title = (t === 'dark' ? 'حالت روز' : 'حالت شب');
| |
| }
| |
| }
| |
| var saved = 'light';
| |
| try { saved = localStorage.getItem('wj-theme') || 'light'; } catch (e) {}
| |
| apply(saved);
| |
| function addBtn() {
| |
| if (document.getElementById('wj-theme-btn')) { return; }
| |
| var host = document.querySelector('.vector-header-end') || document.querySelector('#p-personal') || document.querySelector('.vector-user-links');
| |
| if (!host) { return; }
| |
| var btn = document.createElement('button');
| |
| btn.id = 'wj-theme-btn';
| |
| btn.type = 'button';
| |
| btn.className = 'wj-theme-btn';
| |
| btn.setAttribute('aria-label', 'تغییر حالت شب و روز');
| |
| host.insertBefore(btn, host.firstChild);
| |
| btn.addEventListener('click', function () {
| |
| var cur = document.documentElement.classList.contains('wj-night') ? 'dark' : 'light';
| |
| var next = (cur === 'dark') ? 'light' : 'dark';
| |
| try { localStorage.setItem('wj-theme', next); } catch (e) {}
| |
| apply(next);
| |
| });
| |
| apply(document.documentElement.classList.contains('wj-night') ? 'dark' : 'light');
| |
| }
| |
| if (document.readyState !== 'loading') { addBtn(); }
| |
| else { document.addEventListener('DOMContentLoaded', addBtn); }
| |
| })();
| |