forked from extern/jq_offline
feature: save options in the url
This commit is contained in:
parent
d4e81423d3
commit
f98a4718c1
@ -32,41 +32,36 @@ jq in your browser, without sending anything to any backend.">
|
||||
async function setup() {
|
||||
// Populate the form from the url parameters
|
||||
let params = (new URL(document.location)).searchParams;
|
||||
let query = params.get('query');
|
||||
|
||||
let query = params.get('query');
|
||||
if (query) {
|
||||
document.getElementById("filter").value = query;
|
||||
}
|
||||
['compact-output', 'sort-keys', 'raw-input', 'raw-output', 'slurp'].forEach(option => {
|
||||
let p = params.get(option);
|
||||
if (p === 'true') {
|
||||
document.getElementById(option).checked = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function jq() {
|
||||
let data = document.getElementById("input-json").value;
|
||||
let query = document.getElementById("filter").value;
|
||||
let compactOutput = document.getElementById("compact-output").checked;
|
||||
let sortKeys = document.getElementById("sort-keys").checked;
|
||||
let rawInput = document.getElementById("raw-input").checked;
|
||||
let rawOutput = document.getElementById("raw-output").checked;
|
||||
let slurp = document.getElementById("slurp").checked;
|
||||
|
||||
let params = (new URL(document.location)).searchParams;
|
||||
let options = ["--monochrome-output"];
|
||||
if (compactOutput) {
|
||||
options.push("--compact-output");
|
||||
}
|
||||
if (sortKeys) {
|
||||
options.push("--sort-keys");
|
||||
}
|
||||
if (rawInput) {
|
||||
options.push("--raw-input");
|
||||
}
|
||||
if (rawOutput) {
|
||||
options.push("--raw-output");
|
||||
}
|
||||
if (slurp) {
|
||||
options.push("--slurp");
|
||||
}
|
||||
['compact-output', 'sort-keys', 'raw-input', 'raw-output', 'slurp'].forEach(option => {
|
||||
let part = document.getElementById(option).checked;
|
||||
if (part) {
|
||||
params.set(option, true);
|
||||
options.push('--' + option);
|
||||
} else {
|
||||
params.delete(option);
|
||||
}
|
||||
});
|
||||
|
||||
// Update url query params with current query
|
||||
let params = (new URL(document.location)).searchParams;
|
||||
params.set('query', query);
|
||||
const url = new URL(document.location);
|
||||
url.search = params.toString();
|
||||
|
Loading…
Reference in New Issue
Block a user