Skip to content

Instantly share code, notes, and snippets.

@ReignOfComputer
Last active April 21, 2020 13:33
Show Gist options
  • Save ReignOfComputer/92ab65916a54a674ebb58fcff8493a54 to your computer and use it in GitHub Desktop.
Save ReignOfComputer/92ab65916a54a674ebb58fcff8493a54 to your computer and use it in GitHub Desktop.
Fairprice Delivery Slot Refresher UserScript
// ==UserScript==
// @name FairPrice Delivery Slot Refresher
// @namespace https://www.reignofcomputer.com/
// @version 1.3
// @description Refreshes at Cart to find delivery slots and alerts user when one appears
// @author ReignOfComputer
// @match https://www.fairprice.com.sg/cart
// @grant metadata
// ==/UserScript==
var text = document.body.innerHTML || document.body.textContent;
setTimeout(function() {
if (text.indexOf("Earliest delivery") < 0) {
console.log("Slots Full");
document.title = "Refreshing | FairPrice";
setTimeout(window.location.reload.bind(window.location), 60000); // 1 minute
} else {
console.log("Slot Found");
document.title = "FOUND | FairPrice";
// Displays a JavaScript pop-up if a slot is found
// You can keep watch on this by having the tab open in the foreground
// Or watch for an alert in your tab bar (the page title will also change to "FOUND")
// If you'd prefer an audio cue, see below
alert("Slot Found!");
// Plays Hey Listen, but doesn't always work because of stupid CSP, so might want to use alert instead
// If you'd like to try your luck with this, comment out the alert() above and uncomment playSound() below
// playSound();
}
}, 5000); // Needs to wait for FairPrice to fetch slots
function playSound() {
return new Promise((resolve) => {
const audio = new Audio('https://cdn.reignofcomputer.com/dev/hey_listen.mp3');
audio.onended = resolve;
audio.play();
}).then(playSound);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment