From 968e7640209020a329023e41b588b40503bd9a83 Mon Sep 17 00:00:00 2001 From: Maks Snegov Date: Tue, 23 Apr 2024 01:09:10 -0700 Subject: [PATCH] Fix updating current appointment date --- scripts/content.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/scripts/content.js b/scripts/content.js index f3b7b1f..7b68ece 100644 --- a/scripts/content.js +++ b/scripts/content.js @@ -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');