(() => { const t = (k, vars) => window.WrappedI18n.t(k, vars); let settings = null; const els = { token: document.getElementById("token-input"), password: document.getElementById("unwrap-password"), btn: document.getElementById("unwrap-btn"), error: document.getElementById("form-error"), errorTitle: document.getElementById("form-error-title"), errorHint: document.getElementById("form-error-hint"), errorAttempts: document.getElementById("form-error-attempts"), form: document.getElementById("unwrap-form"), result: document.getElementById("result-panel"), items: document.getElementById("items"), captchaSlot: document.getElementById("captcha-slot"), }; function showError(title, hint, attempts) { if (!els.error) return; if (els.errorTitle) els.errorTitle.textContent = title || ""; if (els.errorHint) { if (hint) { els.errorHint.textContent = hint; els.errorHint.classList.remove("hidden"); } else { els.errorHint.textContent = ""; els.errorHint.classList.add("hidden"); } } if (els.errorAttempts) { if (attempts) { els.errorAttempts.textContent = attempts; els.errorAttempts.classList.remove("hidden"); } else { els.errorAttempts.textContent = ""; els.errorAttempts.classList.add("hidden"); } } // Fallback if structured nodes missing if (!els.errorTitle) els.error.textContent = [title, hint, attempts].filter(Boolean).join(" "); els.error.classList.remove("hidden"); } function clearError() { if (!els.error) return; els.error.classList.add("hidden"); if (els.errorTitle) els.errorTitle.textContent = ""; if (els.errorHint) { els.errorHint.textContent = ""; els.errorHint.classList.add("hidden"); } if (els.errorAttempts) { els.errorAttempts.textContent = ""; els.errorAttempts.classList.add("hidden"); } } function attemptsLabel(detail) { const n = Number(detail?.attempts_remaining); const max = Number(detail?.attempts_max); if (!Number.isFinite(n) || !Number.isFinite(max)) return ""; return t("unwrap.attemptsLeft", { n, max }); } function loadCaptcha() { els.captchaSlot.innerHTML = ""; const provider = settings.captcha_provider; if (provider === "turnstile" && settings.turnstile_site_key) { const div = document.createElement("div"); div.className = "cf-turnstile"; div.dataset.sitekey = settings.turnstile_site_key; els.captchaSlot.appendChild(div); const s = document.createElement("script"); s.src = "https://challenges.cloudflare.com/turnstile/v0/api.js"; s.async = true; document.body.appendChild(s); } else if (provider === "hcaptcha" && settings.hcaptcha_site_key) { const div = document.createElement("div"); div.className = "h-captcha"; div.dataset.sitekey = settings.hcaptcha_site_key; els.captchaSlot.appendChild(div); const s = document.createElement("script"); s.src = "https://js.hcaptcha.com/1/api.js"; s.async = true; document.body.appendChild(s); } } function captchaToken() { if (settings.captcha_provider === "turnstile" && window.turnstile) { return window.turnstile.getResponse?.() || ""; } if (settings.captcha_provider === "hcaptcha" && window.hcaptcha) { return window.hcaptcha.getResponse?.() || ""; } return ""; } function resolveKey(parsed) { if (parsed.key) return parsed.key; if (location.hash && location.hash.length > 1) return location.hash.slice(1); return null; } function downloadBlob(name, blob) { const a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = name; a.click(); setTimeout(() => URL.revokeObjectURL(a.href), 2000); } function makeDownloadBtn(onClick) { const btn = document.createElement("button"); btn.className = "btn download-btn"; btn.type = "button"; btn.innerHTML = `${t("common.download")}`; btn.addEventListener("click", onClick); return btn; } function makeCopyBtn(getText) { const btn = document.createElement("button"); btn.className = "btn copy-btn"; btn.type = "button"; const label = () => `${t("common.copy")}`; btn.innerHTML = label(); btn.addEventListener("click", async () => { try { await navigator.clipboard.writeText(getText() || ""); btn.innerHTML = `${t("common.copied")}`; setTimeout(() => { btn.innerHTML = label(); }, 1200); } catch { /* ignore */ } }); return btn; } function renderPackage(pack) { els.items.innerHTML = ""; for (const item of pack.items || []) { const card = document.createElement("div"); card.className = "item-card"; if (item.type === "text") { const lang = item.language || "plaintext"; const text = item.content || ""; const head = document.createElement("div"); head.className = "item-card-head"; head.innerHTML = `