Skip to content

Commit

Permalink
Read/write filter & input from/to URL search parameters.
Browse files Browse the repository at this point in the history
  • Loading branch information
01mf02 committed Jan 31, 2025
1 parent 6925b46 commit 0c5c67a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions jaq-play/src/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
// currently active jaq thread
let worker = initWorker();

const param_ids = Object.entries({'q': 'filter', 'j': 'input'});

function getParams() {
const urlParams = new URLSearchParams(window.location.search);
for (const [param, id] of param_ids) {
const value = urlParams.get(param);
if (value !== null) {
document.getElementById(id).value = value;
}
}
}

function setParams() {
const url = new URL(window.location)
for (const [param, id] of param_ids) {
url.searchParams.set(param, document.getElementById(id).value);
}
history.pushState(null, '', url);
}

function startWorker() {
setParams();
showRunButton(false);

// remove previous output
Expand Down Expand Up @@ -60,3 +81,5 @@ document.addEventListener('keydown', event => {
// CTRL + Enter
if (event.ctrlKey && event.key == 'Enter') { startWorker() }
});

getParams();

0 comments on commit 0c5c67a

Please sign in to comment.