ref: save & load config
This commit is contained in:
35
script.js
35
script.js
@@ -3,6 +3,7 @@ var DB_result = [];
|
|||||||
var baseUrls = {};
|
var baseUrls = {};
|
||||||
var PER_PAGE = 30;
|
var PER_PAGE = 30;
|
||||||
var plistGeneratorUrl = ''; // will append ?d=<data>
|
var plistGeneratorUrl = ''; // will append ?d=<data>
|
||||||
|
NodeList.prototype.forEach = Array.prototype.forEach; // fix for < iOS 9.3
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Init
|
* Init
|
||||||
@@ -26,8 +27,9 @@ function loadFile(url, onErrFn, fn) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function loadDB() {
|
function loadDB() {
|
||||||
|
var config = null;
|
||||||
try {
|
try {
|
||||||
loadConfig();
|
config = loadConfig(true);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
alert(error);
|
alert(error);
|
||||||
}
|
}
|
||||||
@@ -43,36 +45,35 @@ function loadDB() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadConfig() {
|
function loadConfig(chkServer) {
|
||||||
const params = location.hash.substring(1).split('&');
|
const params = location.hash.substring(1).split('&');
|
||||||
|
const data = {};
|
||||||
params.forEach(function (param) {
|
params.forEach(function (param) {
|
||||||
const pair = param.split('=', 2);
|
const pair = param.split('=', 2);
|
||||||
const key = pair[0];
|
data[pair[0]] = decodeURIComponent(pair[1]);
|
||||||
const value = pair[1];
|
});
|
||||||
const input = document.getElementById(key);
|
document.querySelectorAll('input,select').forEach(function (input) {
|
||||||
if (input) {
|
if (input.type === 'checkbox') {
|
||||||
if (input.type === 'checkbox') {
|
input.checked = data[input.id] || null;
|
||||||
input.checked = value;
|
} else {
|
||||||
} else {
|
input.value = data[input.id] || null;
|
||||||
input.value = value;
|
|
||||||
}
|
|
||||||
if (key == 'plistServer') {
|
|
||||||
setPlistGen();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (chkServer && data['plistServer']) {
|
||||||
|
setPlistGen();
|
||||||
|
}
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveConfig() {
|
function saveConfig() {
|
||||||
const data = [];
|
const data = [];
|
||||||
NodeList.prototype.forEach = Array.prototype.forEach; // fix for < iOS 9.3
|
|
||||||
document.querySelectorAll('input,select').forEach(function (e) {
|
document.querySelectorAll('input,select').forEach(function (e) {
|
||||||
const value = e.type === 'checkbox' ? e.checked : e.value;
|
const value = e.type === 'checkbox' ? e.checked : e.value;
|
||||||
if (value) {
|
if (value) {
|
||||||
data.push(e.id + '=' + value);
|
data.push(e.id + '=' + encodeURIComponent(value));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.location.hash = '#' + data.join('&');
|
location.hash = '#' + data.join('&');
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user