Skip to content
This repository was archived by the owner on Jul 19, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ You can [install](https://chrome.google.com/extensions/detail/lnalnbkkohdcnaapee

## Changelog

### Version 0.3.2
* add 2 minutes intervall (I am so impatient)
* add desktop notifications

### Version 0.3.1

* _Feature:_ When sorting jobs by status, jobs with the same status are now ordered alphabetically
Expand Down
93 changes: 81 additions & 12 deletions background.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,13 @@
var refreshTimer;
var jobs;
var xhr;
var previousResponse;
var showNotification;

function init() {
desc = localStorage.desc == 'true';
green = localStorage.green == 'true';
showNotification = localStorage.showNotification == 'true';
if (!localStorage.url) {
updateStatus(-1);
jobs = null;
Expand Down Expand Up @@ -72,12 +75,66 @@
handleError(e);
}
}

function color2state(color) {
switch(color) {
case 'green_anime':
case 'blue_anime':
case 'green':
case 'blue':
return "OK";
case 'red_anime':
case 'red':
return "FAILED";
}
return color;
}

// Displays a notification popup
function notify(message) {
try {
var notification = webkitNotifications.createNotification("./images/icon48.png", "Hudson", message);
var timeout = 15;

notification.show();
if( localStorage.showNotificationTime ) {
setTimeout(function () { notification.cancel(); }, localStorage.showNotificationTime * 1000);
}

} catch (e) {
alert("error displaying notification");
}
}


function checkResponse() {
if (xhr.readyState != 4) return;

if (xhr.status == 200 && xhr.responseText) {
var response = JSON.parse(xhr.responseText);

if( previousResponse ) {
var previousJobs = previousResponse.jobs;
var previousStates = {};

for(i in previousJobs) {
job = previousJobs[i];
previousStates[job.name] = job.color;
}
var message = "";
for(i in response.jobs) {
job = response.jobs[i];
if(color2state(job.color) != color2state(previousStates[job.name])) {
//message += "<br/>" + job.name + ": " + color2state(previousStates[job.name]) + " -> " + color2state(job.color);
message += job.name + ": " + color2state(previousStates[job.name]) + " -> " + color2state(job.color) + "\n";
}
}
if(message != "") {
notify(message)
}
}

previousResponse = response;
var topStatus = -1;
if (response.jobs) {
jobs = response.jobs;
Expand Down Expand Up @@ -150,16 +207,29 @@
}
}

function openTab() {
chrome.tabs.getAllInWindow(undefined, function(tabs) {
for (var i = 0, tab; tab = tabs[i]; i++) {
if (tab.url && tab.url.indexOf(localStorage.url) == 0) {
chrome.tabs.update(tab.id, {selected: true});
return;
}
}
chrome.tabs.create({url: localStorage.url});
});
// This code was written by Tyler Akins and has been placed in the
// public domain. It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com
function base64(input) {
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2))
enc3 = enc4 = 64;
else if (isNaN(chr3))
enc4 = 64;
output += (keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4));
}
return output;
}

window.onload = function() {
Expand All @@ -168,4 +238,3 @@
</script>
</head>
</html>

2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Hudson Monitor",
"version": "0.3.1",
"version": "0.3.2",
"description": "This extension can monitor your Hudson CI server",
"icons": { "16": "images/icon16.png",
"32": "images/icon32.png",
Expand Down
79 changes: 77 additions & 2 deletions options.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
var urlInput;
var errorImage;
var refreshDropdown;
var showNotificationTimeDropdown;
var authCheckbox;
var usernameInput;
var passwordInput;
Expand All @@ -42,6 +43,15 @@
errorImage.style.visibility = 'hidden';
}

showNotificationTimeDropdown = document.getElementById('showNotificationTimeDropdown');
var showNotificationTime = localStorage.showNotificationTime || 0;
for (var i = 0; i < showNotificationTimeDropdown.options.length; i++) {
if (showNotificationTimeDropdown.options[i].value == showNotificationTime) {
showNotificationTimeDropdown.selectedIndex = i;
break;
}
}

refreshDropdown = document.getElementById('refresh');
var refreshTime = localStorage.refreshTime || REFRESH_DEFAULT;
for (var i = 0; i < refreshDropdown.options.length; i++) {
Expand All @@ -54,6 +64,7 @@
authCheckbox = document.getElementById('auth');
usernameInput = document.getElementById('username');
passwordInput = document.getElementById('password');
showNotification = document.getElementById('showNotification');
if (typeof localStorage.username == 'string') {
authCheckbox.checked = true;
usernameInput.value = localStorage.username || '';
Expand All @@ -80,9 +91,38 @@
greenBalls = document.getElementById('greenBalls');
if (typeof localStorage.green == 'string')
greenBalls.checked = true;

showNotification = document.getElementById('showNotification');
if( localStorage.showNotification == 'true' )
showNotification.checked = true;


markClean();
}

function requestUserPermission() {
try {
var checkboxUserPermission = document.getElementById('showNotification');
if (checkboxUserPermission.checked) {
if (checkUserPermission())
return;

if (typeof webkitNotifications != "undefined") {
webkitNotifications.requestPermission(function () {
var permissionGranted = checkUserPermission();
checkboxUserPermission.checked = permissionGranted;
});
}
}
} catch (e) { checkboxUserPermission.checked = false; alert("error getting permissions");}
}

function checkUserPermission() {
try {
return (webkitNotifications.checkPermission() == 0);
} catch (e) { return false; }
}


function save() {
if (urlInput.value != '' && urlInput.value != 'http://') {
Expand All @@ -91,6 +131,12 @@
delete localStorage.url;
}

if (showNotificationTimeDropdown.value != "0") {
localStorage.showNotificationTime = showNotificationTimeDropdown.value;
} else {
delete localStorage.showNotificationTime;
}

if (refreshDropdown.value != REFRESH_DEFAULT) {
localStorage.refreshTime = refreshDropdown.value;
} else {
Expand Down Expand Up @@ -122,6 +168,12 @@
delete localStorage.green;
}

if (showNotification.checked == true) {
localStorage.showNotification = 'true';
} else {
localStorage.showNotification = 'false';
}

init();
chrome.extension.getBackgroundPage().init();
}
Expand All @@ -140,7 +192,7 @@
usernameInput.disabled = true;
passwordInput.disabled = true;
}

saveButton.disabled = false;
}

Expand All @@ -164,6 +216,7 @@ <h2>Options</h2>
<td><label for="refresh">Refresh Time</label></td>
<td colspan="2">
<select id="refresh" name="refresh" onchange="markDirty()">
<option value="2">2 Minutes</option>
<option value="5">5 Minutes</option>
<option value="10">10 Minutes</option>
<option value="15">15 Minutes</option>
Expand All @@ -180,6 +233,29 @@ <h2>Options</h2>
</td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Notifications</legend>
<table>
<tr>
<td>
<input type="checkbox" id="showNotification" onchange="markDirty();requestUserPermission();" /><label for="show_notification">Show desktop notifications</label>
</td>
</tr>
<tr>
<td><label for="showNotificationTimeDropdown">Hide notification after:</label></td>
<td colspan="2">
<select id="showNotificationTimeDropdown" name="showNotificationTimeDropdown" onchange="markDirty()">
<option value="0">never hide</option>
<option value="5">5 seconds</option>
<option value="15">15 seconds</option>
<option value="30">30 seconds</option>
<option value="60">1 minute</option>
<option value="300">5 minutes</option>
</select>
</td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>
Expand Down Expand Up @@ -230,4 +306,3 @@ <h2>Options</h2>
</div>
</body>
</html>