import{i as e}from"./dist-lcs5aYiW.js";import{a as t,d as n,l as r,r as i}from"./main-DnoTvuZO.js";var a=document.getElementById(`about-dialog`),o=document.getElementById(`close-about`),s=!1;document.getElementById(`about`).addEventListener(`click`,()=>{a.show()}),o.onclick=()=>a.close(),document.getElementById(`telegram`).onclick=()=>{t(`https://t.me/kowchannel`)},document.getElementById(`github`).onclick=()=>{t(`https://github.com/KOWX712/Tricky-Addon-Update-Target-List`)},document.getElementById(`canary`).onclick=()=>{if(s)return;s=!0,a.close(),r(n(`prompt_checking_update`),!0,1e4);let t=``,o=e(`sh`,[`${i}/common/get_extra.sh`,`--download`,`https://nightly.link/KOWX712/Tricky-Addon-Update-Target-List/workflows/build/main?preview`],{env:{PATH:`$PATH:/data/adb/ap/bin:/data/adb/ksu/bin:/data/adb/magisk`}});o.stdout.on(`data`,e=>{t+=e}),o.on(`exit`,async a=>{if(a===0){let a=new DOMParser().parseFromString(t,`text/html`).querySelector(`a[href$=".zip"]`)?.href;if(a){let t=a.split(`-`),o=t.length>=2?t[t.length-2]:null,l=e(`sh`,[`${i}/common/get_extra.sh`,`--check-update`,`${o}`],{env:{CANARY:`true`}});l.stdout.on(`data`,e=>console.log(e)),l.stderr.on(`data`,e=>console.log(e)),l.on(`exit`,e=>{e===0?(r(n(`prompt_no_update`)),s=!1):e===1&&c(a)})}else console.error(`No link found.`)}else console.error(`Error fetching ZIP link`),s=!1})},document.getElementById(`locales`).onclick=async()=>{if(s)return;s=!0,a.close(),r(n(`prompt_checking_update`),!0,1e4);let t=`https://raw.githubusercontent.com/KOWX712/Tricky-Addon-Update-Target-List/bot/locales_version`,o=await fetch(t).catch(()=>null);if((!o||!o.ok)&&(o=await fetch(`https://gh.sevencdn.com/${t}`).catch(()=>null)),!o||!o.ok){r(n(`prompt_translation_update_failed`),!1),s=!1;return}try{let t=(await o.text()).trim(),a=await fetch(`locales/version`).catch(()=>null),c=a?(await a.text()).trim():`0`;Number(t)<=Number(c)?(r(n(`prompt_no_update`)),s=!1):(r(n(`prompt_downloading`),!0,2e4),e(`sh`,[`${i}/common/get_extra.sh`,`--update-locales`]).on(`exit`,e=>{s=!1,r(n(e===0?`prompt_translation_updated`:`prompt_translation_update_failed`),e===0),e===0&&window.location.reload()}))}catch{r(n(`prompt_translation_update_failed`),!1),s=!1}};function c(t){r(n(`prompt_downloading`),!0,2e4);let a=e(`sh`,[`${i}/common/get_extra.sh`,`--get-update`,`${t}`],{env:{PATH:`$PATH:/data/adb/ap/bin:/data/adb/ksu/bin:/data/adb/magisk:/data/data/com.termux/files/usr/bin`}});a.stdout.on(`data`,e=>console.log(e)),a.stderr.on(`data`,e=>console.log(e)),a.on(`exit`,e=>{e===0?l():(r(n(`prompt_download_fail`),!1),s=!1)})}function l(){r(n(`prompt_installing`));let t=``,a=e(`sh`,[`${i}/common/get_extra.sh`,`--install-update`],{env:{PATH:`$PATH:/data/adb/ap/bin:/data/adb/ksu/bin:/data/adb/magisk`}});a.stdout.on(`data`,e=>t+=e),a.stderr.on(`data`,e=>{console.error(`Error during installation:`,e)}),a.on(`exit`,e=>{t.includes(`No need to reboot`)&&window.location.reload(),e===0?r(n(`prompt_installed`)):r(n(`prompt_install_fail`),!1),s=!1})}