2 <script type=
"text/javascript">
5 var prefs_last_updated =
0;
7 function param_escape(arg) {
8 if (typeof encodeURIComponent != 'undefined')
9 return encodeURIComponent(arg);
16 var login = localStorage[
"login"];
18 var requestUrl = localStorage[
"site_url"] +
"/backend.php";
19 var params =
"op=getUnread&login=" + param_escape(login);
21 var xhr = new XMLHttpRequest();
24 xhr.open(
"POST", requestUrl, true);
25 xhr.setRequestHeader(
"Content-type",
"application/x-www-form-urlencoded");
28 xhr.onreadystatechange = function() {
29 if (xhr.readyState ==
4) {
31 var icon = new Object();
32 var title = new Object();
34 if (xhr.status ==
200) {
35 var unread = parseInt(xhr.responseText);
38 icon.path =
"images/alert.png";
39 title.title =
"You have %s unread articles.".replace(
"%s", unread);
41 icon.path =
"images/normal.png";
42 title.title =
"You have no unread articles.";
45 localStorage[
"last_updated"] = d.getTime();
46 localStorage[
"last_error"] =
"";
48 localStorage[
"last_error"] = xhr.responseText;
50 icon.path =
"images/error.png";
51 title.title =
"Error (%s) while requesting article information.".replace(
"%s", xhr.status);
54 chrome.browserAction.setTitle(title);
55 chrome.browserAction.setIcon(icon);
67 if (localStorage[
"update_interval"])
68 update_interval = localStorage[
"update_interval"] *
60 *
1000;
70 update_interval =
15 *
60 *
1000;
72 if (localStorage[
"prefs_updated"])
73 prefs_updated = localStorage[
"prefs_updated"];
79 if (d.getTime()
> last_updated + update_interval ||
80 prefs_updated != prefs_last_updated) {
82 last_updated = d.getTime();
83 prefs_last_updated = prefs_updated;
91 window.setTimeout(
"timeout()",
1000);
96 chrome.browserAction.onClicked.addListener(function() {
97 var site_url = localStorage['site_url'];
100 var cp = new Object();
104 chrome.tabs.create(cp);
109 window.setTimeout(
"timeout()",
1000);
114 <body onload=
"init()"> </body>