diff options
| author | Jieiku | 2023-08-17 12:16:18 -0700 |
|---|---|---|
| committer | Jieiku | 2023-08-17 12:16:18 -0700 |
| commit | 3e5d8a96e9eae21a799f327cd8a52adb891ebe66 (patch) | |
| tree | 6a1377b5207e4e3555f65ca162014468c64d6985 /static/codecopy.js | |
| parent | 1d9be812c25508a5dc36afb9e80669b668a47190 (diff) | |
| parent | 0983915e23793c28dd0bee149fd2ec05a7e96a94 (diff) | |
| download | abridge-3e5d8a96e9eae21a799f327cd8a52adb891ebe66.tar.gz abridge-3e5d8a96e9eae21a799f327cd8a52adb891ebe66.tar.bz2 abridge-3e5d8a96e9eae21a799f327cd8a52adb891ebe66.zip | |
resolve merge conflicts
Diffstat (limited to 'static/codecopy.js')
| -rw-r--r-- | static/codecopy.js | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/static/codecopy.js b/static/codecopy.js deleted file mode 100644 index c1f3a75..0000000 --- a/static/codecopy.js +++ /dev/null @@ -1,76 +0,0 @@ -// https://aaronluna.dev/blog/add-copy-button-to-code-blocks-hugo-chroma/ -// Further modified for Zola by Jieiku: https://github.com/Jieiku -(function() { - // create copy button - function ccb(highlightDiv) { - const button = document.createElement("button"); - button.className = "cc "; - button.type = "button"; - button.innerHTML = "Copy"; - button.addEventListener("click", () => - ccc(button, highlightDiv) - ); - - // addCopyButtonToDom - const wrapper = document.createElement("div"); - wrapper.className = "ccw"; - wrapper.appendChild(button); - highlightDiv.parentNode.insertBefore(wrapper, highlightDiv); - wrapper.appendChild(highlightDiv); - } - - // copy code clipboard - async function ccc(button, highlightDiv) { - //look for table, if so do it different - const { length } = highlightDiv.querySelectorAll("table"); - let codeToCopy = ""; - if (length > 0) { - const items = highlightDiv.querySelectorAll(":last-child > tr > td:last-child"); - items.forEach(item => { - codeToCopy = codeToCopy + item.innerText; - //console.log(codeToCopy); - }); - } else { - codeToCopy = highlightDiv.querySelector(":last-child > code").innerText; - } - try { - result = await navigator.permissions.query({ name: "clipboard-write" }); - if (result.state == "granted" || result.state == "prompt") { - await navigator.clipboard.writeText(codeToCopy); - } else { - cce(codeToCopy, highlightDiv);//copyCodeBlockExecCommand - } - } catch (_) { - cce(codeToCopy, highlightDiv);//copyCodeBlockExecCommand - } finally { - //codeWasCopied - //button.blur(); - button.innerHTML = "Copied"; - setTimeout(function () { - button.innerHTML = "Copy"; - }, 2000); - } - } - - //copyCodeBlockExecCommand - function cce(codeToCopy, highlightDiv) { - const textArea = document.createElement("textArea"); - textArea.contentEditable = "true"; - textArea.readOnly = "false"; - textArea.className = "copyable-text-area"; - textArea.value = codeToCopy; - highlightDiv.insertBefore(textArea, highlightDiv.firstChild); - const range = document.createRange(); - range.selectNodeContents(textArea); - const sel = window.getSelection(); - sel.removeAllRanges(); - sel.addRange(range); - textArea.setSelectionRange(0, 999999); - document.execCommand("copy"); - highlightDiv.removeChild(textArea); - } - - document - .querySelectorAll("pre") - .forEach((highlightDiv) => ccb(highlightDiv)); -})();
\ No newline at end of file |
