mirror of
https://github.com/ekmas/cs16.css
synced 2026-04-10 21:53:24 +00:00
Clear existing "copy code" button timeout before creating another (#2)
This commit is contained in:
commit
ad77e30568
1 changed files with 8 additions and 1 deletions
|
|
@ -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);
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue