diff options
author | foxfire52 <foxfire52@virgilio.it> | 2024-10-25 14:14:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-25 14:14:47 +0200 |
commit | e9ecdfe5dd9c1ee15337fc70c71ddc50ec78bb29 (patch) | |
tree | dd47328c5d2edaab7dca9501246cfa933aa55657 /g4f/gui/client | |
parent | Undo minify highlightjs-copy.min.js (diff) | |
download | gpt4free-e9ecdfe5dd9c1ee15337fc70c71ddc50ec78bb29.tar gpt4free-e9ecdfe5dd9c1ee15337fc70c71ddc50ec78bb29.tar.gz gpt4free-e9ecdfe5dd9c1ee15337fc70c71ddc50ec78bb29.tar.bz2 gpt4free-e9ecdfe5dd9c1ee15337fc70c71ddc50ec78bb29.tar.lz gpt4free-e9ecdfe5dd9c1ee15337fc70c71ddc50ec78bb29.tar.xz gpt4free-e9ecdfe5dd9c1ee15337fc70c71ddc50ec78bb29.tar.zst gpt4free-e9ecdfe5dd9c1ee15337fc70c71ddc50ec78bb29.zip |
Diffstat (limited to 'g4f/gui/client')
-rw-r--r-- | g4f/gui/client/static/js/highlightjs-copy.min.js | 28 |
1 files changed, 21 insertions, 7 deletions
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); + } - } + } |