MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
(function () { | (function () { | ||
'use strict'; | 'use strict'; | ||
var KEY = ' | var KEY = 'icelist_anon_donate_dismiss_until'; | ||
var DAYS = 14; | var DAYS = 14; | ||
function | if (!mw.user.isAnon()) return; | ||
var until = parseInt(localStorage.getItem(KEY) || '0', 10); | |||
if (Date.now() < until) return; | |||
function mount() { | |||
var siteNotice = document.getElementById('siteNotice'); | var siteNotice = document.getElementById('siteNotice'); | ||
if (!siteNotice) return; | if (!siteNotice) return; | ||
var | // If empty, do nothing | ||
var txt = (siteNotice.textContent || '').replace(/\s+/g, ' ').trim(); | |||
if (!txt) return; | |||
siteNotice.classList.add('icelist-anon-donate'); | |||
// | // Add close button once | ||
var | if (!siteNotice.querySelector('.icelist-notice-close')) { | ||
var btn = document.createElement('button'); | |||
btn.type = 'button'; | |||
btn.className = 'icelist-notice-close'; | |||
btn.setAttribute('aria-label', 'Close'); | |||
btn.textContent = '×'; | |||
siteNotice.insertBefore(btn, siteNotice.firstChild); | |||
btn.addEventListener('click', function (e) { | |||
e.preventDefault(); | |||
siteNotice.style.display = 'none'; | |||
localStorage.setItem(KEY, String(Date.now() + DAYS * 24 * 60 * 60 * 1000)); | |||
}); | |||
} | } | ||
} | } | ||
if (document.readyState === 'loading') { | if (document.readyState === 'loading') { | ||
document.addEventListener('DOMContentLoaded', | document.addEventListener('DOMContentLoaded', mount); | ||
} else { | } else { | ||
mount(); | |||
} | } | ||
})(); | })(); | ||