diff options
Diffstat (limited to 'src/main.js')
-rw-r--r-- | src/main.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/main.js b/src/main.js index 3ca7d30..44eab32 100644 --- a/src/main.js +++ b/src/main.js @@ -9,6 +9,8 @@ document.querySelectorAll(".toggle-vision").forEach((button) => { }); document.querySelectorAll(".inner .cs-btn").forEach((button) => { + let timeout = null; + button.addEventListener("click", function () { const codeElement = this.closest(".inner").querySelector("code"); const codeToCopy = codeElement.textContent; @@ -16,7 +18,12 @@ document.querySelectorAll(".inner .cs-btn").forEach((button) => { .writeText(codeToCopy) .then(() => { this.textContent = "Copied!"; - setTimeout(() => { + + if (timeout !== null) { + clearTimeout(timeout); + } + + timeout = setTimeout(() => { this.textContent = "Copy"; }, 2000); }) |