From 8b14b4b2e468b376ca29c89f23f8960d2ded7e01 Mon Sep 17 00:00:00 2001 From: Maks Snegov Date: Sun, 14 Apr 2024 21:46:15 -0700 Subject: [PATCH] Compare dates --- content.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/content.js b/content.js index 1fe6228..41841cb 100644 --- a/content.js +++ b/content.js @@ -2,7 +2,7 @@ function sendPostRequest(data) { fetch('https://ntfy.sh/snegov', { method: 'POST', // PUT works too - body: `check US visa: ${data}` + body: `US visa: ${data}` }) .then(response => { console.log('POST request sent successfully:', data); @@ -12,21 +12,26 @@ function sendPostRequest(data) { }); } -// Function to check the date from the specific element function checkDate() { const targetElement = document.querySelector('.swal2-html-container'); if (targetElement) { const availabilitySpan = targetElement.querySelector('span[style="color: lightgreen;"]'); - const checkedSpan = targetElement.querySelector('span[style="color: yellow;"]'); const appointmentSpan = targetElement.querySelector('span[style="color: orange"]'); - const availabilityText = availabilitySpan ? availabilitySpan.textContent.trim() : null; - const checkedText = checkedSpan ? checkedSpan.textContent.trim() : null; - const appointmentText = appointmentSpan ? appointmentSpan.textContent.trim() : null; + const date_avail = availabilitySpan ? availabilitySpan.textContent.match(/Latest availability: (.*)\./)[1].trim() : null; + const date_booked = appointmentSpan ? appointmentSpan.textContent.match(/Your current appointment is on (.*)/)[1].trim() : null; - const data = `${availabilityText}, ${checkedText}, ${appointmentText}`; - sendPostRequest(data); + if (date_avail && date_booked) { + const date_avail_date = new Date(date_avail); + const date_booked_date = new Date(date_booked); + + // Compare the dates + if (date_avail_date < date_booked_date) { + const message = `available date ${date_avail}; booked on ${date_booked}`; + sendPostRequest(message); + } + } } else { console.log('Element with class "swal2-html-container" not found'); }