From e112d9461e05f44abcde621bcbcb61fb24d06caa Mon Sep 17 00:00:00 2001 From: igorechek06 Date: Thu, 22 Aug 2024 01:01:32 +0900 Subject: Change site stylistic --- script.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'script.js') diff --git a/script.js b/script.js index 2f428b9..368f712 100644 --- a/script.js +++ b/script.js @@ -1,18 +1,17 @@ -function copy(text, tooltip) { - return () => { - navigator.clipboard.writeText(text); - tooltip.textContent = " []"; - setTimeout(() => (tooltip.textContent = " []"), 1000); - }; -} - window.onload = () => { document.querySelectorAll(".copy").forEach((element) => { const tooltip = document.createElement("span"); - tooltip.classList.add("copy-button"); - tooltip.textContent = " []"; - - element.onclick = copy(element.attributes["copy-text"]?.value, tooltip); + tooltip.textContent = " [copy]"; element.appendChild(tooltip); + + element.addEventListener("click", () => { + try { + navigator.clipboard.writeText(element.attributes["copy-text"]?.value); + tooltip.textContent = " [copied]"; + } catch (error) { + tooltip.textContent = " [error]"; + } + setTimeout(() => (tooltip.textContent = " [copy]"), 1000); + }); }); }; -- cgit v1.2.3