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