Skip to content

Instantly share code, notes, and snippets.

@pawlik
Last active January 12, 2017 08:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawlik/6d58f8659675ec037540c824670fab34 to your computer and use it in GitHub Desktop.
Save pawlik/6d58f8659675ec037540c824670fab34 to your computer and use it in GitHub Desktop.
(function() {
// Updates GitHub favicon on pull request pages depending on it's check's status
// if the last checked status was 'pending'
// it will refresh every 5 minutes if you leave the tab
// and will refresh once more when you re-enter it
// if the status was 'success' or 'failure' - it will just update the favicon
is_pending = function() { return !!document.querySelector('.donut-chart>.pending'); };
is_failure = function() { return !!document.querySelector('.donut-chart>.failure'); };
update_favicon = function() {
pending = is_pending();
failure = is_failure();
pending_ico = 'https://cloud.githubusercontent.com/assets/61051/21805979/615b9d54-d737-11e6-8eb5-f473f3167e60.png';
failure_ico = 'https://cloud.githubusercontent.com/assets/61051/21805980/615bd44a-d737-11e6-8f7e-d3e8e8382712.png';
success_ico = 'https://cloud.githubusercontent.com/assets/61051/21805981/615c29b8-d737-11e6-8c2e-684742e5da9a.png';
link = document.querySelector("link[rel='icon']");
if(pending) {
link.href = pending_ico;
} else if(failure) {
link.href = failure_ico;
} else {
link.href = success_ico;
}
document.getElementsByTagName('head')[0].appendChild(link);
};
update_favicon();
refresh_rate = 5 * 60 * 1000;
if(is_pending()) {
if(document.hidden) {
setTimeout(function() { window.location.reload(true) }, refresh_rate);
}
document.addEventListener('visibilitychange', function(){
if(document.hidden) {
setTimeout(function() { window.location.reload(true) },refresh_rate);
} else {
window.location.reload(true);
}
});
}
})();
@pawlik
Copy link
Author

pawlik commented Jan 10, 2017

2017-01-10_15 02 09_

icons:
favicon-pending
favicon-success
favicon-failure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment