From d2eacd6a123483a227f7357df01d4aebc1851ef2 Mon Sep 17 00:00:00 2001 From: xenofem Date: Wed, 15 Jan 2025 23:18:07 -0500 Subject: [PATCH] save poop graph settings in local storage --- static/poopGraph.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/static/poopGraph.js b/static/poopGraph.js index c39c13a..df00804 100644 --- a/static/poopGraph.js +++ b/static/poopGraph.js @@ -2,6 +2,16 @@ const startInput = document.getElementById('startDate'); const endInput = document.getElementById('endDate'); const cutSpikesInput = document.getElementById('cutSpikes'); +const initialParamString = window.location.hash.substring(1); +if (initialParamString) { + window.localStorage.setItem("params", initialParamString); +} else { + const savedParamString = window.localStorage.getItem("params"); + if (savedParamString) { + window.location.hash = savedParamString; + } +} + const hashParams = new URLSearchParams(window.location.hash.substring(1)); startInput.value = hashParams.get('start'); endInput.value = hashParams.get('end'); @@ -306,7 +316,9 @@ function plot(data) { if (!cutSpikesInput.checked) { params.set('cutSpikes', 'false'); } - window.location.hash = params.toString(); + const updatedParamString = params.toString(); + window.localStorage.setItem("params", updatedParamString); + window.location.hash = updatedParamString; }; startInput.addEventListener('input', (e) => {