|
|
| Line 1: |
Line 1: |
| /* ICE List – Donate notice controller | | /* === ICE List Site Notice Close Button (Minimal, Safe) === */ |
| * - Shows a big top notice for anonymous users
| |
| * - Dismissible with X
| |
| * - Remembers dismissal for N days via localStorage
| |
| * - Replaces whatever is in #siteNotice (including plain Anonnotice text)
| |
| */
| |
|
| |
|
| (function () {
| | mw.hook('wikipage.content').add(function () { |
| 'use strict';
| |
| | |
| // === CONFIG ===
| |
| var KEY = 'icelist_donate_notice_until';
| |
| var DAYS = 14;
| |
| | |
| // Show only to anonymous users
| |
| if (!mw.user.isAnon()) return;
| |
| | |
| // Respect dismissal window
| |
| var until = parseInt(localStorage.getItem(KEY) || '0', 10);
| |
| if (Date.now() < until) return;
| |
| | |
| function mount() {
| |
| var siteNotice = document.getElementById('siteNotice');
| |
| if (!siteNotice) return;
| |
| | |
| // If there is literally no notice area text/content, still allow injection.
| |
| // (Some skins may render an empty wrapper; that’s fine.)
| |
| | |
| // Build the banner as real DOM/HTML (NOT escaped entities)
| |
| siteNotice.innerHTML =
| |
| '<div id="donate-top-notice">' +
| |
| '<div class="donate-notice-inner">' +
| |
| '<span class="donate-title">Support ICE List</span>' +
| |
| '<span class="donate-text">We document federal immigration enforcement, identify agents, and preserve evidence that would otherwise disappear. Donations keep this work public, independent, and alive.</span>' +
| |
| '<a class="donate-btn" href="' + mw.util.getUrl('ICE_List_Wiki:Donate') + '">Donate</a>' +
| |
| '<button id="donate-notice-close" aria-label="Close" type="button">×</button>' +
| |
| '</div>' +
| |
| '</div>';
| |
| | |
| var closeBtn = document.getElementById('donate-notice-close');
| |
| if (!closeBtn) return;
| |
| | |
| closeBtn.addEventListener('click', function () {
| |
| var wrap = document.getElementById('donate-top-notice');
| |
| if (wrap) wrap.style.display = 'none';
| |
| localStorage.setItem(KEY, String(Date.now() + DAYS * 24 * 60 * 60 * 1000));
| |
| });
| |
| }
| |
| | |
| // Ensure DOM is ready
| |
| if (document.readyState === 'loading') {
| |
| document.addEventListener('DOMContentLoaded', mount);
| |
| } else {
| |
| mount();
| |
| }
| |
| })();
| |
| | |
| (function () {
| |
| const banner = document.getElementById('icelist-donate-banner');
| |
| if (!banner) return;
| |
| | |
| if (localStorage.getItem('icelistDonateBannerDismissed') === 'true') {
| |
| banner.style.display = 'none';
| |
| return;
| |
| }
| |
| | |
| const dismiss = document.getElementById('icelist-donate-dismiss');
| |
| if (dismiss) {
| |
| dismiss.addEventListener('click', function () {
| |
| banner.style.display = 'none';
| |
| localStorage.setItem('icelistDonateBannerDismissed', 'true');
| |
| });
| |
| }
| |
| })();
| |
| (function () { | |
| var KEY = 'icelist_notice_closed';
| |
| | |
| // anon users only
| |
| if (!mw.user.isAnon()) return; | | if (!mw.user.isAnon()) return; |
|
| |
|
| Line 82: |
Line 7: |
| if (!notice) return; | | if (!notice) return; |
|
| |
|
| // already dismissed | | // Already dismissed |
| if (localStorage.getItem(KEY) === '1') { | | if (localStorage.getItem('icelist_notice_closed') === '1') { |
| notice.style.display = 'none'; | | notice.style.display = 'none'; |
| return; | | return; |
| } | | } |
|
| |
|
| // create close button | | // Prevent duplicate buttons |
| | if (notice.querySelector('.icelist-notice-close')) return; |
| | |
| var btn = document.createElement('button'); | | var btn = document.createElement('button'); |
| | btn.className = 'icelist-notice-close'; |
| | btn.setAttribute('aria-label', 'Close'); |
| btn.textContent = '×'; | | btn.textContent = '×'; |
| btn.setAttribute('aria-label', 'Close'); | | |
| btn.className = 'icelist-notice-close'; | | btn.onclick = function () { |
| | notice.style.display = 'none'; |
| | localStorage.setItem('icelist_notice_closed', '1'); |
| | }; |
|
| |
|
| notice.appendChild(btn); | | notice.appendChild(btn); |
| | | }); |
| btn.addEventListener('click', function () {
| |
| notice.style.display = 'none';
| |
| localStorage.setItem(KEY, '1');
| |
| });
| |
| })();
| |