Skip to content

Instantly share code, notes, and snippets.

@rayfranco
Created June 21, 2018 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayfranco/060ec85bc80e8078ea185e9ef058bffc to your computer and use it in GitHub Desktop.
Save rayfranco/060ec85bc80e8078ea185e9ef058bffc to your computer and use it in GitHub Desktop.
Check for status code change periodically. Designed to be pasted in Chrome Dev Tools to bypass any CORS issues.
function check (DELAY_MINUTE = 1, RESPONSE_CODE = 200) {
var req = new XMLHttpRequest()
req.addEventListener('load', onLoad)
function open () {
req.open('HEAD', location.href, true)
req.send()
}
function onLoad () {
req.status === RESPONSE_CODE ? notify() : setTimeout(open, DELAY_MINUTE * 60 * 1000)
}
function notify() {
const str = `Yay! ${location.href} is available!`
Notification.permission === 'granted' ? new Notification(str, { sticky: true }) : alert(str)
}
Notification.requestPermission((permission) => {
open()
})
window.onbeforeunload = function(e) {
return e.returnValue = 'Work in progress, sure you wanna quit?'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment