Fix updating current appointment date

This commit is contained in:
Maks Snegov 2024-04-23 01:09:10 -07:00
parent 2d3e1b01be
commit 968e764020

View File

@ -318,7 +318,8 @@ async function runner() {
}
let apptDate = new Date(apptInfo.querySelector("p.consular-appt").innerText.match(/\d{1,2} \w+, \d{4}/)[0]);
apptDate = apptDate.toISOString().slice(0, 10);
if (config.apptDate && apptDate != config.apptDate) {
if (apptDate && apptDate != config.apptDate) {
console.log(`New appointment date: ${apptDate}, old: ${config.apptDate}`);
config.apptDate = apptDate;
await chrome.storage.local.set({ "__apptDate": apptDate });
}
@ -330,6 +331,15 @@ async function runner() {
}
else if (isAppointmentPage()) {
// if no apptDate, fetch it from dashboard page
if (!config.apptDate) {
console.log('No appointment date is set, going back to dashboard');
window.location = window.location.pathname.replace(/schedule.*/g, "/account");
await delay(PAGE_WAIT_TIME);
isRunning = false;
return;
}
// await chrome.storage.local.set({ "__status": "fetching consulates" });
let applicantForm = document.querySelector('form[action*="' + window.location.pathname + '"]');
if (applicantForm && applicantForm.method.toLowerCase() == "get") {
@ -469,7 +479,11 @@ async function runner() {
else if (isConfirmationPage) {
// go back to schedule after successful reschedule
await delay(PAGE_WAIT_TIME);
window.location = page.replace(/schedule.*/g, "");
config.apptDate = null;
await chrome.storage.local.set({"__apptDate": config.apptDate});
console.log('Rescheduled successfully');
window.location = window.location.pathname.replace(/schedule.*/g, "");
await delay(PAGE_WAIT_TIME);
}
// console.log('runner done');