diff --git a/dist/assets/index-b2v8Ytf5.js b/dist/assets/index-DgFnfrFO.js similarity index 97% rename from dist/assets/index-b2v8Ytf5.js rename to dist/assets/index-DgFnfrFO.js index 8d3dfe2..a0b113a 100644 --- a/dist/assets/index-b2v8Ytf5.js +++ b/dist/assets/index-DgFnfrFO.js @@ -385,12 +385,45 @@ var imgToWebp = (f, D = 128, q = 80) => new Promise((r, j) => { var b64 = (x) => x.split(",")[1] || ""; var utob = (s) => btoa(unescape(encodeURIComponent(s))); var btou = (s) => decodeURIComponent(escape(atob(s.replace(/\s/g, "")))); -function partsToText(m) { +async function copyToClipboard(text) { + if (typeof text !== "string") text = String(text ?? ""); + if (navigator.clipboard?.writeText) try { + await navigator.clipboard.writeText(text); + return true; + } catch {} + try { + const ta = document.createElement("textarea"); + ta.value = text; + ta.style.position = "fixed"; + ta.style.opacity = "0"; + ta.style.left = "-9999px"; + document.body.appendChild(ta); + ta.focus(); + ta.select(); + const ok = document.execCommand("copy"); + ta.remove(); + return ok; + } catch { + return false; + } +} +function partsToText(m, stripData = false) { if (!m) return ""; - const c = m.content, i = m.images; - let t = Array.isArray(c) ? c.map((p) => p?.type === "text" ? p.text : p?.type === "image_url" ? `![](${p.image_url?.url || ""})` : p?.type === "file" ? `[${p.file?.filename || "file"}]` : p?.type === "input_audio" ? `(audio:${p.input_audio?.format || ""})` : "").join("\n") : String(c || ""); - if (Array.isArray(i)) t += i.map((x) => `\n![](${x.image_url?.url})\n`).join(""); - return t; + const c = m.content, i = m.images, out = []; + if (Array.isArray(c)) { + for (const p of c) if (p?.type === "text") { + if (p.text) out.push(p.text); + } else if (p?.type === "image_url") { + const u = p.image_url?.url || ""; + if (!stripData || !u.startsWith("data:")) out.push(`![](${u})`); + } else if (p?.type === "file") out.push(`[${p.file?.filename || "file"}]`); + else if (p?.type === "input_audio") out.push(`(audio:${p.input_audio?.format || ""})`); + } else if (c != null) out.push(String(c)); + if (Array.isArray(i)) for (const x of i) { + const u = x.image_url?.url || ""; + if (!stripData || !u.startsWith("data:")) out.push(`![](${u})`); + } + return out.join("\n"); } function dl(name, obj) { const blob = new Blob([JSON.stringify(obj, null, 2)], { type: name.endsWith(".sune") ? "application/octet-stream" : "application/json" }), url = URL.createObjectURL(blob), a = document.createElement("a"); @@ -575,11 +608,10 @@ function enhanceCodeBlocks(root, doHL = true) { const len = code.textContent.length, countText = len >= 1e3 ? (len / 1e3).toFixed(1) + "K" : len; const $btn = window.$("").on("click", async (e) => { e.stopPropagation(); - try { - await navigator.clipboard.writeText(code.innerText); + if (await copyToClipboard(code.innerText)) { $btn.text("Copied"); setTimeout(() => $btn.text("Copy"), 1200); - } catch {} + } }); const $container = window.$("
"); $container.append(window.$(`${countText} chars`), $btn); @@ -1123,15 +1155,14 @@ function _createMessageRow(m) { }); const $copyBtn = $("").on("click", async function(e) { e.stopPropagation(); - try { - await navigator.clipboard.writeText(partsToText(m)); + if (await copyToClipboard(partsToText(state.messages.find((x) => x.id === m.id) || m, true))) { $(this).html(""); icons(); setTimeout(() => { $(this).html(""); icons(); }, 1200); - } catch {} + } }); $head.append($avatar, $name, $copyBtn, $deleteBtn); const $bubble = $(`
`); @@ -1485,10 +1516,7 @@ $(el.threadPopover).on("click", async (e) => { const u = el.threadRepoInput.value.trim(); if (u.startsWith("gh://")) { const info = parseGhUrl(u); - try { - await navigator.clipboard.writeText(`${info.owner}/${info.repo}@${info.branch}/${th.id}`); - alert("Path copied."); - } catch {} + if (await copyToClipboard(`${info.owner}/${info.repo}@${info.branch}/${th.id}`)) alert("Path copied."); } } hideThreadPopover(); @@ -2355,11 +2383,7 @@ var onForeground = () => { if (state.busy) syncWhileBusy(); }; $(document).on("visibilitychange", onForeground); -$(el.copySystemPrompt).on("click", async () => { - try { - await navigator.clipboard.writeText(el.set_system_prompt.value || ""); - } catch {} -}); +$(el.copySystemPrompt).on("click", async () => await copyToClipboard(el.set_system_prompt.value || "")); $(el.pasteSystemPrompt).on("click", async () => { try { el.set_system_prompt.value = await navigator.clipboard.readText(); @@ -2367,10 +2391,8 @@ $(el.pasteSystemPrompt).on("click", async () => { }); var getActiveJar = () => !el.htmlEditor.classList.contains("hidden") ? jars.html : jars.extension; $(el.copyHTML).on("click", async () => { - try { - const jar = getActiveJar(); - await navigator.clipboard.writeText(jar ? jar.toString() : ""); - } catch {} + const jar = getActiveJar(); + await copyToClipboard(jar ? jar.toString() : ""); }); $(el.pasteHTML).on("click", async () => { try { @@ -2405,6 +2427,7 @@ Object.assign(window, { _createMessageRow, msgRow, partsToText, + copyToClipboard, addSuneBubbleStreaming, clearChat, payloadWithSampling, diff --git a/dist/index.html b/dist/index.html index 03ab664..cf1a394 100644 --- a/dist/index.html +++ b/dist/index.html @@ -13,7 +13,7 @@ - + diff --git a/dist/sw.js b/dist/sw.js index 2835a5e..29f6f76 100644 --- a/dist/sw.js +++ b/dist/sw.js @@ -1 +1 @@ -if(!self.define){let e,s={};const i=(i,n)=>(i=new URL(i+".js",n).href,s[i]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=i,e.onload=s,document.head.appendChild(e)}else e=i,importScripts(i),s()}).then(()=>{let e=s[i];if(!e)throw new Error(`Module ${i} didn’t register its module`);return e}));self.define=(n,t)=>{const r=e||("document"in self?document.currentScript.src:"")||location.href;if(s[r])return;let o={};const l=e=>i(e,r),c={module:{uri:r},exports:o,require:l};s[r]=Promise.all(n.map(e=>c[e]||l(e))).then(e=>(t(...e),o))}}define(["./workbox-9c191d2f"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"5479938ea7e8721c4c76398f2d94d0f1"},{url:"assets/index-b2v8Ytf5.js",revision:null},{url:"assets/index-DUC1RW1F.css",revision:null},{url:"manifest.webmanifest",revision:"7a6c5c6ab9cb5d3605d21df44c6b17a2"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))}); +if(!self.define){let e,s={};const i=(i,n)=>(i=new URL(i+".js",n).href,s[i]||new Promise(s=>{if("document"in self){const e=document.createElement("script");e.src=i,e.onload=s,document.head.appendChild(e)}else e=i,importScripts(i),s()}).then(()=>{let e=s[i];if(!e)throw new Error(`Module ${i} didn’t register its module`);return e}));self.define=(n,r)=>{const t=e||("document"in self?document.currentScript.src:"")||location.href;if(s[t])return;let o={};const d=e=>i(e,t),l={module:{uri:t},exports:o,require:d};s[t]=Promise.all(n.map(e=>l[e]||d(e))).then(e=>(r(...e),o))}}define(["./workbox-9c191d2f"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"registerSW.js",revision:"1872c500de691dce40960bb85481de07"},{url:"index.html",revision:"0b0cd45d08b40d617d4906d0b3b35466"},{url:"assets/index-DgFnfrFO.js",revision:null},{url:"assets/index-DUC1RW1F.css",revision:null},{url:"manifest.webmanifest",revision:"7a6c5c6ab9cb5d3605d21df44c6b17a2"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("index.html")))});