(function(){ const isCap = !!window.Capacitor || /Capacitor/i.test(navigator.userAgent); if (!isCap) return; if ((location.origin || '').startsWith('capacitor://')) return; const Plugins = (window.Capacitor && window.Capacitor.Plugins) || {}; const Pref = Plugins.Preferences ? { get: ({key}) => Plugins.Preferences.get({key}), set: ({key,value}) => Plugins.Preferences.set({key,value}), remove:({key}) => Plugins.Preferences.remove({key}) } : { get: async ({key}) => ({ value: localStorage.getItem(key) || null }), set: async ({key,value}) => localStorage.setItem(key, value), remove: async ({key}) => localStorage.removeItem(key) }; const Http = (Plugins.Http || Plugins.CapacitorHttp) || null; const K_INST='fr_instances_v1', K_ACTIVE='fr_active_v1', K_STATUS='fr_status_v1'; const $ = s => document.querySelector(s); const el = (t,a={},html='') => { const n=document.createElement(t); for (const k in a) n.setAttribute(k,a[k]); n.innerHTML=html; return n; }; const normalize = u => { if(!u) return ''; let v=u.trim(); if(!/^https?:\/\//i.test(v)) v='https://'+v; return v.replace(/\/+$/,''); }; const host = u => { try{ return new URL(normalize(u)).hostname }catch{ return '' } }; const originOf = u => { try{ return new URL(normalize(u)).origin }catch{ return '' } }; const faviconUrl = u => { try{ const x=new URL(normalize(u)); return x.origin+'/favicon.ico' }catch{ return '' } }; const initialsIcon = (hn='FR') => { const t=(hn||'FR').replace(/^www\./,'').slice(0,2).toUpperCase(); const svg=``; return 'data:image/svg+xml;utf8,'+encodeURIComponent(svg); }; async function getStatusCache(){ const raw=(await Pref.get({key:K_STATUS})).value; try{ return raw?JSON.parse(raw):{} }catch{ return {}; } } async function writeStatus(origin, ok){ const cache=await getStatusCache(); cache[origin]={ ok, ts: Date.now() }; await Pref.set({key:K_STATUS, value:JSON.stringify(cache)}); } async function verifyFileRise(u, timeout=5000){ if (!u || !Http) return {ok:false}; const base = normalize(u), origin = originOf(base); const tryJson = async (url, validate) => { try{ const r = await Http.get({ url, connectTimeout:timeout, readTimeout:timeout, headers:{'Accept':'application/json','Cache-Control':'no-cache'} }); if (r && r.data) { const j = (typeof r.data === 'string') ? JSON.parse(r.data) : r.data; return !!validate(j); } }catch(_){} return false; }; if (await tryJson(origin + '/siteConfig.json', j => j && (j.appTitle || j.headerTitle || j.auth || j.oidc || j.basicAuth))) return {ok:true, origin}; if (await tryJson(origin + '/api/ping.php', j => j && (j.ok===true || j.status==='ok' || j.pong || j.app==='FileRise'))) return {ok:true, origin}; if (await tryJson(origin + '/api/version.php', j => j && (j.version || j.app==='FileRise'))) return {ok:true, origin}; try{ const r = await Http.get({ url: origin+'/', connectTimeout:timeout, readTimeout:timeout, headers:{'Cache-Control':'no-cache'} }); if (typeof r.data === 'string' && /FileRise/i.test(r.data)) return {ok:true, origin}; }catch(_){} return {ok:false, origin}; } async function probeReachable(u, timeout=3000){ try{ const base = new URL(normalize(u)).origin, ico=base+'/favicon.ico'; if (Http){ try{ const r=await Http.get({ url: ico, connectTimeout:timeout, readTimeout:timeout, headers:{'Cache-Control':'no-cache'} }); if (r && typeof r.status==='number' && r.status<500) return true; }catch(e){} try{ const r2=await Http.get({ url: base+'/', connectTimeout:timeout, readTimeout:timeout, headers:{'Cache-Control':'no-cache'} }); if (r2 && typeof r2.status==='number' && r2.status<500) return true; }catch(e){} return false; } return await new Promise(res=>{ const img=new Image(), t=setTimeout(()=>done(false), timeout); function done(ok){ clearTimeout(t); img.onload=img.onerror=null; res(ok); } img.onload=()=>done(true); img.onerror=()=>done(false); img.src = ico + (ico.includes('?')?'&':'?') + '__fr=' + Date.now(); }); }catch{ return false; } } async function loadInstances(){ const raw=(await Pref.get({key:K_INST})).value; try{ return raw?JSON.parse(raw):[] }catch{ return [] } } async function saveInstances(list){ await Pref.set({key:K_INST, value:JSON.stringify(list)}); } async function getActive(){ return (await Pref.get({key:K_ACTIVE})).value } async function setActive(id){ await Pref.set({key:K_ACTIVE, value:id||''}) } // ---- Styles (slide-up sheet + disabled buttons + safe-area) ---- if (!$('#frx-mobile-style')) { const css = ` .frx-fab { position:fixed; right:16px; bottom:calc(env(safe-area-inset-bottom,0px) + 18px); width:52px; height:52px; border-radius:26px; background: linear-gradient(180deg,#64B5F6,#2196F3 65%,#1976D2); color:#fff; display:grid; place-items:center; box-shadow:0 10px 22px rgba(33,150,243,.38); z-index:2147483647; cursor:pointer; user-select:none; } .frx-fab:active { transform: translateY(1px) scale(.98); } .frx-fab svg { width:26px; height:26px; fill:white } .frx-scrim{position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:2147483645;opacity:0;visibility:hidden;transition:opacity .24s ease} .frx-scrim.show{opacity:1;visibility:visible} .frx-sheet{position:fixed;left:0;right:0;bottom:0;background:#0f172a;color:#e5e7eb; border-top-left-radius:16px;border-top-right-radius:16px;box-shadow:0 -10px 30px rgba(0,0,0,.3); z-index:2147483646;transform:translateY(100%);opacity:0;visibility:hidden; transition:transform .28s cubic-bezier(.2,.8,.2,1), opacity .28s ease; will-change:transform} .frx-sheet.show{transform:translateY(0);opacity:1;visibility:visible} .frx-sheet .hdr{display:flex;align-items:center;justify-content:space-between;padding:14px 16px;border-bottom:1px solid rgba(255,255,255,.08)} .frx-title{display:flex;align-items:center;gap:10px;font-weight:800} .frx-title img{width:22px;height:22px} .frx-list{max-height:60vh;overflow:auto;padding:8px 12px} .frx-chip{border:1px solid rgba(255,255,255,.08);border-radius:12px;padding:12px;margin:8px 4px;background:rgba(255,255,255,.04)} .frx-chip.active{outline:3px solid rgba(33,150,243,.35); border-color:#2196F3} .frx-top{display:flex;gap:10px;align-items:center;justify-content:space-between;margin-bottom:10px} .frx-left{display:flex;gap:10px;align-items:center} .frx-ico{width:20px;height:20px;border-radius:6px;overflow:hidden;background:#fff;display:grid;place-items:center} .frx-ico img{width:100%;height:100%;object-fit:cover;display:block} .frx-name{font-weight:800} .frx-host{font-size:12px;opacity:.8;margin-top:2px} .frx-status{display:flex;align-items:center;gap:6px;font-size:12px;opacity:.9} .frx-dot{width:10px;height:10px;border-radius:50%;} .frx-dot.on{background:#10B981;box-shadow:0 0 0 3px rgba(16,185,129,.18)} .frx-dot.off{background:#ef4444;box-shadow:0 0 0 3px rgba(239,68,68,.18)} .frx-actions{display:flex;gap:8px;flex-wrap:wrap} .frx-btn{appearance:none;border:0;border-radius:10px;padding:10px 12px;font-weight:700;cursor:pointer;transition:.15s ease opacity, .15s ease filter} .frx-btn[disabled]{opacity:.5;cursor:not-allowed;filter:grayscale(20%)} .frx-primary{background:linear-gradient(180deg,#64B5F6,#2196F3);color:#fff} .frx-ghost{background:transparent;color:#cbd5e1;border:1px solid rgba(255,255,255,.12)} .frx-danger{background:transparent;color:#f44336;border:1px solid rgba(244,67,54,.45)} .frx-row{display:flex;gap:8px;align-items:center} .frx-field{display:grid;gap:6px;margin:8px 4px} .frx-input{width:100%;padding:12px;border-radius:10px;border:1px solid rgba(255,255,255,.12);background:transparent;color:inherit} .frx-footer{display:flex;justify-content:flex-end;gap:8px;padding:10px 12px;border-top:1px solid rgba(255,255,255,.08)} @media (pointer:coarse) { .frx-fab { width:58px; height:58px; border-radius:29px; } } `; document.head.appendChild(el('style',{id:'frx-mobile-style'}, css)); } // DOM const scrim = el('div',{class:'frx-scrim', id:'frx-scrim'}); const sheet = el('div',{class:'frx-sheet', id:'frx-sheet'}, `