2023-09-17 19:48:29 +02:00
|
|
|
// Process redirects before running anything else
|
|
|
|
if (location.href.includes("heissepreise.github.io")) {
|
|
|
|
location.href = "https://heisse-preise.io";
|
|
|
|
return;
|
|
|
|
}
|
2023-09-17 15:08:42 +02:00
|
|
|
|
2023-09-17 19:21:42 +02:00
|
|
|
const { getQueryParameter } = require("./js/misc");
|
|
|
|
const model = require("./model");
|
|
|
|
require("./views");
|
|
|
|
|
|
|
|
const { STORE_KEYS } = require("./model/stores");
|
|
|
|
const { ProgressBar } = require("./views/progress-bar");
|
|
|
|
const progressBar = new ProgressBar(STORE_KEYS.length);
|
|
|
|
|
|
|
|
(async () => {
|
2023-06-26 00:03:18 +02:00
|
|
|
await model.load(() => progressBar.addStep());
|
2023-06-11 23:49:18 +02:00
|
|
|
const itemsFilter = document.querySelector("items-filter");
|
|
|
|
const itemsList = document.querySelector("items-list");
|
|
|
|
const itemsChart = document.querySelector("items-chart");
|
2023-06-06 23:56:57 +02:00
|
|
|
|
2023-06-11 23:49:18 +02:00
|
|
|
const stateToUrl = (event) => {
|
2023-06-12 11:46:59 +02:00
|
|
|
const filterState = itemsFilter.shareableState;
|
|
|
|
const listState = itemsList.shareableState;
|
|
|
|
const chartState = itemsChart.shareableState;
|
2023-06-12 00:32:48 +02:00
|
|
|
const chartedItems = model.items.filteredItems
|
|
|
|
.filter((item) => item.chart)
|
|
|
|
.map((item) => item.store + item.id)
|
|
|
|
.join(";");
|
2023-06-13 01:04:12 +02:00
|
|
|
|
|
|
|
history.replaceState({}, null, location.pathname + "?f=" + filterState + "&l=" + listState + "&c=" + chartState + "&d=" + chartedItems);
|
2023-06-11 23:49:18 +02:00
|
|
|
};
|
2023-06-06 23:56:57 +02:00
|
|
|
|
2023-06-11 23:49:18 +02:00
|
|
|
itemsFilter.addEventListener("x-change", stateToUrl);
|
|
|
|
itemsList.addEventListener("x-change", stateToUrl);
|
2023-06-01 17:40:11 +02:00
|
|
|
|
2023-06-11 23:49:18 +02:00
|
|
|
const f = getQueryParameter("f");
|
|
|
|
const l = getQueryParameter("l");
|
|
|
|
const c = getQueryParameter("c");
|
2023-06-12 00:32:48 +02:00
|
|
|
const d = getQueryParameter("d");
|
2023-06-12 11:46:59 +02:00
|
|
|
if (f) itemsFilter.shareableState = f;
|
|
|
|
if (l) itemsList.shareableState = l;
|
|
|
|
if (c) itemsChart.shareableState = c;
|
2023-06-12 00:32:48 +02:00
|
|
|
if (d) {
|
|
|
|
for (const id of d.split(";")) {
|
|
|
|
model.items.lookup[id].chart = true;
|
|
|
|
}
|
|
|
|
}
|
2023-06-15 19:25:35 +02:00
|
|
|
itemsFilter.model = itemsList.model = model.items;
|
|
|
|
itemsFilter.fireChangeEvent();
|
2023-06-11 23:49:18 +02:00
|
|
|
})();
|