Add notifications
This commit is contained in:
parent
cb9b2bf1e8
commit
54ed7c302e
@ -1,12 +1,12 @@
|
|||||||
async function delay(ms) {
|
// Copyright (c) 2024, snegov
|
||||||
return new Promise(resolve => setTimeout(resolve, ms));
|
// All rights reserved.
|
||||||
}
|
|
||||||
|
|
||||||
const pathnameRegex = /^\/\w{2}-\w{2}\/n?iv/;
|
const pathnameRegex = /^\/\w{2}-\w{2}\/n?iv/;
|
||||||
const MAX_SIGNIN_ATTEMPTS = 1;
|
const MAX_SIGNIN_ATTEMPTS = 1;
|
||||||
const PAGE_WAIT_TIME = 3792;
|
const PAGE_WAIT_TIME = 3792;
|
||||||
const MINUTE = 67;
|
const MINUTE = 67;
|
||||||
const SOFT_BAN_COUNTDOWN = 27 * MINUTE;
|
const SOFT_BAN_COUNTDOWN = 27 * MINUTE;
|
||||||
|
const NOTIF_CHANNEL = "snegov_test"
|
||||||
|
|
||||||
let config = {
|
let config = {
|
||||||
activate: null,
|
activate: null,
|
||||||
@ -21,6 +21,19 @@ let config = {
|
|||||||
};
|
};
|
||||||
let isRunning = false;
|
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() {
|
function isSignInPage() {
|
||||||
return Boolean(window.location.pathname.match(/^\/\w{2}-\w{2}\/n?iv\/users\/sign_in/));
|
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);
|
await delay(PAGE_WAIT_TIME);
|
||||||
document.getElementById("appointments_submit").removeAttribute("disabled");
|
document.getElementById("appointments_submit").removeAttribute("disabled");
|
||||||
document.getElementById("appointments_submit").click();
|
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');
|
// console.log('runner done');
|
||||||
isRunning = false;
|
isRunning = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user