Skip to content

Instantly share code, notes, and snippets.

@dvdbng
Last active August 18, 2016 14:34
Show Gist options
  • Save dvdbng/44f66d6f3ac0aa6389c1b8be46dbfd41 to your computer and use it in GitHub Desktop.
Save dvdbng/44f66d6f3ac0aa6389c1b8be46dbfd41 to your computer and use it in GitHub Desktop.
An userscript that shows a desktop notification when the status of a github PR changes
// ==UserScript==
// @name PR Notifications
// @namespace ghnotifications
// @description Show notifications when the status of a PR changes
// @include https://github.com/*
// @version 1
// @grant none
// ==/UserScript==
(function(){
if(Notification.permission !== 'denied' && Notification.permission !== 'granted') {
Notification.requestPermission();
}
function getState() {
var elm = document.querySelector('.merge-pr .branch-action');
var match = elm && elm.getAttribute('class').match(/\bbranch-action-state-(\w+)/);
return match && match[1];
}
var prevState = null;
setInterval(function(){
var newState = getState();
if(prevState && newState && prevState != newState) {
new Notification("Status changed from " + prevState + ' to ' + newState, {
body: document.title,
icon: 'https://github.com/apple-touch-icon.png'
});
}
prevState = newState;
}, 500);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment