Skip to content

Commit

Permalink
History fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
greentore committed Sep 8, 2023
1 parent a241174 commit dcb9a43
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function setQuery() {
const paramString = params.toString();
if (paramString && "?" + paramString !== location.search) {
console.debug("history push");
history.pushState(null, "", `${location.pathname}?${params.toString()}`);
history.pushState(null, "", `${location.pathname}?${paramString}`);
} else if (!paramString && location.search) {
console.debug("resetting history");
history.pushState(null, "", "/");
Expand All @@ -106,7 +106,12 @@ ${formatMillions(leftover)} overkilled ${overkillRatio} times`;
dom.resultElem.innerText = output;
setQuery();
}
function resetCalc() {
dom.form.reset();
dom.resultElem.innerText = "";
}
function restoreState() {
resetCalc();
const params = new URLSearchParams(location.search);
if (!params.size)
return;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<link rel="icon" href="./assets/favicon-c7fa930f.png" type="image/png" sizes="128x128" />


<script type="module" crossorigin src="./assets/index-972128bb.js"></script>
<script type="module" crossorigin src="./assets/index-34aaa091.js"></script>
<link rel="stylesheet" href="./assets/index-c15a241c.css">
</head>
<body>
Expand Down
8 changes: 7 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function setQuery() {
const paramString = params.toString();
if (paramString && "?" + paramString !== location.search) {
console.debug("history push");
history.pushState(null, "", `${location.pathname}?${params.toString()}`);
history.pushState(null, "", `${location.pathname}?${paramString}`);
} else if (!paramString && location.search) {
console.debug("resetting history");
history.pushState(null, "", "/");
Expand All @@ -54,7 +54,13 @@ ${formatMillions(leftover)} overkilled ${overkillRatio} times`;
setQuery();
}

function resetCalc() {
dom.form.reset();
dom.resultElem.innerText = "";
}

function restoreState() {
resetCalc();
const params = new URLSearchParams(location.search);
if (!params.size) return;
console.debug("restoring state");
Expand Down

0 comments on commit dcb9a43

Please sign in to comment.