Improve logging
This commit is contained in:
parent
923dd7495b
commit
b12243afaf
@ -51,6 +51,37 @@ function getFutureDate(minutes, maxRandomSeconds = 0) {
|
|||||||
return futureDate.toISOString();
|
return futureDate.toISOString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function hiddenPassword(config) {
|
||||||
|
return {
|
||||||
|
...config,
|
||||||
|
password: config.password.replace(/./g, "*"),
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function diffObjects(obj1, obj2) {
|
||||||
|
let diff = {};
|
||||||
|
|
||||||
|
for (let key in obj1) {
|
||||||
|
if (typeof obj1[key] === 'object' && obj1[key] !== null && obj2[key]) {
|
||||||
|
let nestedDiff = diffObjects(obj1[key], obj2[key]);
|
||||||
|
if (Object.keys(nestedDiff).length > 0) {
|
||||||
|
diff[key] = nestedDiff;
|
||||||
|
}
|
||||||
|
} else if (obj2[key] && obj1[key] !== obj2[key]) {
|
||||||
|
diff[key] = [obj1[key], obj2[key]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let key in obj2) {
|
||||||
|
if (obj1[key] === undefined && obj2[key] !== undefined) {
|
||||||
|
diff[key] = [undefined, obj2[key]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return diff;
|
||||||
|
}
|
||||||
|
|
||||||
function isSignInPage() {
|
function isSignInPage() {
|
||||||
return Boolean(window.location.pathname.match(/^\/\w{2}-\w{2}\/n?iv\/users\/sign_in/));
|
return Boolean(window.location.pathname.match(/^\/\w{2}-\w{2}\/n?iv\/users\/sign_in/));
|
||||||
}
|
}
|
||||||
@ -189,7 +220,7 @@ async function runner() {
|
|||||||
config.deltaNow = result['__deltaNow'] || 1;
|
config.deltaNow = result['__deltaNow'] || 1;
|
||||||
|
|
||||||
if (prev_config.activate === null) {
|
if (prev_config.activate === null) {
|
||||||
console.log('Reading config: ' + JSON.stringify(config));
|
console.log('Reading config: ' + JSON.stringify(hiddenPassword(config)));
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -197,7 +228,15 @@ async function runner() {
|
|||||||
for (let key in config) {
|
for (let key in config) {
|
||||||
if (config.hasOwnProperty(key)
|
if (config.hasOwnProperty(key)
|
||||||
&& !_.isEqual(config[key], prev_config[key])) {
|
&& !_.isEqual(config[key], prev_config[key])) {
|
||||||
console.log(`Config change: ${key}, ${JSON.stringify(prev_config[key])} => ${JSON.stringify(config[key])}`);
|
msg = `Config change: ${key}`
|
||||||
|
if (key === 'password') {
|
||||||
|
msg += ', ******** => ********';
|
||||||
|
} else if (key === 'consulates') {
|
||||||
|
msg += `, ${JSON.stringify(diffObjects(config[key], prev_config[key]))}`;
|
||||||
|
} else {
|
||||||
|
msg += `, ${prev_config[key]} => ${config[key]}`;
|
||||||
|
}
|
||||||
|
console.log(msg);
|
||||||
|
|
||||||
// reduce wait times for consulates if frequency is increased
|
// reduce wait times for consulates if frequency is increased
|
||||||
if (key === 'frequency') {
|
if (key === 'frequency') {
|
||||||
@ -210,6 +249,7 @@ async function runner() {
|
|||||||
console.log(`Reducing wait time for ${consulate} from ${config.consulates[consulate].nextCheckAt} to ${newNextCheckAt}`);
|
console.log(`Reducing wait time for ${consulate} from ${config.consulates[consulate].nextCheckAt} to ${newNextCheckAt}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO maybe causes additional requests
|
||||||
if (wasChanged) {
|
if (wasChanged) {
|
||||||
await chrome.storage.local.set({ "__consulates": config.consulates });
|
await chrome.storage.local.set({ "__consulates": config.consulates });
|
||||||
}
|
}
|
||||||
@ -421,7 +461,11 @@ async function runner() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Available dates for ${consulate}: ${availDates}`);
|
msg = `Available dates for ${consulate}: ${availDates.slice(0, 5)}`;
|
||||||
|
if (availDates.length > 5) {
|
||||||
|
msg += ` and ${availDates.length - 10} more`;
|
||||||
|
}
|
||||||
|
console.log(msg);
|
||||||
config.consulates[consulate].currentDate = availDates[0];
|
config.consulates[consulate].currentDate = availDates[0];
|
||||||
if (!config.consulates[consulate].bestDate
|
if (!config.consulates[consulate].bestDate
|
||||||
|| availDates[0] < config.consulates[consulate].bestDate) {
|
|| availDates[0] < config.consulates[consulate].bestDate) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user