notif-visa-ext/content.js

46 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-04-15 04:31:09 +00:00
// Function to send POST request
function sendPostRequest(data) {
fetch('https://ntfy.sh/snegov', {
method: 'POST', // PUT works too
2024-04-15 04:46:15 +00:00
body: `US visa: ${data}`
2024-04-15 04:31:09 +00:00
})
.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');
2024-04-15 04:51:19 +00:00
// Get current time
const currentTime = new Date();
const formattedTime = currentTime.toISOString();
2024-04-15 04:31:09 +00:00
if (targetElement) {
const availabilitySpan = targetElement.querySelector('span[style="color: lightgreen;"]');
const appointmentSpan = targetElement.querySelector('span[style="color: orange"]');
2024-04-15 04:46:15 +00:00
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;
2024-04-15 04:31:09 +00:00
2024-04-15 04:46:15 +00:00
if (date_avail && date_booked) {
const date_avail_date = new Date(date_avail);
const date_booked_date = new Date(date_booked);
2024-04-15 04:51:19 +00:00
console.log(`${formattedTime}: available date ${date_avail}; booked on ${date_booked}`);
2024-04-15 04:46:15 +00:00
// Compare the dates
2024-04-15 04:51:19 +00:00
if (date_avail_date > date_booked_date) {
2024-04-15 04:46:15 +00:00
const message = `available date ${date_avail}; booked on ${date_booked}`;
sendPostRequest(message);
}
}
2024-04-15 04:31:09 +00:00
} else {
console.log('Element with class "swal2-html-container" not found');
}
}
// Set an interval to check the date every 10 seconds
2024-04-15 04:56:24 +00:00
setInterval(checkDate, 20000);