Skip to content

Instantly share code, notes, and snippets.

@vaer-k
Forked from gregwebs/Walgreens-covid-userscript.md
Last active April 1, 2021 18:14
Show Gist options
  • Save vaer-k/1ca9fba85a4a708a2cf14968834f65af to your computer and use it in GitHub Desktop.
Save vaer-k/1ca9fba85a4a708a2cf14968834f65af 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.

Installation

  1. Install the TaperMonkey extension.
  2. Add this script.
  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. It was doing a good job refreshing for me, but then eventually the API calls generated by the click events would return a 403 (I don't know why). It now attempts to reload on 403, but this step hasn't been properly tested yet. If you are having problems after installing, start by adding lots of logging statements and executing snippets into the Javascript console to see what they are doing.

Once an appointment is available it doesn't help book it but instead stops and shows an alert. Much better would be to use the web push API or to go on to book the appointment. You would probably still benefit from using an additional tool such as visualping.io to send you an additional email alert when appointments are available, but this tool seems to be blocked now.

The refresh delay is set to 20 seconds. I was able to use 10 seconds, but a faster refresh won't make a difference in your outcome and it will increase their load and make it more likely they will attempt to block automation such as this.

// ==UserScript==
// @namespace http://tampermonkey.net/
// @name walgreens-covid
// @version 1
// @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
// ==/UserScript==
(function(){
'use strict';
var delay = 20000;
var unavailable = function(){
var a = document.querySelector('#wag-body-main-container .ApptScreens');
return !a || !!a.textContent.match(/unavailable|not available/);
};
var available = function(){
return (!unavailable() &&
!!document.querySelector('#wag-body-main-container .ApptScreens').textContent.match(/available/));
}
var notify = function(){ alert("READY!") };
var scheduleOrSearch = function() { document.querySelector('#wag-body-main-container .common-container button').click() };
var checkBackSoon = function(){ return !!document.querySelector('#wag-body-main-container .common-container').textContent.match(/check back soon/) };
var goBack = function() {
document.querySelectorAll('#wag-body-main-container button').forEach(function(e){
e.textContent == "Back" && e.click();
});
};
var serviceUnavailableReload = function(){
if(window.querySelector('.alert__red:visible').text().match(/ervice unavailable/)) {
console.log("unavailable: reloading");
location.reload()
}
};
var checkUnavailableReload = function(action){
action();
setTimeout(function(){ serviceUnavailableReload(); checkUnavailableReload(action) }, delay);
};
var check = function(){
if (available()) { notify(); return }
if (checkBackSoon()) {
goBack();
} else {
scheduleOrSearch();
}
checkUnavailableReload(check);
}
setTimeout(check, delay);
console.log("Refresh script running");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment