Permalink
Browse files

Initial commit.

  • Loading branch information...
0 parents commit 0eec4c4af0435de7f6c69bd7e5d77a682a552319 beawesomeinstead committed Feb 22, 2011
Showing with 236 additions and 0 deletions.
  1. +72 −0 background.html
  2. BIN icon.png
  3. +17 −0 manifest.json
  4. +23 −0 options.html
  5. +124 −0 popup.html
  6. BIN travis.png
@@ -0,0 +1,72 @@
+<script>
+ var statusURL = "http://travis-ci.org/builds/last.json";
+
+ if (!localStorage.prefs) {
+ // Default to notifications being on.
+ localStorage.prefs = JSON.stringify({ "use_notifications": true });
+ }
+
+ var lastOpen = null;
+ var lastNotification = null;
+ function notifyIfStatusChange(open, status) {
+ var prefs = JSON.parse(localStorage.prefs);
+ if (lastOpen && lastOpen != open && prefs.use_notifications) {
+ if (lastNotification) {
+ lastNotification.cancel();
+ }
+ var notification = webkitNotifications.createNotification(
+ chrome.extension.getURL("icon.png"), "Tree is " + open, status);
+ lastNotification = notification;
+ notification.show();
+ }
+ lastOpen = open;
+ }
+
+ function updateStatus(status) {
+ chrome.browserAction.setTitle({title:status});
+ var open = /open/i;
+ if (open.exec(status)) {
+ notifyIfStatusChange("open", status);
+ chrome.browserAction.setBadgeText({text:"\u2022"});
+ chrome.browserAction.setBadgeBackgroundColor({color:[0,255,0,255]});
+ } else {
+ notifyIfStatusChange("closed", status);
+ //chrome.browserAction.setBadgeText("\u2639");
+ chrome.browserAction.setBadgeText({text:"\u00D7"});
+ chrome.browserAction.setBadgeBackgroundColor({color:[255,0,0,255]});
+ }
+ }
+
+ function requestStatus() {
+ requestURL(statusURL, updateStatus);
+ setTimeout(requestStatus, 30000);
+ }
+
+ function requestURL(url, callback) {
+ //console.log("requestURL: " + url);
+ var xhr = new XMLHttpRequest();
+ try {
+ xhr.onreadystatechange = function(state) {
+ if (xhr.readyState == 4) {
+ var text = xhr.responseText;
+ //console.log(text);
+ callback(text);
+ }
+ }
+
+ xhr.onerror = function(error) {
+ console.log("xhr error: " + JSON.stringify(error));
+ console.dir(error);
+ }
+
+ xhr.open("GET", url, true);
+ xhr.send({});
+ } catch(e) {
+ console.log("exception: " + e);
+ }
+ }
+
+ window.onload = function() {
+ window.setTimeout(requestStatus, 10);
+ }
+</script>
BIN icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,17 @@
+{
+ "name": "Travis Build Monitor",
+ "version": "0.1.0",
+ "description": "Displays the status of the build in the toolbar. Click to see more detailed status in a popup.",
+ "icons": { "128": "icon.png" },
+ "background_page": "background.html",
+ "permissions": [
+ "notifications",
+ "http://travis-ci.org/"
+ ],
+ "browser_action": {
+ "default_title": "",
+ "default_icon": "travis.png",
+ "popup": "popup.html"
+ },
+ "options_page": "options.html"
+}
@@ -0,0 +1,23 @@
+<!doctype html>
+<html>
+ <head>
+ <script>
+ function save() {
+ var prefs = JSON.parse(localStorage.prefs);
+ prefs.use_notifications = document.getElementById("notifications").checked;
+ localStorage.prefs = JSON.stringify(prefs);
+ }
+
+ // Make sure the checkbox checked state gets properly initialized from the
+ // saved preference.
+ window.onload = function() {
+ var prefs = JSON.parse(localStorage.prefs);
+ document.getElementById("notifications").checked = prefs.use_notifications;
+ }
+ </script>
+ </head>
+ <body>
+ <h2>Options</h2><br>
+ <p>Use desktop notifications: <input id="notifications" type="checkbox" onclick="save()"></p>
+ </body>
+</html>
@@ -0,0 +1,124 @@
+<head>
+ <script>
+ var botRoot = "http://travis-ci.org/";
+ var botList;
+ var checkinResults;
+ var bots;
+ var failures;
+
+ function updateBotList(text) {
+ var results = (new RegExp('(.*)<\/body>', 'g')).exec(text);
+ if (!results || results.index < 0) {
+ console.log("Error: couldn't find bot JSON");
+ console.log(text);
+ return;
+ }
+ var data;
+ try {
+ data = JSON.parse(results[1]);
+ } catch (e) {
+ console.dir(e);
+ console.log(text);
+ return;
+ }
+ if (!data) {
+ throw new Error("JSON parse fail: " + results[1]);
+ }
+ botList = data[0];
+ checkinResults = data[1];
+
+ failures = botList.filter(function(bot) {
+ return (bot.color != "success");
+ });
+ displayFailures();
+ }
+
+ function displayFailures() {
+ bots.innerText = "";
+
+ if (failures.length == 0) {
+ var anchor = document.createElement("a");
+ anchor.addEventListener("click", showConsole);
+ anchor.className = "open";
+ anchor.innerText = "The tree is completely green.";
+ bots.appendChild(anchor);
+ bots.appendChild(document.createTextNode(" (no way!)"));
+ } else {
+ var anchor = document.createElement("a");
+ anchor.addEventListener("click", showFailures);
+ anchor.innerText = "failures:";
+ var div = document.createElement("div");
+ div.appendChild(anchor);
+ bots.appendChild(div);
+
+ failures.forEach(function(bot, i) {
+ var div = document.createElement("div");
+ div.className = "bot " + bot.color;
+ div.addEventListener("click", function() {
+ // Requires closure for each iteration to retain local value of |i|.
+ return function() { showBot(i); }
+ }());
+ div.innerText = bot.title;
+ bots.appendChild(div);
+ });
+ }
+ }
+
+ function showBot(botIndex) {
+ var bot = failures[botIndex];
+ var url = botRoot + "builds/last.json?builder=" + bot.name;
+ window.open(url);
+ window.event.stopPropagation();
+ }
+
+ function requestURL(url, callback) {
+ console.log("requestURL: " + url);
+ var xhr = new XMLHttpRequest();
+ try {
+ xhr.onreadystatechange = function(state) {
+ if (xhr.readyState == 4) {
+ var text = xhr.responseText;
+ //console.log(text);
+ callback(text);
+ }
+ }
+
+ xhr.onerror = function(error) {
+ console.log("xhr error: " + JSON.stringify(error));
+ console.dir(error);
+ }
+
+ xhr.open("GET", url, true);
+ xhr.send({});
+ } catch(e) {
+ console.log("exception: " + e);
+ }
+ }
+ window.onload = function() {
+ bots = document.getElementById("bots");
+
+ // XHR from onload winds up blocking the load, so we put it in a setTimeout.
+ window.setTimeout(requestURL, 0, "builds/last.json", updateBotList);
+ }
+ </script>
+ <style>
+ body{ font-family:sans-serif; font-size:0.8em; overflow:hidden; }
+ #links{ background-color:#efefef; border:1px solid #ccc; -webkit-border-radius:5px; margin-top:1px; white-space:nowrap; text-align:center; padding:3px; }
+ a{ text-decoration:underline; color:#444; }
+ a:hover{ color:#000; cursor:pointer; }
+ body.big .bot{ -webkit-transition:all .5s ease-out; margin:20px; }
+ .bot{ cursor:pointer; -webkit-border-radius:5px; margin-top:1px; white-space:nowrap; padding:3px; }
+ .bot:hover{ border:2px solid #000; padding:2px; }
+ .open{ color:green; }
+ .closed{ color:red; }
+ .running{ background-color:#fffc6c; border:1px solid #c5c56d; }
+ .notstarted{ border:1px solid #aaa; }
+ .failure{ background-color:#e98080; border:1px solid #a77272; }
+ .warnings{ background-color:#ffc343; border:1px solid #c29d46; }
+ .success{ background-color:#8fdf5f; border:1px solid #4f8530; }
+ .exception{ background-color:#e0b0ff; border:1px solid #aca0b3; }
+ </style>
+</head>
+<body class="big">
+ <div id="bots">Loading....</div>
+</body>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0eec4c4

Please sign in to comment.