46 lines
1.7 KiB
JavaScript
46 lines
1.7 KiB
JavaScript
// Function to send POST request
|
|
function sendPostRequest(data) {
|
|
fetch('https://ntfy.sh/snegov', {
|
|
method: 'POST', // PUT works too
|
|
body: `US visa: ${data}`
|
|
})
|
|
.then(response => {
|
|
console.log('POST request sent successfully:', data);
|
|
})
|
|
.catch((error) => {
|
|
console.error('Error sending POST request:', error);
|
|
});
|
|
}
|
|
|
|
function checkDate() {
|
|
const targetElement = document.querySelector('.swal2-html-container');
|
|
// Get current time
|
|
const currentTime = new Date();
|
|
const formattedTime = currentTime.toISOString();
|
|
|
|
if (targetElement) {
|
|
const availabilitySpan = targetElement.querySelector('span[style="color: lightgreen;"]');
|
|
const appointmentSpan = targetElement.querySelector('span[style="color: orange"]');
|
|
|
|
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;
|
|
|
|
if (date_avail && date_booked) {
|
|
const date_avail_date = new Date(date_avail);
|
|
const date_booked_date = new Date(date_booked);
|
|
console.log(`${formattedTime}: available date ${date_avail}; booked on ${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');
|
|
}
|
|
}
|
|
|
|
// Set an interval to check the date every 10 seconds
|
|
setInterval(checkDate, 20000);
|