XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Update highlightjs-copy.min.js

e9ecdfe5
foxfire52 <foxfire52@virgilio.it>
提交于

代码差异

1 个文件 +21 -7
Modified g4f/gui/client/static/js/highlightjs-copy.min.js +21 -7
@@ -15,13 +15,25 @@ class CopyButtonPlugin {
15 15 el.parentElement.classList.add("hljs-copy-wrapper");
16 16 el.parentElement.appendChild(button);
17 17 el.parentElement.style.setProperty("--hljs-theme-background", window.getComputedStyle(el).backgroundColor);
18 button.onclick = function () {
19 if (!navigator.clipboard) return;
18 button.onclick = async () => {
19 if (!navigator.clipboard) {
20 console.error("navigator.clipboard: Clipboard API unavailable.")
21 return;
22 }
20 23 let newText = text;
21 24 if (hook && typeof hook === "function") {
22 25 newText = hook(text, el) || text
23 26 }
24 navigator.clipboard.writeText(newText).then(function () {
27
28 try {
29 console.warn("newText type: ", typeof newText);
30 console.warn("Current Text: " + newText);
31 await navigator.clipboard.writeText(newText);
32 } catch (e) {
33 console.error("Clipboard API writeText failed!!")
34 console.error(e);
35 fallback_copy(newText);
36 }
25 37 button.innerHTML = "Copied!";
26 38 button.dataset.copied = true;
27 39 let alert = Object.assign(document.createElement("div"), {
@@ -36,9 +48,11 @@ class CopyButtonPlugin {
36 48 el.parentElement.removeChild(alert);
37 49 alert = null
38 50 }, 2e3)
39 }).then(function () {
40 if (typeof callback === "function") return callback(newText, el)
41 })
51 }
52
53
54 if (typeof callback === "function") return callback(newText, el);
55
42 56 }
43 }
57
44 58 }