mirror of
https://github.com/multipleof4/devsune.git
synced 2026-01-13 16:07:55 +00:00
Update index.html via Sune
This commit is contained in:
@@ -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=`<!-- Sune load failed for ${esc(src)}: ${esc(errorMsg)} -->`}}};
|
||||
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=`<!-- Sune load failed for ${esc(src)}: ${esc(errorMsg)} -->`}}};
|
||||
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?`<img src="${esc(a.avatar)}" alt="" class="h-8 w-8 rounded-full object-cover"/>`:'✺';icons();await renderSuneHTML()}
|
||||
const suneRow=a=>`<div class="relative flex items-center gap-2 px-3 py-2 ${a.pinned?'bg-yellow-50':''}"><button data-sune-id="${a.id}" class="flex-1 text-left flex items-center gap-2 ${a.id===SUNE.id?'font-medium':''}">${a.avatar?`<img src="${esc(a.avatar)}" alt="" class="h-6 w-6 rounded-full object-cover"/>`:`<span class="h-6 w-6 rounded-full bg-gray-200 flex items-center justify-center">✺</span>`}<span class="truncate">${a.pinned?'📌 ':''}${esc(a.name)}</span></button><button data-sune-menu="${a.id}" class="h-8 w-8 rounded hover:bg-gray-100 flex items-center justify-center" title="More"><i data-lucide="more-horizontal" class="h-4 w-4"></i></button></div>`
|
||||
|
||||
Reference in New Issue
Block a user