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