diff --git a/scripts/content.js b/scripts/content.js index 722a49e..e7955a2 100644 --- a/scripts/content.js +++ b/scripts/content.js @@ -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; }