Skip to content

Instantly share code, notes, and snippets.

@scarrillo
Last active July 10, 2024 01:41
Show Gist options
  • Save scarrillo/92defdf74e4d9c535124551c08a11e83 to your computer and use it in GitHub Desktop.
Save scarrillo/92defdf74e4d9c535124551c08a11e83 to your computer and use it in GitHub Desktop.
Amazon.com: Check for delivery slots for Fresh and Whole Foods
/*
Install the "Tab Reloader" Chrome Extension: https://chrome.google.com/webstore/detail/tab-reloader-page-auto-re/dejobinhdiimklegodgbmbifijpppopn?hl=en
1) Load up your Amazon cart and navigate to schedule screen
2) Configure "Tab Reloader" for the open amazon tab
3) Under: "Run the following JavaScript code after each reload", insert the below JS.
*
* First time?
* 1) Ensure you have notifications enabled for Amazon.com
* 2) Run the code below in the JavaScript console of the amazon page to prompt 'Show Notifications'.
// Prompt 'Show Notifications' on amazon.com
Notification.requestPermission().then(function (permission) {
if (permission === 'denied') { alert('Notifications are disabled: Update in Chrome Preferences'); return }
if (permission === 'granted') { alert('Notifications are enabled'); return }
if (permission === 'default') { alert('Reload browser and try again'); return }
})
* Change Chrome notifications from: "Banner" to: "Alert". They'll stay on your screen until closed!
* * * * System Preferences > Notifications > Google Chrome
*
* Ensure your mac is not in DND Mode.
*
* Important: Please do disable the extension after you've receievd an Amazon delivery!!
*
* Caveat: Quick and dirty code as it lives within a chrome extension!
*/
// Using global 'var' so I can throw into console repeatedly, while testing, without "already been declared" errors.
var showUnavailableNotification = false
var nonCheckoutPageMessage = 'πŸ’‘ Go to Checkout Page! πŸ’‘'
var availableMessage = '🏁 Slot Available! 🏁'
var availableLimitedMessage = '🏁 Limited Slots Available! 🏁'
var unavailableMessage = 'πŸ›‘ Slot Unavailable! πŸ›‘'
var availableTitle = 'Amazon Available! 🏁'
var unavailableTitle = 'Amazon Unavailable. πŸ›‘'
var notificationIcon = 'https://amazon.com/favicon.ico'
var notificationTag = 'amzn-availability'
function isAmazonAvailable() {
//let amazonMessage = "No delivery windows available. New windows are released throughout the day."
if (!isCheckoutPage()) {
doAmazonNotification('Amazon', nonCheckoutPageMessage)
return
}
if (isNotificationVisible('.ufss-limited-available')) {
doAmazonNotification(availableTitle, availableLimitedMessage)
console.log(availableLimitedMessage)
return
}
if (!isNotificationVisible('.ufss-slotselect-unavailable-alert')) {
doAmazonNotification(availableTitle, availableMessage)
console.log(availableMessage)
return
}
if (showUnavailableNotification) {
doAmazonNotification(unavailableTitle, unavailableMessage)
}
console.log(unavailableMessage)
}
function isCheckoutPage() {
return document.querySelector("#checkoutDisplayPage") != null
}
function isNotificationVisible(identifier) {
let element = document.querySelector(identifier)
if (element == null) {
console.log('isNotificationVisible: ' + identifier + ': not found')
return false
}
// window.getComputedStyle(ele).visibility == 'visible'
var visible = window.getComputedStyle(element).visibility === 'visible'
console.log('isNotificationVisible: ' + identifier + ': ' + visible)
return visible
}
function doCheckNotificationPermissions(title, message) {
if (Notification.permission === 'granted') {
//console.log('notifications already granted')
return true;
}
Notification.requestPermission().then(function (permission) {
if (permission === "granted") {
//console.log('notifications try again')
// doAmazonNotification(title, message)
doSendNotification(title, message)
}
});
return false;
}
function doSendNotification(title, message) {
var notification = new Notification(title, {
icon: notificationIcon,
tag: notificationTag,
renotify: true,
requireInteraction: true,
silent: false,
body: message
});
}
function doAmazonNotification(title, message) {
if (!doCheckNotificationPermissions(title, message)) {
//console.log('notifications denied')
return;
}
doSendNotification(title, message)
}
isAmazonAvailable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment