diff --git a/index.html b/index.html index c2b1d79..0d6a7f6 100644 --- a/index.html +++ b/index.html @@ -162,7 +162,7 @@ const SUNE=window.SUNE=new Proxy({get list(){return sunes},get id(){return su.ge if(!sunes.length){const def=SUNE.create({name:'Default'});SUNE.setActive(def.id)} const state={messages:[],busy:false,controller:null,currentThreadId:null,abortRequested:false,attachments:[],stream:{rid:null,bubble:null,meta:null,text:'',done:false}} const getModelShort=m=>{const mm=m||SUNE.model||'';return mm.includes('/')?mm.split('/').pop():mm} -const renderSuneTag=async(root=document)=>{for(const tag of root.querySelectorAll('sune[src^="gh://"]')){const src=tag.getAttribute('src');try{const[,org,repo,...path]=src.replace('gh://','').split('/');if(!org||!repo||!path.length)throw new Error('Invalid gh:// URL format');const url=`https://cdn.jsdelivr.net/gh/${org}/${repo}/${path.join('/')}`;const response=await fetch(url);if(!response.ok)throw new Error(`HTTP error ${response.status}: ${response.statusText}`);const suneData=await response.json();if(!suneData||typeof suneData!=='object')throw new Error('Invalid Sune JSON data');const html=[suneData?.settings?.html,suneData?.settings?.extension_html].join('\n');const div=document.createElement('div');div.innerHTML=html;div.querySelectorAll('script').forEach(s=>{const n=document.createElement('script');[...s.attributes].forEach(a=>n.setAttribute(a.name,a.value));n.text=s.text;document.body.appendChild(n);s.remove()});tag.replaceWith(...div.childNodes)}catch(e){const errorMsg=e instanceof Error?e.message:String(e);console.error(`Sune load failed for ${src}:`,errorMsg);tag.outerHTML=``}}}; +const renderSuneTag=async(root=document)=>{for(const tag of root.querySelectorAll('sune[src^="gh://"]')){const src=tag.getAttribute('src');try{const[org,repo,...path]=src.replace('gh://','').split('/');if(!org||!repo||!path.length)throw new Error('Invalid gh:// URL format');const url=`https://cdn.jsdelivr.net/gh/${org}/${repo}/${path.join('/')}`;const response=await fetch(url);if(!response.ok)throw new Error(`HTTP error ${response.status}: ${response.statusText}`);const suneData=await response.json();if(!suneData||typeof suneData!=='object')throw new Error('Invalid Sune JSON data');const html=[suneData?.settings?.html,suneData?.settings?.extension_html].join('\n');const div=document.createElement('div');div.innerHTML=html;div.querySelectorAll('script').forEach(s=>{const n=document.createElement('script');[...s.attributes].forEach(a=>n.setAttribute(a.name,a.value));n.text=s.text;document.body.appendChild(n);s.remove()});tag.replaceWith(...div.childNodes)}catch(e){const errorMsg=e instanceof Error?e.message:String(e);console.error(`Sune load failed for ${src}:`,errorMsg);tag.outerHTML=``}}}; const renderSuneHTML=async()=>{const c=[SUNE.html,SUNE.extension_html].map(x=>(x||'').trim()).join('\n'),m=el.suneHtml;m.innerHTML='';m.classList.toggle('hidden',!c);if(!c)return;m.insertAdjacentHTML('afterbegin',c);m.querySelectorAll('script').forEach(s=>{const n=document.createElement('script');[...s.attributes].forEach(a=>n.setAttribute(a.name,a.value));n.text=s.text;s.replaceWith(n)});await renderSuneTag(m)} const reflectActiveSune=async()=>{const a=SUNE.active;el.suneBtnTop.title=`Settings — ${a.name}`;el.suneBtnTop.innerHTML=a.avatar?``:'✺';icons();await renderSuneHTML()} const suneRow=a=>`
`