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

XFEstudio/gpt4free

Undo minify highlightjs-copy.min.js

51d6f285
foxfire52 <foxfire52@virgilio.it>
提交于

代码差异

1 个文件 +44 -1
Modified g4f/gui/client/static/js/highlightjs-copy.min.js +44 -1
@@ -1 +1,44 @@
1 class CopyButtonPlugin{constructor(options={}){self.hook=options.hook;self.callback=options.callback}"after:highlightElement"({el,text}){let button=Object.assign(document.createElement("button"),{innerHTML:"Copy",className:"hljs-copy-button"});button.dataset.copied=false;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;let newText=text;if(hook&&typeof hook==="function"){newText=hook(text,el)||text}navigator.clipboard.writeText(newText).then(function(){button.innerHTML="Copied!";button.dataset.copied=true;let alert=Object.assign(document.createElement("div"),{role:"status",className:"hljs-copy-alert",innerHTML:"Copied to clipboard"});el.parentElement.appendChild(alert);setTimeout(()=>{button.innerHTML="Copy";button.dataset.copied=false;el.parentElement.removeChild(alert);alert=null},2e3)}).then(function(){if(typeof callback==="function")return callback(newText,el)})}}}
1 class CopyButtonPlugin {
2 constructor(options = {}) {
3 self.hook = options.hook;
4 self.callback = options.callback
5 }
6 "after:highlightElement"({
7 el,
8 text
9 }) {
10 let button = Object.assign(document.createElement("button"), {
11 innerHTML: "Copy",
12 className: "hljs-copy-button"
13 });
14 button.dataset.copied = false;
15 el.parentElement.classList.add("hljs-copy-wrapper");
16 el.parentElement.appendChild(button);
17 el.parentElement.style.setProperty("--hljs-theme-background", window.getComputedStyle(el).backgroundColor);
18 button.onclick = function () {
19 if (!navigator.clipboard) return;
20 let newText = text;
21 if (hook && typeof hook === "function") {
22 newText = hook(text, el) || text
23 }
24 navigator.clipboard.writeText(newText).then(function () {
25 button.innerHTML = "Copied!";
26 button.dataset.copied = true;
27 let alert = Object.assign(document.createElement("div"), {
28 role: "status",
29 className: "hljs-copy-alert",
30 innerHTML: "Copied to clipboard"
31 });
32 el.parentElement.appendChild(alert);
33 setTimeout(() => {
34 button.innerHTML = "Copy";
35 button.dataset.copied = false;
36 el.parentElement.removeChild(alert);
37 alert = null
38 }, 2e3)
39 }).then(function () {
40 if (typeof callback === "function") return callback(newText, el)
41 })
42 }
43 }
44 }