From 9ef1cd3459729dcb6b63b088017a2dd1c9fe64c8 Mon Sep 17 00:00:00 2001 From: philipp Date: Mon, 20 Nov 2023 17:52:10 +0100 Subject: [PATCH] make years in stat changeable --- templates/stat.people.html.tera | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/templates/stat.people.html.tera b/templates/stat.people.html.tera index 7737082..1db20ad 100644 --- a/templates/stat.people.html.tera +++ b/templates/stat.people.html.tera @@ -6,7 +6,7 @@
-

Statistik

+

Statistik

@@ -46,6 +46,33 @@ const data = [ ] sessionStorage.setItem('userStats', JSON.stringify(data)); {% endif %} + +function getYearFromURL() { + var queryParams = new URLSearchParams(window.location.search); + return queryParams.get('year'); +} + +function populateYears() { + var select = document.getElementById('yearSelect'); + var currentYear = new Date().getFullYear(); + var selectedYear = getYearFromURL() || currentYear; + for (var year = 1977; year <= currentYear; year++) { + var option = document.createElement('option'); + option.value = option.textContent = year; + if (year == selectedYear) { + option.selected = true; + } + select.appendChild(option); + } +} + +function changeYear() { + var selectedYear = document.getElementById('yearSelect').value; + window.location.href = '?year=' + selectedYear; +} + +// Call this function when the page loads +populateYears();