Skip to content

Instantly share code, notes, and snippets.

@jxpsert
Created May 20, 2022 16:44
Show Gist options
  • Select an option

  • Save jxpsert/863d817afd295fb4cad873dfd2e2b83a to your computer and use it in GitHub Desktop.

Select an option

Save jxpsert/863d817afd295fb4cad873dfd2e2b83a to your computer and use it in GitHub Desktop.
$(".countdownclock").each(function (i, e) {
const $this = $(this);
const countdown = $this;
let button = e.parentElement.parentElement.parentElement.childNodes[2].childNodes[0];
console.log(button);
// console.log(button.childNodes);
countdown.text(turnTot(countdown.attr("data-time")));
let changet = setInterval(function () {
let newt = countdown.attr("data-time") - 1;
countdown.attr("data-time", newt);
countdown.text(turnTot(newt));
if (countdown.attr("data-time") <= 0) {
clearInterval(changet);
countdown.text("0s");
button.href = "";
button.innerText = "Verlopen";
button.classList.add("disabled");
}
}, 1000);
});
function turnTot(t) {
let days = Math.floor(t / 24 / 3600);
let hours = Math.floor((t / 3600) % 24);
let minutes = Math.floor((t % 3600) / 60);
let seconds = Math.floor((t % 3600) % 60);
let newt = days + "d " + (hours + "u ") + minutes + "m " + seconds + "s";
return String(newt);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment