Created
June 21, 2018 15:03
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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