2023-05-25 06:44:05 +02:00
|
|
|
let changeDates = [];
|
|
|
|
let items = [];
|
|
|
|
|
|
|
|
async function load() {
|
|
|
|
const today = currentDate();
|
2023-05-25 13:32:53 +02:00
|
|
|
items = await loadItems();
|
2023-05-25 06:55:22 +02:00
|
|
|
items.sort((a, b) => {
|
|
|
|
if (a.store < b.store) {
|
|
|
|
return -1;
|
|
|
|
} else if (a.store > b.store) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a.name < b.name) {
|
|
|
|
return -1;
|
|
|
|
} else if (a.name > b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
2023-05-25 06:44:05 +02:00
|
|
|
|
|
|
|
document.querySelector("#date").innerText = "Preisänderungen am " + currentDate();
|
|
|
|
|
2023-05-28 21:26:49 +02:00
|
|
|
const filtersStore = document.querySelector("#filters-store");
|
|
|
|
filtersStore.innerHTML = STORE_KEYS.map(store => `<label><input id="${store}" type="checkbox" checked="true">${stores[store].name}</label>`).join(" ");
|
|
|
|
filtersStore.querySelectorAll("input").forEach(input => {
|
|
|
|
input.addEventListener("change", () => showResults(items, currentDate()));
|
|
|
|
});
|
2023-05-29 12:14:08 +02:00
|
|
|
document.querySelector("#filters-changes").querySelectorAll("input").forEach(input => {
|
|
|
|
input.addEventListener("change", () => showResults(items, currentDate()));
|
|
|
|
});
|
2023-05-29 12:31:14 +02:00
|
|
|
document.querySelector("#filter").addEventListener("input", () => showResults(items, currentDate()));
|
2023-05-28 21:26:49 +02:00
|
|
|
showResults(items, currentDate());
|
2023-05-25 06:44:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function showResults(items, today) {
|
|
|
|
const increases = document.querySelector("#increases").checked;
|
|
|
|
const decreases = document.querySelector("#decreases").checked;
|
2023-05-28 21:26:49 +02:00
|
|
|
const storeCheckboxes = STORE_KEYS.map(store => document.querySelector(`#${store}`));
|
|
|
|
const checkedStores = STORE_KEYS.filter((store, i) => storeCheckboxes[i].checked)
|
2023-05-25 13:32:53 +02:00
|
|
|
let changedItems = [];
|
2023-05-25 06:44:05 +02:00
|
|
|
for (item of items) {
|
|
|
|
if (item.priceHistory.length < 2) continue;
|
|
|
|
|
|
|
|
for (let i = 0; i < item.priceHistory.length; i++) {
|
2023-05-28 21:26:49 +02:00
|
|
|
if (!checkedStores.includes(item.store)) continue;
|
2023-05-25 06:55:22 +02:00
|
|
|
|
2023-05-25 06:44:05 +02:00
|
|
|
if (item.priceHistory[i].date == today && i + 1 < item.priceHistory.length) {
|
|
|
|
if (increases && (item.priceHistory[i].price > item.priceHistory[i + 1].price)) changedItems.push(item);
|
|
|
|
if (decreases && (item.priceHistory[i].price < item.priceHistory[i + 1].price)) changedItems.push(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-25 13:32:53 +02:00
|
|
|
const query = document.querySelector("#filter").value.trim();
|
2023-05-29 12:34:39 +02:00
|
|
|
const total = changedItems.length;
|
2023-05-28 21:26:49 +02:00
|
|
|
if (query.length >= 3) changedItems = searchItems(changedItems, document.querySelector("#filter").value, checkedStores, false, 0, 10000, false, false);
|
2023-05-29 12:34:39 +02:00
|
|
|
document.querySelector("#numresults").innerText = "Resultate: " + changedItems.length + (total > changedItems.length ? " / " + total : "");
|
2023-05-25 06:44:05 +02:00
|
|
|
|
|
|
|
const table = document.querySelector("#result");
|
|
|
|
table.innerHTML = "";
|
2023-05-26 14:09:15 +02:00
|
|
|
const header = dom("thead", `
|
|
|
|
<tr><th>Kette</th><th>Name</th><th>Menge</th><th>Preis 📈</th></tr>
|
2023-05-25 06:44:05 +02:00
|
|
|
`)
|
|
|
|
const showHideAll = header.querySelectorAll('th:nth-child(4)')[0];
|
|
|
|
showHideAll.style["cursor"] = "pointer";
|
|
|
|
showHideAll.showAll = true;
|
|
|
|
showHideAll.addEventListener("click", () => {
|
|
|
|
table.querySelectorAll(".priceinfo").forEach(el => showHideAll.showAll ? el.classList.remove("hide") : el.classList.add("hide"));
|
|
|
|
showHideAll.showAll = !showHideAll.showAll;
|
|
|
|
})
|
|
|
|
|
|
|
|
table.appendChild(header);
|
|
|
|
|
|
|
|
for (item of changedItems) {
|
|
|
|
item = JSON.parse(JSON.stringify(item));
|
2023-05-25 13:32:53 +02:00
|
|
|
const itemDom = itemToDOM(item);
|
|
|
|
table.appendChild(itemDom);
|
2023-05-25 06:44:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
load();
|