1 line
1.1 KiB
JavaScript
1 line
1.1 KiB
JavaScript
|
|
(()=>{(function(){const e=document.getElementById("code-copy").innerHTML,n=document.getElementById("code-copy-done").innerHTML;function s(t){const n=document.createElement("button");n.className="right-1 top-1 absolute",n.type="button",n.innerHTML=e,n.addEventListener("click",()=>o(n,t)),t.insertBefore(n,t.firstChild)}document.querySelectorAll(".highlight").forEach(e=>s(e));async function o(s,o){let i=o.querySelector("code").textContent;o.querySelector("table")&&(i=o.querySelector("td:last-child code").textContent);let a=!0;try{var r=await navigator.permissions.query({name:"clipboard-write"});r.state!="granted"&&r.state!="prompt"&&(a=!1)}catch{}try{a?await navigator.clipboard.writeText(i):t(i,o)}catch{t(i,o)}finally{s.blur(),s.innerHTML=n,setTimeout(function(){s.innerHTML=e},2e3)}}function t(e,t){const n=document.createElement("textArea");n.contentEditable="true",n.readOnly="false",n.className="copyable-text-area",n.value=e,t.insertBefore(n,t.firstChild);const s=document.createRange();s.selectNodeContents(n);const o=window.getSelection();o.removeAllRanges(),o.addRange(s),n.setSelectionRange(0,999999),document.execCommand("copy"),t.removeChild(n)}})()})()
|