From 114d4b469e2710479921601f63d9777c91c24f43 Mon Sep 17 00:00:00 2001 From: ZhengLinLei Date: Tue, 23 Jan 2024 10:18:22 +0100 Subject: [PATCH] Fixed dblclick --- js/min/script.min.js | 2 +- js/src/script.js | 70 ++++++++++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/js/min/script.min.js b/js/min/script.min.js index a180d7d..bf01363 100644 --- a/js/min/script.min.js +++ b/js/min/script.min.js @@ -1 +1 @@ -let setTabSize=t=>{document.querySelectorAll(".textarea div pre code").forEach(e=>{e.style.tabSize=""+(0!=t?t:4),e.style.MozTabSize=""+(0!=t?t:4)}),tabSize=t},tabSize=4,tabRegex=/\t/g;const ThemeArr=["light","dark","funky","twilight","solarized","night","zll"];let THEME_={importTheme:e=>{var t=new FileReader;const r=document.querySelector("#terminal-main-history");t.readAsText(e.files[0],"UTF-8"),t.onload=e=>{let t=e.target.result,o="";try{for(var n in t=JSON.parse(t),document.body.removeAttribute("class"),document.body.classList.add(t.class),localStorage.setItem("theme",t.class),delete t.class,t)document.body.style.setProperty(n,t[n]);localStorage.setItem("customTheme",JSON.stringify(t))}catch(e){o="Error: Cannot parse JSON"}e=document.createElement("div");e.classList.add("terminal-output"),e.innerHTML=o,r.appendChild(e),terminal.scrollTop=terminal.scrollHeight},t.onerror=()=>{var e=document.createElement("div");e.classList.add("terminal-output"),e.innerHTML="Error: Cannot read file content",r.appendChild(e),terminal.scrollTop=terminal.scrollHeight}},exportTheme:()=>{var e,t={"--theme-bg-color":"","--theme-primary-color":"","--theme-secondary-color":"","--theme-color-muted":"","--theme-text-color":"","--theme-extra-color":"","--theme-border-color":"","--theme-caret-color":"","--theme-alert-color":"","--theme-cristal-color":"","--theme-footer-color":""};for(e in t)t[e]=document.body.style.getPropertyValue(e);t.class=document.body.classList[0],saveToFile("PasteCodeTheme.json",JSON.stringify(t))}},TMP_ID=0;function Out(e){document.querySelector("#"+TMP_ID).innerHTML+=e+"
"}function saveToFile(e,t){var o;"saveAs"in window?(o=new Blob([t],{type:"text/plain;charset=utf-8"}),saveAs(o,e)):((o=document.createElement("a")).setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(t)),o.setAttribute("download",e),o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o))}window.addEventListener("load",()=>{var l=new LZMA("./js/src/lzma_worker.js");const s={url:document.location,base64:"undefined",_get:{},localStorage:{fileMemory:"paste-code",autoExecuteFlag:"paste-code-auto-execute"}},d={parent:document.querySelector(".textarea"),max:4,min:1,label:"Window",current:0,focus:0,visible:0,windows:[],codeWindow:[],windows_value:[],lineActive:[]};let i=e=>{document.querySelector(".alert-modal").classList.add("active"),document.querySelector(".alert-modal-text").textContent=e,setTimeout(function(){document.querySelector(".alert-modal").classList.remove("active")},5e3)};const u=e=>{var e=e.value.split("\n")[0];return!!e.match(/[\!|\?]/)&&((e=(e=e.split(/[\!|\?]/))[e.length-1].toLowerCase().trim()).includes("--\x3e")?e.replace("--\x3e","").trim():e)},a=e=>{var t=d.windows.indexOf(e),o=d.codeWindow[t],n=e.value.split("\n"),r=u(e);r&&o.setAttribute("class","language-"+r),tabRegex.test(e.value)&&(e.value=e.value.replaceAll(tabRegex," ".repeat(tabSize))),o.innerHTML=e.value.replaceAll(new RegExp("&","g"),"&").replaceAll(new RegExp("<","g"),"<"),Prism.highlightElement(o),document.querySelector(".w-"+t).style.setProperty("--padd",100<=n.length?1e3<=n.length?1e4<=n.length?"55px":"45px":"35px":"25px"),e.parentElement.querySelector(".line-numbers-rows").innerHTML=Array(n.length).fill("").join(""),e===document.activeElement&&c(e)},c=(e,t=-1)=>{var o=e.value.substring(0,e.selectionStart).split("\n").length,n=e.parentElement.querySelector(".line-numbers-rows");o+t{e=e.parentElement.querySelector(".line-numbers-rows");Array.from(e.children).forEach(e=>{e.classList.remove("current")})};function p(){var e;d.parent.classList.remove("odd-3"),d.parent.classList.remove("odd-4"),3==d.visible&&(3==d.current?d.parent.classList.add("odd-3"):(!(e=["none"==d.windows[2].parentElement.style.display,"none"==d.windows[3].parentElement.style.display])[0]&&e[1]&&d.parent.classList.add("odd-3"),d.parent.classList.add("odd-4")))}const h=()=>{if(d.current{var e=n.classList[0].replace("w-","");d.focus=e}),n.addEventListener("dblclick",()=>{if(1document.querySelector(".hidden-tab").classList.remove("demo"),1e3),n.style.display="none",d.visible--,p();let t=document.createElement("a");t.onclick=e=>{n.style.display="block",t.remove(),d.focus=n.classList[0].replace("w-",""),d.visible++,p()};let o;try{o=n.querySelector("pre").classList[0].replace("language-","")}catch(e){o=""}t.innerHTML=`[${0a(l)),l.addEventListener("mouseup",()=>c(l)),("ontouchstart"in window||0c(l)),l.addEventListener("scroll",()=>{r.scrollTo(l.scrollLeft,l.scrollTop),o.scrollTo(l.scrollLeft,l.scrollTop)}),l.addEventListener("keydown",e=>{var t=(e,t)=>{var o=l.selectionStart;l.value=l.value.substring(0,o)+e+l.value.substring(l.selectionEnd),l.selectionStart=l.selectionEnd=o+t,a(l)},o=("Tab"!=e.key&&9!=e.keyCode&&9!=e.which||(e.preventDefault(),t(" ".repeat(tabSize),tabSize)),{"(":")","[":"]","{":"}",'"':'"',"'":"'","`":"`"}),o=(e.key in o&&t(o[e.key],0),(r.classList[0]??"").replace("language-","").toUpperCase());"<"!=e.key||"HTML"!=o&&"XML"!=o||t(">",0),"ArrowUp"!=e.key&&38!=e.keyCode&&38!=e.which||c(l,delay=-2),"ArrowDown"!=e.key&&40!=e.keyCode&&40!=e.which||c(l,delay=0),(e.altKey&&"l"==e.key||e.altKey&&76==e.keyCode||e.altKey&&76==e.which)&&(e.preventDefault(),o=l.value.substring(0,l.selectionStart).lastIndexOf("\n")+1,t=l.value.substring(l.selectionEnd).indexOf("\n")+l.selectionEnd,t+=t==l.value.length-1?1:0,l.setSelectionRange(o,t)),e.ctrlKey&&"s"===e.key&&(e.preventDefault(),b("url",!0,e=>{try{localStorage.setItem(s.localStorage.fileMemory,e),i("Content saved successfully")}catch(e){i("Error saving")}}))}),l.addEventListener("keyup",e=>{"Enter"!=e.key&&13!=e.keyCode&&13!=e.which&&"ArrowUp"!=e.key&&38!=e.keyCode&&38!=e.which&&"ArrowDown"!=e.key&&40!=e.keyCode&&40!=e.which&&"ArrowLeft"!=e.key&&37!=e.keyCode&&37!=e.which&&"ArrowRight"!=e.key&&39!=e.keyCode&&39!=e.which||c(l)}),l.addEventListener("focusout",()=>{m(l)}),r.appendChild(t),n.appendChild(o),n.appendChild(l),n.appendChild(r),d.parent.appendChild(n),d.windows.push(l),d.current++,d.visible++,d.parent.classList.remove("odd-3"),d.parent.classList.remove("odd-4"),p(),2!=d.current&&4!=d.current||((e=document.createElement("div")).classList.add("LR"),e.classList.add("LR-1"),n.appendChild(e)),2!=d.current&&3!=d.current&&4!=d.current||((e=document.createElement("div")).classList.add("TB"),e.classList.add("TB-"+(d.current-2)),n.appendChild(e)),d.codeWindow.push(t),n.classList.add("w-"+(d.current-1)),!0}0document.querySelector(".hidden-tab").classList.remove("demo"),1e3))},w=()=>{if(d.current>d.min&&d.visible>d.min){for(;;){if("none"!=d.windows[d.focus].parentElement.style.display)break;0==d.focus?d.focus=d.current-1:d.focus--}const t=()=>{d.parent.removeChild(d.windows[d.focus].parentElement),d.windows=d.windows.filter((e,t)=>t!=d.focus),d.codeWindow=d.codeWindow.filter((e,t)=>t!=d.focus),d.current--,d.visible--,p(),d.windows.forEach((e,t)=>{e.parentElement.classList.remove(...e.parentElement.classList),e.parentElement.classList.add("w-"+t)}),document.querySelector(".hidden-tab").classList.add("demo"),setTimeout(()=>document.querySelector(".hidden-tab").classList.remove("demo"),1e3)};document.querySelector(".modal-text").textContent="Are you sure you want to remove the window ["+d.focus+"]?",document.querySelector(".container-modal .code").innerHTML="",document.querySelector(".container-modal .code").appendChild(d.codeWindow[d.focus].parentElement.cloneNode(!0)),document.querySelector(".container-modal").classList.add("show"),document.getElementById("confirm-modal").onclick=t,window.onkeydown=e=>{"Enter"!=e.key&&13!=e.keyCode&&"Enter"!=e.code&&13!=e.which||(t(),document.querySelector(".container-modal").classList.remove("show"),window.onkeydown=null)}}},g=()=>document.querySelector("body > footer").classList.remove("text-offer"),v=e=>{var t;return"touchstart"==e.type||"touchmove"==e.type||"touchend"==e.type||"touchcancel"==e.type?(t=(t=void 0===e.originalEvent?e:e.originalEvent).touches[0]||t.changedTouches[0],x=t.pageX,y=t.pageY):"mousedown"!=e.type&&"mouseup"!=e.type&&"mousemove"!=e.type&&"mouseover"!=e.type&&"mouseout"!=e.type&&"mouseenter"!=e.type&&"mouseleave"!=e.type||(x=e.clientX,y=e.clientY),{x:x,y:y}},f=(t,o,n=!1,r=null)=>{let l="y"===o;var e=v(t);let i,a,c,s=(c=n?(i=r,a=l?.9*window.innerHeight:.5*window.innerWidth,l?.1*window.innerHeight:.1*window.innerWidth):(i=l?document.querySelector("#terminal"):document.querySelector("#terminal-fast-option"),a=l?.8*window.innerHeight:.5*window.innerWidth,l?.2*window.innerHeight:.1*window.innerWidth),i.getBoundingClientRect()[l?"height":"width"]),d=e[o];e=e=>{["touchstart","touchmove","touchend","touchcancel"].includes(t.type)||e.preventDefault();e=v(e),document.body.classList.add(l?"row-resize":"col-resize"),document.body.classList.add("no-select"),e=s-(e[o]-d);e>c&&eS(o,n),window.ontouchend=()=>S(o,n)},S=(e,t=!1)=>{e="y"===e;document.body.classList.remove(e?"row-resize":"col-resize"),document.body.classList.remove("no-select"),window.onmousemove=null,window.ontouchmove=null,window.onmouseup=null,window.ontouchend=null,t||localStorage.setItem(e?"terminalHeight":"terminalOptWidth",e?terminal.parentElement.parentElement.getBoundingClientRect().height:document.querySelector("#terminal-fast-option").getBoundingClientRect().width)},b=(o,n=!1,r)=>{d.windows.forEach((e,t)=>d.windows_value[t]=e.value),l.compress(JSON.stringify(d.windows_value),1,(e,t)=>{if(t)alert("Failed to compress data: "+t);else{let t=new FileReader;t.onload=function(){var e=t.result.substr(t.result.indexOf(",")+1);n?r(e):(e="https://"+s.url.host+s.url.pathname+"#"+e,e="markdown"===o?"[paste]("+e+")":e,"true"==localStorage.getItem(s.localStorage.autoExecuteFlag)&&(e+="?execute=true"),navigator.clipboard.writeText(e),document.querySelector(".nav-text-offer input").value=e,document.querySelector("body > footer").classList.add("text-offer"))},t.readAsDataURL(new Blob([new Uint8Array(e)]))}})};let L;const E=()=>{window.addEventListener("keydown",e=>{((e.metaKey||e.ctrlKey||e.altKey)&&"t"==e.key||(e.metaKey||e.ctrlKey||e.altKey)&&84==e.keyCode||(e.metaKey||e.ctrlKey||e.altKey)&&84==e.which)&&(e.preventDefault(),L())});const e=e=>{ThemeArr.includes(e)||(e=ThemeArr[0]),document.body.classList.remove(...ThemeArr),document.body.classList.add(e),localStorage.setItem("theme",e)};document.querySelector(".invert-color").addEventListener("click",()=>{document.body.classList.contains("dark")?e("light"):e("dark")}),0==d.current&&h(),document.querySelector("#add-w").addEventListener("click",h),document.querySelector("#remove-w").addEventListener("click",w),document.querySelectorAll(".generate-url").forEach(t=>{t.addEventListener("click",()=>{var e=t.getAttribute("data-type");b(e)})}),document.querySelector("a.cancel-url").addEventListener("click",g),document.querySelector("a.copy-url").addEventListener("click",()=>{document.querySelector(".nav-text-offer input").select(),document.execCommand("copy"),g()});const t=()=>{document.querySelector(".container-modal").classList.remove("show"),window.onkeydown=null},n=(document.querySelector(".container-modal .bg-event").addEventListener("click",t),["confirm-modal","cancel-modal"].forEach(e=>document.getElementById(e).addEventListener("click",t)),L=(e="toggle")=>{switch(e){case"open":document.querySelector("#terminal").classList.add("open"),o.focus(),document.querySelector(".hidden-tab").classList.add("terminal-opened");break;case"close":document.querySelector("#terminal").classList.remove("open"),document.querySelector(".hidden-tab").classList.remove("terminal-opened");break;case"toggle":document.querySelector("#terminal").classList.toggle("open"),o.focus(),document.querySelector(".hidden-tab").classList.toggle("terminal-opened")}localStorage.setItem("terminal",!!document.querySelector("#terminal").classList.contains("open"))},(e=null)=>{a.historyPosition=0;var t=document.createElement("div");t.classList.add("terminal-input"),t.innerHTML=document.querySelector("#terminal-main-input").innerHTML,i.appendChild(t),t.removeChild(t.querySelector("button")),c.exec(e??r.innerText).then(e=>{var t;a.position=0,r.innerHTML="",(!e[0]||0L("open")),document.querySelector("#close-t").addEventListener("click",()=>L("close")),o.addEventListener("focus",()=>{o.scrollTop=o.scrollHeight,l.classList.add("blink")}),o.addEventListener("blur",()=>l.classList.remove("blink")),o.addEventListener("keydown",e=>{var t;e.ctrlKey||e.metaKey||e.altKey||(e.preventDefault(),1==e.key.length&&(a.position+=1,r.innerText=r.innerText.slice(0,a.position-1)+e.key+r.innerText.slice(a.position-1))),"ArrowLeft"==e.key&&(a.position-=0=t.length?0:1:a.historyPosition<=0?0:-1,t=t[t.length-a.historyPosition],r.innerText=t||"",a.position=r.innerText.length),"v"==e.key&&(e.ctrlKey||e.metaKey)&&navigator.clipboard.readText().then(e=>{r.innerText=r.innerText.slice(0,a.position-1)+e+r.innerText.slice(a.position-1),a.position+=e.length}),"Backspace"!=e.key&&"Delete"!=e.key||(r.innerText=r.innerText.slice(0,a.position-1)+r.innerText.slice(a.position),a.position-=0==a.position?0:1),"Enter"!=e.key&&"Return"!=e.key&&"NumpadEnter"!=e.key||n()}),document.querySelectorAll(".terminal-option").forEach(o=>{o.addEventListener("click",()=>{return e=o.getAttribute("data-option"),t={add:["window add 1",1],remove:["window remove 1",1],exit:["exit",1],clear:["cls",1],help:["help",1],reset:["config reset",1],import:["config set JSON",0],export:["config get",1]},r.innerHTML=t[e][0],a.position=r.innerText.length,void(t[e][1]&&n());var e,t})}),["mousedown","touchstart"].forEach(e=>{document.querySelector("#scroll-height.terminal").addEventListener(e,e=>f(e,"y")),document.querySelector("#scroll-width.terminal-opt").addEventListener(e,e=>f(e,"x"))}),new Terminal({terminal:{main:o,input:r,output:i,caret:l,toggleFnc:L,config:a},window:{add:h,remove:w,config:d,getLang:u},theme:{list:ThemeArr,set:e},root:s}));if("execute"in s._get&&"true"==s._get.execute){document.querySelector(".modal-text").innerHTML="The auto-execute is enabled. This action could be dangerous.

Do you want to execute it?",document.querySelector(".container-modal .code").innerHTML="",document.querySelector(".container-modal .code").appendChild(d.codeWindow[0].parentElement.cloneNode(!0)),document.querySelector(".container-modal").classList.add("show");let t=()=>{L("open"),n("run 0")};document.getElementById("confirm-modal").onclick=t,window.onkeydown=e=>{"Enter"!=e.key&&13!=e.keyCode&&"Enter"!=e.code&&13!=e.which||(t(),document.querySelector(".container-modal").classList.remove("show"),window.onkeydown=null)}}};(fn=async()=>{var e=()=>{if((r??"").split("&").forEach(e=>{e=e.split("=");s._get[e[0]]=e[1]}),E(),localStorage.getItem("theme")&&document.body.classList.add(localStorage.getItem("theme")),localStorage.getItem("customTheme")){var e,t=JSON.parse(localStorage.getItem("customTheme"));for(e in t)document.body.style.setProperty(e,t[e])}var o,n;localStorage.getItem("terminalHeight")&&(n=parseFloat(localStorage.getItem("terminalHeight")),o=.8*window.innerHeight,.2*window.innerHeight{e=await(await fetch("data:application/octet-stream;base64,"+e)).blob();let t=new FileReader;t.onload=function(){var e=Array.from(new Uint8Array(t.result));l.decompress(e,function(e,t){t&&alert("Failed to decompress data: "+t);try{var o=JSON.parse(e);"object"==typeof o&&o.forEach((e,t)=>{h(),d.windows[t].value=e,a(d.windows[t])})}catch(t){alert("Failed to writing data: "+t)}n()})},t.readAsArrayBuffer(e)})(s.base64,e)})()}); \ No newline at end of file +let setTabSize=t=>{document.querySelectorAll(".textarea div pre code").forEach(e=>{e.style.tabSize=""+(0!=t?t:4),e.style.MozTabSize=""+(0!=t?t:4)}),tabSize=t},tabSize=4,tabRegex=/\t/g;const ThemeArr=["light","dark","funky","twilight","solarized","night","zll"];let THEME_={importTheme:e=>{var t=new FileReader;const r=document.querySelector("#terminal-main-history");t.readAsText(e.files[0],"UTF-8"),t.onload=e=>{let t=e.target.result,o="";try{for(var n in t=JSON.parse(t),document.body.removeAttribute("class"),document.body.classList.add(t.class),localStorage.setItem("theme",t.class),delete t.class,t)document.body.style.setProperty(n,t[n]);localStorage.setItem("customTheme",JSON.stringify(t))}catch(e){o="Error: Cannot parse JSON"}e=document.createElement("div");e.classList.add("terminal-output"),e.innerHTML=o,r.appendChild(e),terminal.scrollTop=terminal.scrollHeight},t.onerror=()=>{var e=document.createElement("div");e.classList.add("terminal-output"),e.innerHTML="Error: Cannot read file content",r.appendChild(e),terminal.scrollTop=terminal.scrollHeight}},exportTheme:()=>{var e,t={"--theme-bg-color":"","--theme-primary-color":"","--theme-secondary-color":"","--theme-color-muted":"","--theme-text-color":"","--theme-extra-color":"","--theme-border-color":"","--theme-caret-color":"","--theme-alert-color":"","--theme-cristal-color":"","--theme-footer-color":""};for(e in t)t[e]=document.body.style.getPropertyValue(e);t.class=document.body.classList[0],saveToFile("PasteCodeTheme.json",JSON.stringify(t))}},TMP_ID=0;function Out(e){document.querySelector("#"+TMP_ID).innerHTML+=e+"
"}function saveToFile(e,t){var o;"saveAs"in window?(o=new Blob([t],{type:"text/plain;charset=utf-8"}),saveAs(o,e)):((o=document.createElement("a")).setAttribute("href","data:text/plain;charset=utf-8,"+encodeURIComponent(t)),o.setAttribute("download",e),o.style.display="none",document.body.appendChild(o),o.click(),document.body.removeChild(o))}window.addEventListener("load",()=>{var l=new LZMA("./js/src/lzma_worker.js");const s={url:document.location,base64:"undefined",_get:{},localStorage:{fileMemory:"paste-code",autoExecuteFlag:"paste-code-auto-execute"}},d={parent:document.querySelector(".textarea"),max:4,min:1,label:"Window",current:0,focus:0,visible:0,windows:[],codeWindow:[],windows_value:[],lineActive:[]};let a=e=>{document.querySelector(".alert-modal").classList.add("active"),document.querySelector(".alert-modal-text").textContent=e,setTimeout(function(){document.querySelector(".alert-modal").classList.remove("active")},5e3)};const u=e=>{var e=e.value.split("\n")[0];return!!e.match(/[\!|\?]/)&&((e=(e=e.split(/[\!|\?]/))[e.length-1].toLowerCase().trim()).includes("--\x3e")?e.replace("--\x3e","").trim():e)},c=e=>{var t=d.windows.indexOf(e),o=d.codeWindow[t],n=e.value.split("\n"),r=u(e);r&&o.setAttribute("class","language-"+r),tabRegex.test(e.value)&&(e.value=e.value.replaceAll(tabRegex," ".repeat(tabSize))),o.innerHTML=e.value.replaceAll(new RegExp("&","g"),"&").replaceAll(new RegExp("<","g"),"<"),Prism.highlightElement(o),document.querySelector(".w-"+t).style.setProperty("--padd",100<=n.length?1e3<=n.length?1e4<=n.length?"55px":"45px":"35px":"25px"),e.parentElement.querySelector(".line-numbers-rows").innerHTML=Array(n.length).fill("").join(""),e===document.activeElement&&m(e)},m=(e,t=-1)=>{var o=e.value.substring(0,e.selectionStart).split("\n").length,n=e.parentElement.querySelector(".line-numbers-rows");o+t{e=e.parentElement.querySelector(".line-numbers-rows");Array.from(e.children).forEach(e=>{e.classList.remove("current")})};function h(){var e;d.parent.classList.remove("odd-3"),d.parent.classList.remove("odd-4"),3==d.visible&&(3==d.current?d.parent.classList.add("odd-3"):(!(e=["none"==d.windows[2].parentElement.style.display,"none"==d.windows[3].parentElement.style.display])[0]&&e[1]&&d.parent.classList.add("odd-3"),d.parent.classList.add("odd-4")))}const w=()=>{if(d.current{var e=n.classList[0].replace("w-","");d.focus=e});var t;window.addEventListener("dblclick",function(e){t=setTimeout(function(){t=null},400)}),window.addEventListener("click",function(e){if(t&&(clearTimeout(t),t=null,1document.querySelector(".hidden-tab").classList.remove("demo"),1e3),n.style.display="none",d.visible--,h();let t=document.createElement("a");t.onclick=e=>{n.style.display="block",t.remove(),d.focus=n.classList[0].replace("w-",""),d.visible++,h()};let o;try{o=n.querySelector("pre").classList[0].replace("language-","")}catch(e){o=""}t.innerHTML=`[${0c(i)),i.addEventListener("mouseup",()=>m(i)),("ontouchstart"in window||0m(i)),i.addEventListener("scroll",()=>{r.scrollTo(i.scrollLeft,i.scrollTop),l.scrollTo(i.scrollLeft,i.scrollTop)}),i.addEventListener("keydown",e=>{var t=(e,t)=>{var o=i.selectionStart;i.value=i.value.substring(0,o)+e+i.value.substring(i.selectionEnd),i.selectionStart=i.selectionEnd=o+t,c(i)},o=("Tab"!=e.key&&9!=e.keyCode&&9!=e.which||(e.preventDefault(),t(" ".repeat(tabSize),tabSize)),{"(":")","[":"]","{":"}",'"':'"',"'":"'","`":"`"}),o=(e.key in o&&t(o[e.key],0),(r.classList[0]??"").replace("language-","").toUpperCase());"<"!=e.key||"HTML"!=o&&"XML"!=o||t(">",0),"ArrowUp"!=e.key&&38!=e.keyCode&&38!=e.which||m(i,delay=-2),"ArrowDown"!=e.key&&40!=e.keyCode&&40!=e.which||m(i,delay=0),(e.altKey&&"l"==e.key||e.altKey&&76==e.keyCode||e.altKey&&76==e.which)&&(e.preventDefault(),o=i.value.substring(0,i.selectionStart).lastIndexOf("\n")+1,t=i.value.substring(i.selectionEnd).indexOf("\n")+i.selectionEnd,t+=t==i.value.length-1?1:0,i.setSelectionRange(o,t)),e.ctrlKey&&"s"===e.key&&(e.preventDefault(),L("url",!0,e=>{try{localStorage.setItem(s.localStorage.fileMemory,e),a("Content saved successfully")}catch(e){a("Error saving")}}))}),i.addEventListener("keyup",e=>{"Enter"!=e.key&&13!=e.keyCode&&13!=e.which&&"ArrowUp"!=e.key&&38!=e.keyCode&&38!=e.which&&"ArrowDown"!=e.key&&40!=e.keyCode&&40!=e.which&&"ArrowLeft"!=e.key&&37!=e.keyCode&&37!=e.which&&"ArrowRight"!=e.key&&39!=e.keyCode&&39!=e.which||m(i)}),i.addEventListener("focusout",()=>{p(i)}),r.appendChild(o),n.appendChild(l),n.appendChild(i),n.appendChild(r),d.parent.appendChild(n),d.windows.push(i),d.current++,d.visible++,d.parent.classList.remove("odd-3"),d.parent.classList.remove("odd-4"),h(),2!=d.current&&4!=d.current||((e=document.createElement("div")).classList.add("LR"),e.classList.add("LR-1"),n.appendChild(e)),2!=d.current&&3!=d.current&&4!=d.current||((e=document.createElement("div")).classList.add("TB"),e.classList.add("TB-"+(d.current-2)),n.appendChild(e)),d.codeWindow.push(o),n.classList.add("w-"+(d.current-1)),!0}0document.querySelector(".hidden-tab").classList.remove("demo"),1e3))},g=()=>{if(d.current>d.min&&d.visible>d.min){for(;;){if("none"!=d.windows[d.focus].parentElement.style.display)break;0==d.focus?d.focus=d.current-1:d.focus--}const t=()=>{d.parent.removeChild(d.windows[d.focus].parentElement),d.windows=d.windows.filter((e,t)=>t!=d.focus),d.codeWindow=d.codeWindow.filter((e,t)=>t!=d.focus),d.current--,d.visible--,h(),d.windows.forEach((e,t)=>{e.parentElement.classList.remove(...e.parentElement.classList),e.parentElement.classList.add("w-"+t)}),document.querySelector(".hidden-tab").classList.add("demo"),setTimeout(()=>document.querySelector(".hidden-tab").classList.remove("demo"),1e3)};document.querySelector(".modal-text").textContent="Are you sure you want to remove the window ["+d.focus+"]?",document.querySelector(".container-modal .code").innerHTML="",document.querySelector(".container-modal .code").appendChild(d.codeWindow[d.focus].parentElement.cloneNode(!0)),document.querySelector(".container-modal").classList.add("show"),document.getElementById("confirm-modal").onclick=t,window.onkeydown=e=>{"Enter"!=e.key&&13!=e.keyCode&&"Enter"!=e.code&&13!=e.which||(t(),document.querySelector(".container-modal").classList.remove("show"),window.onkeydown=null)}}},v=()=>document.querySelector("body > footer").classList.remove("text-offer"),f=e=>{var t;return"touchstart"==e.type||"touchmove"==e.type||"touchend"==e.type||"touchcancel"==e.type?(t=(t=void 0===e.originalEvent?e:e.originalEvent).touches[0]||t.changedTouches[0],x=t.pageX,y=t.pageY):"mousedown"!=e.type&&"mouseup"!=e.type&&"mousemove"!=e.type&&"mouseover"!=e.type&&"mouseout"!=e.type&&"mouseenter"!=e.type&&"mouseleave"!=e.type||(x=e.clientX,y=e.clientY),{x:x,y:y}},S=(t,o,n=!1,r=null)=>{let l="y"===o;var e=f(t);let i,a,c,s=(c=n?(i=r,a=l?.9*window.innerHeight:.5*window.innerWidth,l?.1*window.innerHeight:.1*window.innerWidth):(i=l?document.querySelector("#terminal"):document.querySelector("#terminal-fast-option"),a=l?.8*window.innerHeight:.5*window.innerWidth,l?.2*window.innerHeight:.1*window.innerWidth),i.getBoundingClientRect()[l?"height":"width"]),d=e[o];e=e=>{["touchstart","touchmove","touchend","touchcancel"].includes(t.type)||e.preventDefault();e=f(e),document.body.classList.add(l?"row-resize":"col-resize"),document.body.classList.add("no-select"),e=s-(e[o]-d);e>c&&eb(o,n),window.ontouchend=()=>b(o,n)},b=(e,t=!1)=>{e="y"===e;document.body.classList.remove(e?"row-resize":"col-resize"),document.body.classList.remove("no-select"),window.onmousemove=null,window.ontouchmove=null,window.onmouseup=null,window.ontouchend=null,t||localStorage.setItem(e?"terminalHeight":"terminalOptWidth",e?terminal.parentElement.parentElement.getBoundingClientRect().height:document.querySelector("#terminal-fast-option").getBoundingClientRect().width)},L=(o,n=!1,r)=>{d.windows.forEach((e,t)=>d.windows_value[t]=e.value),l.compress(JSON.stringify(d.windows_value),1,(e,t)=>{if(t)alert("Failed to compress data: "+t);else{let t=new FileReader;t.onload=function(){var e=t.result.substr(t.result.indexOf(",")+1);n?r(e):(e="https://"+s.url.host+s.url.pathname+"#"+e,e="markdown"===o?"[paste]("+e+")":e,"true"==localStorage.getItem(s.localStorage.autoExecuteFlag)&&(e+="?execute=true"),navigator.clipboard.writeText(e),document.querySelector(".nav-text-offer input").value=e,document.querySelector("body > footer").classList.add("text-offer"))},t.readAsDataURL(new Blob([new Uint8Array(e)]))}})};let E;const i=()=>{window.addEventListener("keydown",e=>{((e.metaKey||e.ctrlKey||e.altKey)&&"t"==e.key||(e.metaKey||e.ctrlKey||e.altKey)&&84==e.keyCode||(e.metaKey||e.ctrlKey||e.altKey)&&84==e.which)&&(e.preventDefault(),E())});const e=e=>{ThemeArr.includes(e)||(e=ThemeArr[0]),document.body.classList.remove(...ThemeArr),document.body.classList.add(e),localStorage.setItem("theme",e)};document.querySelector(".invert-color").addEventListener("click",()=>{document.body.classList.contains("dark")?e("light"):e("dark")}),0==d.current&&w(),document.querySelector("#add-w").addEventListener("click",w),document.querySelector("#remove-w").addEventListener("click",g),document.querySelectorAll(".generate-url").forEach(t=>{t.addEventListener("click",()=>{var e=t.getAttribute("data-type");L(e)})}),document.querySelector("a.cancel-url").addEventListener("click",v),document.querySelector("a.copy-url").addEventListener("click",()=>{document.querySelector(".nav-text-offer input").select(),document.execCommand("copy"),v()});const t=()=>{document.querySelector(".container-modal").classList.remove("show"),window.onkeydown=null},n=(document.querySelector(".container-modal .bg-event").addEventListener("click",t),["confirm-modal","cancel-modal"].forEach(e=>document.getElementById(e).addEventListener("click",t)),E=(e="toggle")=>{switch(e){case"open":document.querySelector("#terminal").classList.add("open"),o.focus(),document.querySelector(".hidden-tab").classList.add("terminal-opened");break;case"close":document.querySelector("#terminal").classList.remove("open"),document.querySelector(".hidden-tab").classList.remove("terminal-opened");break;case"toggle":document.querySelector("#terminal").classList.toggle("open"),o.focus(),document.querySelector(".hidden-tab").classList.toggle("terminal-opened")}localStorage.setItem("terminal",!!document.querySelector("#terminal").classList.contains("open"))},(e=null)=>{a.historyPosition=0;var t=document.createElement("div");t.classList.add("terminal-input"),t.innerHTML=document.querySelector("#terminal-main-input").innerHTML,i.appendChild(t),t.removeChild(t.querySelector("button")),c.exec(e??r.innerText).then(e=>{var t;a.position=0,r.innerHTML="",(!e[0]||0E("open")),document.querySelector("#close-t").addEventListener("click",()=>E("close")),o.addEventListener("focus",()=>{o.scrollTop=o.scrollHeight,l.classList.add("blink")}),o.addEventListener("blur",()=>l.classList.remove("blink")),o.addEventListener("keydown",e=>{var t;e.ctrlKey||e.metaKey||e.altKey||(e.preventDefault(),1==e.key.length&&(a.position+=1,r.innerText=r.innerText.slice(0,a.position-1)+e.key+r.innerText.slice(a.position-1))),"ArrowLeft"==e.key&&(a.position-=0=t.length?0:1:a.historyPosition<=0?0:-1,t=t[t.length-a.historyPosition],r.innerText=t||"",a.position=r.innerText.length),"v"==e.key&&(e.ctrlKey||e.metaKey)&&navigator.clipboard.readText().then(e=>{r.innerText=r.innerText.slice(0,a.position-1)+e+r.innerText.slice(a.position-1),a.position+=e.length}),"Backspace"!=e.key&&"Delete"!=e.key||(r.innerText=r.innerText.slice(0,a.position-1)+r.innerText.slice(a.position),a.position-=0==a.position?0:1),"Enter"!=e.key&&"Return"!=e.key&&"NumpadEnter"!=e.key||n()}),document.querySelectorAll(".terminal-option").forEach(o=>{o.addEventListener("click",()=>{return e=o.getAttribute("data-option"),t={add:["window add 1",1],remove:["window remove 1",1],exit:["exit",1],clear:["cls",1],help:["help",1],reset:["config reset",1],import:["config set JSON",0],export:["config get",1]},r.innerHTML=t[e][0],a.position=r.innerText.length,void(t[e][1]&&n());var e,t})}),["mousedown","touchstart"].forEach(e=>{document.querySelector("#scroll-height.terminal").addEventListener(e,e=>S(e,"y")),document.querySelector("#scroll-width.terminal-opt").addEventListener(e,e=>S(e,"x"))}),new Terminal({terminal:{main:o,input:r,output:i,caret:l,toggleFnc:E,config:a},window:{add:w,remove:g,config:d,getLang:u},theme:{list:ThemeArr,set:e},root:s}));if("execute"in s._get&&"true"==s._get.execute){document.querySelector(".modal-text").innerHTML="The auto-execute is enabled. This action could be dangerous.

Do you want to execute it?",document.querySelector(".container-modal .code").innerHTML="",document.querySelector(".container-modal .code").appendChild(d.codeWindow[0].parentElement.cloneNode(!0)),document.querySelector(".container-modal").classList.add("show");let t=()=>{E("open"),n("run 0")};document.getElementById("confirm-modal").onclick=t,window.onkeydown=e=>{"Enter"!=e.key&&13!=e.keyCode&&"Enter"!=e.code&&13!=e.which||(t(),document.querySelector(".container-modal").classList.remove("show"),window.onkeydown=null)}}};(fn=async()=>{var e=()=>{if((r??"").split("&").forEach(e=>{e=e.split("=");s._get[e[0]]=e[1]}),i(),localStorage.getItem("theme")&&document.body.classList.add(localStorage.getItem("theme")),localStorage.getItem("customTheme")){var e,t=JSON.parse(localStorage.getItem("customTheme"));for(e in t)document.body.style.setProperty(e,t[e])}var o,n;localStorage.getItem("terminalHeight")&&(n=parseFloat(localStorage.getItem("terminalHeight")),o=.8*window.innerHeight,.2*window.innerHeight{e=await(await fetch("data:application/octet-stream;base64,"+e)).blob();let t=new FileReader;t.onload=function(){var e=Array.from(new Uint8Array(t.result));l.decompress(e,function(e,t){t&&alert("Failed to decompress data: "+t);try{var o=JSON.parse(e);"object"==typeof o&&o.forEach((e,t)=>{w(),d.windows[t].value=e,c(d.windows[t])})}catch(t){alert("Failed to writing data: "+t)}n()})},t.readAsArrayBuffer(e)})(s.base64,e)})()}); \ No newline at end of file diff --git a/js/src/script.js b/js/src/script.js index f04f1b9..d49c832 100644 --- a/js/src/script.js +++ b/js/src/script.js @@ -344,35 +344,49 @@ window.addEventListener('load', () => { WINDOW_CONFIG.focus = index; }); - windowParent.addEventListener('dblclick', () => { - // Get focus and close window - if (WINDOW_CONFIG.visible > 1) { - document.querySelector('.hidden-tab').classList.add('demo'); - setTimeout(() => document.querySelector('.hidden-tab').classList.remove('demo'), 1000); - windowParent.style.display = 'none'; - WINDOW_CONFIG.visible--; - - // Odd - visibilityFullSpan(); - - let a = document.createElement('a'); - a.onclick = (e) => { - windowParent.style.display = 'block'; - a.remove(); - - WINDOW_CONFIG.focus = windowParent.classList[0].replace('w-', ''); - WINDOW_CONFIG.visible++; - - visibilityFullSpan(true); - } - let lang; - try { - lang = windowParent.querySelector('pre').classList[0].replace('language-', ''); - } catch(e) { - lang = ''; + var timer, // timer required to reset + timeout = 400; // timer reset in ms + + window.addEventListener("dblclick", function (evt) { + timer = setTimeout(function () { + timer = null; + }, timeout); + }); + window.addEventListener("click", function (evt) { + if (timer) { + clearTimeout(timer); + timer = null; + + // Triple click + // Get focus and close window + if (WINDOW_CONFIG.visible > 1) { + document.querySelector('.hidden-tab').classList.add('demo'); + setTimeout(() => document.querySelector('.hidden-tab').classList.remove('demo'), 1000); + windowParent.style.display = 'none'; + WINDOW_CONFIG.visible--; + + // Odd + visibilityFullSpan(); + + let a = document.createElement('a'); + a.onclick = (e) => { + windowParent.style.display = 'block'; + a.remove(); + + WINDOW_CONFIG.focus = windowParent.classList[0].replace('w-', ''); + WINDOW_CONFIG.visible++; + + visibilityFullSpan(true); + } + let lang; + try { + lang = windowParent.querySelector('pre').classList[0].replace('language-', ''); + } catch(e) { + lang = ''; + } + a.innerHTML = `[${(lang.length > 0 && lang != 'none') ? `${lang.toUpperCase()}-${WINDOW_CONFIG.focus}` : WINDOW_CONFIG.focus}]` + document.querySelector('.hidden-tab').appendChild(a); } - a.innerHTML = `[${(lang.length > 0 && lang != 'none') ? `${lang.toUpperCase()}-${WINDOW_CONFIG.focus}` : WINDOW_CONFIG.focus}]` - document.querySelector('.hidden-tab').appendChild(a); } }); //