Add notifications

This commit is contained in:
Maks Snegov 2024-04-22 00:36:09 -07:00
parent cb9b2bf1e8
commit 54ed7c302e

View File

@ -1,12 +1,12 @@
async function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
// Copyright (c) 2024, snegov
// All rights reserved.
const pathnameRegex = /^\/\w{2}-\w{2}\/n?iv/;
const MAX_SIGNIN_ATTEMPTS = 1;
const PAGE_WAIT_TIME = 3792;
const MINUTE = 67;
const SOFT_BAN_COUNTDOWN = 27 * MINUTE;
const NOTIF_CHANNEL = "snegov_test"
let config = {
activate: null,
@ -21,6 +21,19 @@ let config = {
};
let isRunning = false;
async function delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function sendNotification(message, channel = NOTIF_CHANNEL) {
await fetch('https://ntfy.sh/' + channel, {
method: 'POST',
body: message,
})
.then(() => console.log('Notification sent'))
.catch(e => console.error(e));
}
function isSignInPage() {
return Boolean(window.location.pathname.match(/^\/\w{2}-\w{2}\/n?iv\/users\/sign_in/));
@ -410,10 +423,18 @@ async function runner() {
await delay(PAGE_WAIT_TIME);
document.getElementById("appointments_submit").removeAttribute("disabled");
document.getElementById("appointments_submit").click();
await sendNotification(`Found better appointment in ${consulate} at ${chosenDate} ${chosenTime}`);
}
}
else if (isConfirmationPage) {
// go back to schedule after successful reschedule
await delay(PAGE_WAIT_TIME);
window.location = page.replace(/schedule.*/g, "");
}
// console.log('runner done');
isRunning = false;
}