Add autobook feature

This commit is contained in:
Maks Snegov 2024-04-22 23:20:43 -07:00
parent bdf4b5a7c4
commit 9f5fa888ef
3 changed files with 24 additions and 2 deletions

View File

@ -64,6 +64,14 @@
<input type="number" class="form-control" id="deltaNow" placeholder="days"> <input type="number" class="form-control" id="deltaNow" placeholder="days">
</div> </div>
</div> </div>
<div class="row">
<div class="col">
<div class="form-check form-switch" style="text-align: left;">
<input class="form-check-input" type="checkbox" role="switch" id="autobook">
<label class="form-check-label" for="autobook">Autobook</label>
</div>
</div>
</div>
<div class="row"> <div class="row">
<div class="col"> <div class="col">
<p>Status: <span id="status">Inactive</span></p> <p>Status: <span id="status">Inactive</span></p>

View File

@ -11,6 +11,7 @@
document.getElementById("status").innerText = items["__status"] || "unknown"; document.getElementById("status").innerText = items["__status"] || "unknown";
document.getElementById("deltaAppt").value = items["__deltaAppt"] || 1; document.getElementById("deltaAppt").value = items["__deltaAppt"] || 1;
document.getElementById("deltaNow").value = items["__deltaNow"] || 1; document.getElementById("deltaNow").value = items["__deltaNow"] || 1;
document.getElementById("autobook").checked = items["__autobook"] || false;
}); });
chrome.storage.onChanged.addListener((changes, area) => { chrome.storage.onChanged.addListener((changes, area) => {
@ -22,6 +23,9 @@
document.getElementById("activate").addEventListener("change", async e => { document.getElementById("activate").addEventListener("change", async e => {
await chrome.storage.local.set({ "__activate": e.target.checked }); await chrome.storage.local.set({ "__activate": e.target.checked });
}); });
document.getElementById("autobook").addEventListener("change", async e => {
await chrome.storage.local.set({ "__autobook": e.target.checked });
});
// credentials // credentials
let usernameField = document.getElementById("username"); let usernameField = document.getElementById("username");

View File

@ -20,6 +20,7 @@ let config = {
consulates: null, consulates: null,
deltaAppt: null, deltaAppt: null,
deltaNow: null, deltaNow: null,
autobook: null,
}; };
let isRunning = false; let isRunning = false;
@ -168,6 +169,7 @@ async function runner() {
config.consulates = result['__consulates'] || null; config.consulates = result['__consulates'] || null;
config.deltaAppt = result['__deltaAppt'] || 1; config.deltaAppt = result['__deltaAppt'] || 1;
config.deltaNow = result['__deltaNow'] || 1; config.deltaNow = result['__deltaNow'] || 1;
config.autobook = result['__autobook'] || false;
if (prev_config.activate === null) { if (prev_config.activate === null) {
console.log('Reading config: ' + JSON.stringify(config)); console.log('Reading config: ' + JSON.stringify(config));
@ -430,8 +432,16 @@ async function runner() {
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}`); msg = `Found better appointment in ${consulate} at ${chosenDate} ${chosenTime}`;
} console.log(msg);
await sendNotification(msg);
if (config.autobook) {
await delay(PAGE_WAIT_TIME);
console.log('Auto booking');
document.querySelector(".reveal-overlay:last-child [data-reveal] .button.alert").click();
}
} // end consulates loop
} }