summaryrefslogtreecommitdiffstats
path: root/g4f
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--g4f/gui/client/static/js/highlightjs-copy.min.js28
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);
+
}
- }
+
}