From 669e2886f9213d593faa02c53019d5b45f4a9b3a Mon Sep 17 00:00:00 2001 From: multipleof4 Date: Fri, 5 Sep 2025 22:32:37 -0700 Subject: [PATCH] Contexual Fragment --- index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.html b/index.html index a4e1db8..f675152 100644 --- a/index.html +++ b/index.html @@ -165,7 +165,7 @@ const state=window.state={messages:[],busy:false,controller:null,currentThreadId const getModelShort=m=>{const mm=m||SUNE.model||'';return mm.includes('/')?mm.split('/').pop():mm} const resolveSuneSrc=src=>{if(!src)return null;if(src.startsWith('gh://')){const path=src.substring(5),parts=path.split('/');if(parts.length<3)return null;const[owner,repo,...filePathParts]=parts;return`https://raw.githubusercontent.com/${owner}/${repo}/main/${filePathParts.join('/')}`}return src} const processSuneIncludes=async(html,depth=0)=>{if(depth>5)return'';if(!html)return'';const c=document.createElement('div');c.innerHTML=html;for(const n of[...c.querySelectorAll('sune')]){if(n.hasAttribute('src')){if(n.hasAttribute('private')&&depth>0){n.remove();continue}const s=n.getAttribute('src'),u=resolveSuneSrc(s);if(!u){n.replaceWith(document.createComment(` Invalid src: ${esc(s)} `));continue}try{const r=await fetch(u);if(!r.ok)throw new Error(`HTTP ${r.status}`);const d=await r.json(),o=Array.isArray(d)?d[0]:d,h=[o?.settings?.html||'',o?.settings?.extension_html||''].join('\n');n.replaceWith(document.createRange().createContextualFragment(await processSuneIncludes(h,depth+1)))}catch(e){n.replaceWith(document.createComment(` Fetch failed: ${esc(u)} `))}}else{n.replaceWith(document.createRange().createContextualFragment(n.innerHTML))}}return c.innerHTML} -const renderSuneHTML=async()=>{const baseHtml=[SUNE.html,SUNE.extension_html].map(x=>(x||'').trim()).join('\n');const finalHtml=await processSuneIncludes(baseHtml,0);const container=el.suneHtml;container.innerHTML='';container.classList.toggle('hidden',!finalHtml.trim());if(!finalHtml.trim())return;container.insertAdjacentHTML('afterbegin',finalHtml);const scripts=[];container.querySelectorAll('script').forEach(s=>{if(!s.type||s.type==='text/javascript'){scripts.push(s.textContent);s.remove()}});if(scripts.length)setTimeout(()=>scripts.forEach(code=>{try{new Function(code)()}catch(e){console.error('Sune script error:',e)}}),0)} +const renderSuneHTML=async()=>{const h=await processSuneIncludes([SUNE.html,SUNE.extension_html].map(x=>(x||'').trim()).join('\n')),c=el.suneHtml;c.innerHTML='';const t=h.trim();c.classList.toggle('hidden',!t);if(t)c.appendChild(document.createRange().createContextualFragment(h))} const reflectActiveSune=async()=>{const a=SUNE.active;el.suneBtnTop.title=`Settings — ${a.name}`;el.suneBtnTop.innerHTML=a.avatar?``:'✺';await renderSuneHTML();icons()} const suneRow=a=>`
` const renderSidebar=window.renderSidebar=()=>{const list=[...SUNE.list].sort((a,b)=>(b.pinned-a.pinned));el.suneList.innerHTML=list.map(suneRow).join('');icons()}