// public/js/adminSponsor.js import { t } from './i18n.js?v={{APP_QVER}}'; import { showToast } from './domUtils.js?v={{APP_QVER}}'; // Tiny "translate with fallback" helper, same as in adminPanel.js const tf = (key, fallback) => { const v = t(key); return (v && v !== key) ? v : fallback; }; const SPONSOR_GH = 'https://github.com/sponsors/error311'; const SPONSOR_KOFI = 'https://ko-fi.com/error311'; /** * Initialize the Sponsor / Donations section inside the Admin Panel. * Safe to call multiple times; it no-ops after the first run. */ export function initAdminSponsorSection() { const container = document.getElementById('sponsorContent'); if (!container) return; // Avoid double-wiring if initAdminSponsorSection gets called again if (container.__sponsorInited) return; container.__sponsorInited = true; container.innerHTML = `
${tf("sponsor_note_fixed", "Please consider supporting ongoing development.")} `; const ghInput = document.getElementById('sponsorGitHub'); const kfInput = document.getElementById('sponsorKoFi'); const copyGhBtn = document.getElementById('copySponsorGitHub'); const copyKfBtn = document.getElementById('copySponsorKoFi'); const openGh = document.getElementById('openSponsorGitHub'); const openKf = document.getElementById('openSponsorKoFi'); if (openGh) openGh.href = SPONSOR_GH; if (openKf) openKf.href = SPONSOR_KOFI; async function copyToClipboardSafe(text) { try { if (navigator.clipboard && window.isSecureContext) { await navigator.clipboard.writeText(text); } else { const ta = document.createElement('textarea'); ta.value = text; ta.style.position = 'fixed'; ta.style.left = '-9999px'; document.body.appendChild(ta); ta.select(); document.execCommand('copy'); ta.remove(); } showToast(tf("copied", "Copied!")); } catch { showToast(tf("copy_failed", "Could not copy. Please copy manually.")); } } if (copyGhBtn && ghInput) { copyGhBtn.addEventListener('click', () => copyToClipboardSafe(ghInput.value)); } if (copyKfBtn && kfInput) { copyKfBtn.addEventListener('click', () => copyToClipboardSafe(kfInput.value)); } }