|
|
| Line 1: |
Line 1: |
| /* Any JavaScript here will be loaded for all users on every page load. */ | | /* Any JavaScript here will be loaded for all users on every page load. */ |
|
| |
| $(function () {
| |
|
| |
| console.log("Copy button script loaded");
| |
|
| |
| function addButton(pre) {
| |
| if (pre.dataset.copyBtn) return;
| |
| pre.dataset.copyBtn = "1";
| |
|
| |
| const btn = document.createElement("button");
| |
| btn.innerText = "???? Copia";
| |
|
| |
| btn.style.position = "absolute";
| |
| btn.style.top = "4px";
| |
| btn.style.right = "4px";
| |
| btn.style.zIndex = "9999";
| |
| btn.style.fontSize = "12px";
| |
| btn.style.cursor = "pointer";
| |
|
| |
| const wrapper = pre.parentElement;
| |
| if (getComputedStyle(wrapper).position === "static") {
| |
| wrapper.style.position = "relative";
| |
| }
| |
|
| |
| btn.addEventListener("click", async () => {
| |
| try {
| |
| await navigator.clipboard.writeText(pre.innerText);
| |
| btn.innerText = "✔ Copiato";
| |
| setTimeout(() => btn.innerText = "???? Copia", 1200);
| |
| } catch (e) {
| |
| console.error(e);
| |
| alert("Clipboard non disponibile");
| |
| }
| |
| });
| |
|
| |
| wrapper.appendChild(btn);
| |
| }
| |
|
| |
| function scan() {
| |
| document.querySelectorAll("pre").forEach(addButton);
| |
| }
| |
|
| |
| scan();
| |
| });
| |