Created
March 14, 2017 12:39
-
-
Save herejia/3733afcfdcedc81aacd39ba2dd4ef012 to your computer and use it in GitHub Desktop.
This file contains 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
// ==UserScript== | |
// @name jenkins-html5-notifier | |
// @namespace net.herezia | |
// @description Uses HTML5 notifications to show jenkins build result | |
// @include *jenkins*/console | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
const buildImageElement = document.querySelector('.build-caption > img'); | |
if (!buildImageElement) { | |
return; | |
} | |
const spinner = document.querySelector('#spinner'); | |
const hasEnded = () => !spinner || spinner.style.display === 'none'; | |
const currentStatus = () => hasEnded() ? 'Ended' : buildImageElement.getAttribute('alt') | |
Notification.requestPermission(); | |
let lastStatus = currentStatus(); | |
let intervalId = setInterval(() => { | |
if (lastStatus !== currentStatus()) { | |
lastStatus = currentStatus(); | |
notifyBuildStatus(); | |
} | |
if (hasEnded()) { | |
clearInterval(intervalId); | |
} | |
}, 800); | |
function notifyBuildStatus() { | |
let jobDescription = Array.from(document.querySelectorAll('#breadcrumbs > .item a')) | |
.map(anchorElement => anchorElement.innerHTML) | |
.slice(-3) | |
.join(' '); | |
new Notification('Jenkins job status update', { | |
icon: buildImageElement.getAttribute('src'), | |
body: `${currentStatus()} : ${jobDescription}`, | |
renotify: true, | |
requireInteraction: true | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tested on Jenkins ver.
2.19.3