mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-12-23 11:02:40 +03:00
Update highlightjs-copy.min.js
This commit is contained in:
parent
51d6f28511
commit
e9ecdfe5dd
26
g4f/gui/client/static/js/highlightjs-copy.min.js
vendored
26
g4f/gui/client/static/js/highlightjs-copy.min.js
vendored
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user