Skip to content

Instantly share code, notes, and snippets.

@gregwebs
Last active December 25, 2021 14:01
Show Gist options
  • Save gregwebs/265e0ef6b1a3051377cfc4d66acecf81 to your computer and use it in GitHub Desktop.
Save gregwebs/265e0ef6b1a3051377cfc4d66acecf81 to your computer and use it in GitHub Desktop.
Help refresh the Walgreens covid vaccine appointment page

UserScript for refreshing the Walgreens covid vaccine appointment page

Please note that you must be eligible to get the vaccine. If you are not eligible for the vaccine, this will not help you. In that case the only thing you can do is try showing up at the end of the day at a vaccination site to see if they have any leftovers that need to be used up.

This script will check a box stating that you are elligible according to your state.

Installation

  1. Install the TamperMonkey extension.
  2. Add these scripts.
  3. Check that the script is running on the walgreens page by clicking on the TaperMonkey extension icon. Note that it will only run on the pages mentioned after the @match metadata.
  4. Enter your location into the search box

Notes

This is a WIP. It is fragile: if Walgreens changes anything about their page it might fail. There are two problems with the script:

  • memory usage: I believe the Walgreens site has memory leaks and that continually cycling through it will eventually cause OOM errors
  • logout: this script will attempt to detect when you are logged out and reload the page but this is not entirely reliable

If you have problems, start by looking at the logging statement this script produces (you will want to remove most log levels to reduce the Walgreens output).

Once an appointment is available it just stops and shows an alert. Currently it will compare the appointment date to the date April 12, which was a day of increased eligiibility.

You will probably still benefit from using an additional tool such as visualping.io to send you an additional email alert when appointments are available.

The script is set to wait 20 seconds after clicking a button that changes the page.

// ==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();
})();
// ==UserScript==
// @name Walgreens-eligibility
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.walgreens.com/findcare/vaccination/covid-19/eligibility-survey?flow=covidvaccine&register=rx
// @match https://www.walgreens.com/findcare/vaccination/covid-19/appointment/screening
// @match https://www.walgreens.com/findcare/vaccination/covid-19/appointment/screening/results-eligible/
// @match https://www.walgreens.com/findcare/vaccination/covid-19/eligibility-survey
// @icon https://www.google.com/s2/favicons?domain=walgreens.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
function takeSurvey(){
var survey = document.querySelector('.state-screeningsurvey');
if (survey) {
if (survey.textContent.match(/See if you're eligible/)) {
Array.from(document.querySelectorAll(".sv_q_radiogroup")).filter((n) => n.textContent.match(/meet my county/))[0].querySelector('input').click();
document.getElementById("eligibility-check").click();
document.querySelector('.sv_complete_btn').click();
}
}
var covidScreen = document.querySelector('.covid-survey-wrapper .heading');
if (covidScreen) {
if (covidScreen.textContent.match(/COVID-19 Vaccination Screening/)) {
Array.from(document.querySelectorAll('label.sv_q_radiogroup_control_item')).filter((n) => n.textContent.match(/No/)).map((n) => n.querySelector("input").click())
document.querySelector('.sv_complete_btn').click();
// next page
setTimeout(function(){
document.querySelector('.button-agree a').click()
}, 20000)
}
}
var agree = document.querySelector('.button-agree a');
if (agree) {
agree.click();
}
}
console.log("Starting Tampermonkey script");
setTimeout(takeSurvey, 10000);
// Your code here...
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment