1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
<script>
var statusURL = "http://chromium-status.appspot.com/current";
function updateStatus(text) {
// Page outputs a line like this:
// <div class="Notice">Tree is open (issue -> person) </div>
// Although what's in the <div> is arbitrary and typed by a person.
var results = (new RegExp('"Notice"[^>]*>(.*)<', 'g')).exec(text);
if (!results || results.index < 0) {
throw new Error("couldn't find status div in " + text);
}
var status = results[1];
chrome.browserAction.setTitle({title:status});
var open = /open/i;
if (open.exec(status)) {
//chrome.browserAction.setBadgeText("\u263A");
chrome.browserAction.setBadgeText({text:"\u2022"});
chrome.browserAction.setBadgeBackgroundColor({color:[255,0,255,0]});
} else {
//chrome.browserAction.setBadgeText("\u2639");
chrome.browserAction.setBadgeText({text:"\u00D7"});
chrome.browserAction.setBadgeBackgroundColor({color:[255,255,0,0]});
}
}
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>
|