BirdNET-stream/www/assets/utils/date.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-08-16 19:28:19 +02:00
let date_input;
let endpoint;
2022-08-16 07:05:49 +02:00
2022-08-16 19:28:19 +02:00
try {
date_input = document.querySelector(".date-selector input[type='date']");
let next_date_button = document.getElementsByClassName("next-date-button")[0];
let previous_date_button = document.getElementsByClassName("previous-date-button")[0];
endpoint = document.querySelector(".date-selector a").href.split("/")[3];
next_date_button.addEventListener("click", next_date);
previous_date_button.addEventListener("click", previous_date);
} catch {
console.debug("no date input found");
}
2022-08-16 07:05:49 +02:00
function next_date() {
let date = new Date(date_input.value);
date.setDate(date.getDate() + 1);
date_input.value = date.toISOString().split('T')[0];
update_date_link();
}
function previous_date() {
let date = new Date(date_input.value);
date.setDate(date.getDate() - 1);
date_input.value = date.toISOString().split('T')[0];
update_date_link();
}
function update_date_link() {
let date = new Date(date_input.value);
let date_link = document.querySelector(".date-selector a");
2022-08-16 19:28:19 +02:00
date_link.href = `/${endpoint}/${date.toISOString().split('T')[0]}/`;
2022-08-16 07:05:49 +02:00
}