مدیاویکی:Common.js: تفاوت میان نسخهها
(رفع خطای ES5 (نماد BMP بهجای ایموجی)) |
(بازنویسی تمیز Common.js (رفع ریدایرکت ناخواسته + دکمهٔ شب/روز)) |
||
| خط ۱: | خط ۱: | ||
mw.loader.using('mediawiki.util', function () { | mw.loader.using('mediawiki.util', function () { | ||
var ribbon = document.createElement("div"); | var ribbon = document.createElement("div"); | ||
| خط ۱۰: | خط ۴: | ||
document.body.appendChild(ribbon); | document.body.appendChild(ribbon); | ||
}); | }); | ||
/* ===== Wikijoo night-mode toggle (2026-05-31) ===== */ | /* ===== Wikijoo night-mode toggle (2026-05-31) ===== */ | ||
(function () { | (function () { | ||
نسخهٔ ۳۱ مهٔ ۲۰۲۶، ساعت ۱۲:۱۹
mw.loader.using('mediawiki.util', function () {
var ribbon = document.createElement("div");
ribbon.className = "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); }
})();