mirror of
https://github.com/RGBCube/GitHubWrapper
synced 2025-05-30 20:48:12 +00:00
Docs base plate?
This commit is contained in:
parent
359c483c66
commit
187f15f8bc
29 changed files with 3493 additions and 52 deletions
34
docs/_static/copy.js
vendored
Normal file
34
docs/_static/copy.js
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
const COPY = "content_copy";
|
||||
const COPIED = "done";
|
||||
|
||||
const copy = async (obj) => {
|
||||
// <span class="copy"><span class="material-icons">{{text}}</span></span>
|
||||
await navigator.clipboard.writeText(obj.children[1].innerText).then(
|
||||
() => {
|
||||
let icon = obj.children[0].children[0];
|
||||
icon.textContent = COPIED;
|
||||
setTimeout(() => (icon.textContent = COPY), 2500);
|
||||
},
|
||||
(r) => alert('Could not copy codeblock:\n' + r.toString())
|
||||
);
|
||||
};
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
let allCodeblocks = document.querySelectorAll("div[class='highlight']");
|
||||
|
||||
for (let codeblock of allCodeblocks) {
|
||||
codeblock.parentNode.className += " relative-copy";
|
||||
let copyEl = document.createElement("span");
|
||||
copyEl.addEventListener('click', () => copy(codeblock));
|
||||
copyEl.className = "copy";
|
||||
copyEl.setAttribute("aria-label", "Copy Code");
|
||||
copyEl.setAttribute("title", "Copy Code");
|
||||
|
||||
let copyIcon = document.createElement("span");
|
||||
copyIcon.className = "material-icons";
|
||||
copyIcon.textContent = COPY;
|
||||
copyEl.append(copyIcon);
|
||||
|
||||
codeblock.prepend(copyEl);
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue