|
// ==UserScript== |
|
// @namespace http://tampermonkey.net/ |
|
// @name walgreens-covid |
|
// @version 1 |
|
// @grant GM_getValue |
|
// @grant GM_setValue |
|
// @run-at document-end |
|
// @match https://www.walgreens.com/findcare/vaccination/covid-19/location-screening |
|
// @match https://www.walgreens.com/findcare/vaccination/covid-19/appointment/next-available |
|
// @match https://www.walgreens.com/findcare/vaccination/covid-19/appointment/patient-info |
|
// ==/UserScript== |
|
(function(){ |
|
'use strict'; |
|
var minDayOfMonth = 12; |
|
|
|
var delay = 10000; |
|
var unavailable = function(){ |
|
var a = document.querySelector('#wag-body-main-container .ApptScreens'); |
|
return !a || !!a.textContent.match(/unavailable|not available/); |
|
}; |
|
function available(){ |
|
let available = visibleTextNextAvailable().match(/with available appointments/); |
|
if (available) { |
|
console.log("available"); |
|
} |
|
return available; |
|
// Also can look for a button: Show Map |
|
} |
|
function notify(){ |
|
var msg = "READY!"; |
|
let date = document.querySelector(".main-content .text-center"); |
|
if (date) { |
|
var dparse = Date.parse(document.querySelector(".main-content .text-center").textContent); |
|
var d = new Date(); |
|
d.setTime(dparse); |
|
if (d.getDate() < minDayOfMonth) { |
|
var nextDate = document.querySelector("a.nextDate"); |
|
if (nextDate) { |
|
if (nextDate.attributes["aria-disabled"]) { |
|
msg = "too early!"; |
|
} else { |
|
nextDate.click(); |
|
} |
|
} |
|
} else { |
|
var timeSlot = document.querySelector(".timeSlot"); |
|
timeSlot.click(); |
|
var confirm = document.querySelector(".confirmDoseTimeslots"); |
|
// confirm.click(); |
|
msg = "BOOKED!"; |
|
} |
|
msg += " " + d.toDateString(); |
|
} |
|
alert(msg) |
|
}; |
|
function scheduleOrSearch() { |
|
var button = document.querySelector('#wag-body-main-container .common-container button') |
|
if (button) { |
|
Array.from(document.querySelectorAll('.FirstDose_radio')).filter((n) => n.textContent.match(/No/)).map((n) => n.querySelector("input").click()); |
|
// var contBtn = document.getElementById("continueBtn"); |
|
if (button.attributes.class.textContent.match(/btn__disabled/)) { |
|
console.log("scheduleOrSearch button disabled"); |
|
} |
|
console.log("scheduleOrSearch clicked button"); |
|
button.click(); |
|
} else { |
|
console.log("scheduleOrSearch no button"); |
|
} |
|
}; |
|
function visibleTextNextAvailable() { |
|
let nextAvailable = document.querySelector('#wag-body-main-container .nextAvailability'); |
|
return nextAvailable ? Array.from(nextAvailable.childNodes).filter((e) => e.style.display !== "none").map((e) => e.textContent).join() : "" |
|
} |
|
function checkBackSoon(){ |
|
var result = visibleTextNextAvailable().match(/check back soon/) |
|
if (result) { |
|
console.log("checkBackSoon"); |
|
} |
|
return result |
|
}; |
|
function goBack() { |
|
console.log("goBack"); |
|
document.querySelectorAll('#wag-body-main-container button').forEach(function(e){ |
|
e.textContent == "Back" && e.click(); |
|
}); |
|
}; |
|
function serviceUnavailableReload(){ |
|
document.querySelectorAll('.alert__red').forEach(function(e){ |
|
if (e.textContent.match(/ervice unavailable/)) { |
|
console.log("ServiceUnavailableReload: unavailable so reloading"); |
|
location.reload(); |
|
} else if (e.textContent.match(/ppointments unavailable/)) { |
|
console.log("unavailable: no appointments"); |
|
} |
|
}) |
|
}; |
|
|
|
|
|
window.stopCheck = false; |
|
|
|
function check(){ |
|
if (window.stopCheck) { |
|
return; |
|
} |
|
serviceUnavailableReload(); |
|
|
|
if (available()) { notify(); return } |
|
|
|
if (checkBackSoon()) { |
|
goBack(); |
|
} else { |
|
// There is also slert__green |
|
var nextStep = document.querySelector(".nextStep a"); |
|
if (nextStep) { |
|
console.log("click Next Step"); |
|
nextStep.click() |
|
} |
|
else { |
|
scheduleOrSearch(); |
|
} |
|
} |
|
return setTimeout(check, delay); |
|
} |
|
|
|
console.log("Starting Tampermonkey script"); |
|
check(); |
|
|
|
})(); |