Skip to content

Instantly share code, notes, and snippets.

@benjaminoakes
Last active April 27, 2017 18:52
Show Gist options
  • Save benjaminoakes/7b75366aa70ef882ff5a56383a0b8f11 to your computer and use it in GitHub Desktop.
Save benjaminoakes/7b75366aa70ef882ff5a56383a0b8f11 to your computer and use it in GitHub Desktop.
Travis CI Notifier - run from console on a build page and you'll see a notification when it's done
// Straight from MDN
function notifyMe(s) {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check whether notification permissions have already been granted
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification(s);
}
// Otherwise, we need to ask the user for permission
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// If the user accepts, let's create a notification
if (permission === "granted") {
var notification = new Notification(s);
}
});
}
// At last, if the user has denied notifications, and you
// want to be respectful there is no need to bother them any more.
}
function checkit() {
var classes = document.getElementsByClassName('build-status')[0].className;
console.log('classes: ' + classes);
if (!classes.match('started')) {
notifyMe("Travis CI build finished");
} else {
setTimeout(checkit, 3000);
}
}
checkit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment