From e9ecdfe5dd9c1ee15337fc70c71ddc50ec78bb29 Mon Sep 17 00:00:00 2001 From: foxfire52 Date: Fri, 25 Oct 2024 14:14:47 +0200 Subject: Update highlightjs-copy.min.js --- g4f/gui/client/static/js/highlightjs-copy.min.js | 28 ++++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'g4f/gui/client/static') diff --git a/g4f/gui/client/static/js/highlightjs-copy.min.js b/g4f/gui/client/static/js/highlightjs-copy.min.js index f74a6172..20b7d52b 100644 --- a/g4f/gui/client/static/js/highlightjs-copy.min.js +++ b/g4f/gui/client/static/js/highlightjs-copy.min.js @@ -15,13 +15,25 @@ class CopyButtonPlugin { el.parentElement.classList.add("hljs-copy-wrapper"); el.parentElement.appendChild(button); el.parentElement.style.setProperty("--hljs-theme-background", window.getComputedStyle(el).backgroundColor); - button.onclick = function () { - if (!navigator.clipboard) return; + button.onclick = async () => { + if (!navigator.clipboard) { + console.error("navigator.clipboard: Clipboard API unavailable.") + return; + } let newText = text; if (hook && typeof hook === "function") { newText = hook(text, el) || text } - navigator.clipboard.writeText(newText).then(function () { + + try { + console.warn("newText type: ", typeof newText); + console.warn("Current Text: " + newText); + await navigator.clipboard.writeText(newText); + } catch (e) { + console.error("Clipboard API writeText failed!!") + console.error(e); + fallback_copy(newText); + } button.innerHTML = "Copied!"; button.dataset.copied = true; let alert = Object.assign(document.createElement("div"), { @@ -36,9 +48,11 @@ class CopyButtonPlugin { el.parentElement.removeChild(alert); alert = null }, 2e3) - }).then(function () { - if (typeof callback === "function") return callback(newText, el) - }) + } + + + if (typeof callback === "function") return callback(newText, el); + } - } + } -- cgit v1.2.3