Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let cooldownActive = false;
- function startCooldown(duration) {
- if (!cooldownActive) {
- cooldownActive = true;
- const endTime = Date.now() + duration;
- const timerElement = document.createElement('div');
- timerElement.style.position = 'fixed';
- timerElement.style.top = '10px';
- timerElement.style.left = '10px';
- timerElement.style.backgroundColor = 'black';
- timerElement.style.color = 'white';
- timerElement.style.padding = '10px';
- document.body.appendChild(timerElement);
- const timerInterval = setInterval(() => {
- const timeLeft = Math.max(Math.ceil((endTime - Date.now()) / 1000), 0);
- timerElement.textContent = `Cooldown: ${timeLeft} second${timeLeft === 1 ? '' : 's'}`;
- if (timeLeft <= 0) {
- clearInterval(timerInterval);
- cooldownActive = false;
- timerElement.remove();
- }
- }, 1000);
- }
- }
- startCooldown(5000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement