2010-02-17 11:26:25 +00:00
|
|
|
<html>
|
|
|
|
<script type="text/javascript">
|
|
|
|
|
|
|
|
var last_updated = 0;
|
2012-01-26 11:13:04 +00:00
|
|
|
var feeds_last_updated = 0;
|
2010-02-17 11:26:25 +00:00
|
|
|
var prefs_last_updated = 0;
|
|
|
|
|
|
|
|
function param_escape(arg) {
|
|
|
|
if (typeof encodeURIComponent != 'undefined')
|
|
|
|
return encodeURIComponent(arg);
|
|
|
|
else
|
|
|
|
return escape(arg);
|
|
|
|
}
|
|
|
|
|
2012-01-26 11:13:04 +00:00
|
|
|
function update_feeds() {
|
|
|
|
|
|
|
|
console.log("feeds update");
|
|
|
|
|
|
|
|
var requestUrl = localStorage["site_url"] + "/public.php?op=globalUpdateFeeds";
|
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
xhr.open("POST", requestUrl, true);
|
|
|
|
xhr.send();
|
|
|
|
|
|
|
|
var d = new Date();
|
|
|
|
localStorage["last_feeds_updated"] = d.getTime();
|
|
|
|
}
|
|
|
|
|
2010-02-17 11:26:25 +00:00
|
|
|
function update() {
|
2012-01-26 11:13:04 +00:00
|
|
|
console.log("update");
|
|
|
|
|
2010-02-17 11:26:25 +00:00
|
|
|
var d = new Date();
|
|
|
|
var login = localStorage["login"];
|
2010-02-19 20:33:15 +00:00
|
|
|
var single_user = localStorage["single_user"];
|
|
|
|
|
|
|
|
if (single_user == "1") login = "admin";
|
2010-02-17 11:26:25 +00:00
|
|
|
|
2012-01-26 09:12:14 +00:00
|
|
|
var requestUrl = localStorage["site_url"] + "/public.php";
|
2010-02-17 13:38:51 +00:00
|
|
|
var params = "op=getUnread&fresh=1&login=" + param_escape(login);
|
2010-02-17 11:26:25 +00:00
|
|
|
|
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
|
|
|
xhr.open("POST", requestUrl, true);
|
|
|
|
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
|
|
|
xhr.send(params);
|
|
|
|
|
|
|
|
xhr.onreadystatechange = function() {
|
|
|
|
if (xhr.readyState == 4) {
|
|
|
|
|
|
|
|
var icon = new Object();
|
|
|
|
var title = new Object();
|
2010-02-17 12:53:38 +00:00
|
|
|
var badge = new Object();
|
2010-02-17 13:38:51 +00:00
|
|
|
var badge_color = new Object();
|
2010-02-17 12:53:38 +00:00
|
|
|
|
2010-02-19 20:33:15 +00:00
|
|
|
// init stuff
|
|
|
|
icon.path = "images/normal.png";
|
|
|
|
title.title = "";
|
|
|
|
badge.text = "";
|
|
|
|
badge_color.color = [0, 0, 0, 0];
|
|
|
|
|
2010-02-17 13:38:51 +00:00
|
|
|
var show_badge = localStorage["show_badge"] == "1";
|
|
|
|
var show_fresh = localStorage["show_fresh"] == "1";
|
|
|
|
|
2010-02-17 11:26:25 +00:00
|
|
|
if (xhr.status == 200) {
|
2010-02-17 13:38:51 +00:00
|
|
|
var response = xhr.responseText.split(";");
|
|
|
|
|
|
|
|
var unread = parseInt(response[0]);
|
|
|
|
|
2010-02-19 20:33:15 +00:00
|
|
|
if (isNaN(unread)) unread = 0;
|
2010-02-17 13:38:51 +00:00
|
|
|
|
2010-02-19 20:33:15 +00:00
|
|
|
var fresh;
|
|
|
|
|
2010-02-17 13:38:51 +00:00
|
|
|
if (response.length == 2)
|
|
|
|
fresh = parseInt(response[1]);
|
|
|
|
else
|
|
|
|
fresh = 0;
|
2010-02-17 12:53:38 +00:00
|
|
|
|
2010-02-19 20:33:15 +00:00
|
|
|
if (isNaN(fresh)) fresh = 0;
|
|
|
|
|
2010-02-17 13:38:51 +00:00
|
|
|
if (unread > 0) {
|
2010-02-17 12:53:38 +00:00
|
|
|
icon.path = "images/alert.png";
|
2010-02-17 11:26:25 +00:00
|
|
|
title.title = "You have %s unread articles.".replace("%s", unread);
|
2010-02-17 13:38:51 +00:00
|
|
|
|
2010-02-19 20:33:15 +00:00
|
|
|
if (show_fresh && fresh > 0) {
|
2010-02-17 13:38:51 +00:00
|
|
|
badge.text = fresh + "";
|
|
|
|
badge_color.color = [0, 200, 0, 255];
|
|
|
|
} else {
|
|
|
|
badge.text = unread + "";
|
|
|
|
badge_color.color = [255, 0, 0, 255];
|
|
|
|
}
|
|
|
|
|
2010-02-17 12:53:38 +00:00
|
|
|
} else if (unread == -1) {
|
|
|
|
icon.path = "images/error.png";
|
|
|
|
|
|
|
|
var errorMsg = xhr.responseText.split(";")[1];
|
|
|
|
|
|
|
|
title.title = "Error: %s.".replace("%s", errorMsg.trim());
|
|
|
|
|
2010-02-17 11:26:25 +00:00
|
|
|
} else {
|
|
|
|
title.title = "You have no unread articles.";
|
|
|
|
}
|
|
|
|
|
|
|
|
localStorage["last_updated"] = d.getTime();
|
|
|
|
localStorage["last_error"] = "";
|
|
|
|
} else {
|
|
|
|
localStorage["last_error"] = xhr.responseText;
|
|
|
|
|
|
|
|
icon.path = "images/error.png";
|
2010-02-17 12:53:38 +00:00
|
|
|
title.title = "Error (%s) while updating.".replace("%s", xhr.status);
|
2010-02-17 11:26:25 +00:00
|
|
|
}
|
|
|
|
|
2010-02-17 13:38:51 +00:00
|
|
|
if (!show_badge) badge.text = "";
|
2010-02-17 12:53:38 +00:00
|
|
|
|
2010-02-17 13:38:51 +00:00
|
|
|
chrome.browserAction.setBadgeBackgroundColor(badge_color);
|
2010-02-17 12:53:38 +00:00
|
|
|
chrome.browserAction.setBadgeText(badge);
|
2010-02-17 11:26:25 +00:00
|
|
|
chrome.browserAction.setTitle(title);
|
|
|
|
chrome.browserAction.setIcon(icon);
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function timeout() {
|
|
|
|
|
|
|
|
var update_interval;
|
|
|
|
var prefs_updated;
|
2012-01-26 11:13:04 +00:00
|
|
|
var feeds_update_interval = 30 * 60 * 1000;
|
2010-02-17 11:26:25 +00:00
|
|
|
|
|
|
|
if (localStorage["update_interval"])
|
|
|
|
update_interval = localStorage["update_interval"] * 60 * 1000;
|
|
|
|
else
|
|
|
|
update_interval = 15 * 60 * 1000;
|
|
|
|
|
|
|
|
if (localStorage["prefs_updated"])
|
|
|
|
prefs_updated = localStorage["prefs_updated"];
|
|
|
|
else
|
|
|
|
prefs_updated = -1;
|
|
|
|
|
|
|
|
var d = new Date();
|
|
|
|
|
|
|
|
if (d.getTime() > last_updated + update_interval ||
|
|
|
|
prefs_updated != prefs_last_updated) {
|
|
|
|
|
|
|
|
last_updated = d.getTime();
|
|
|
|
try {
|
|
|
|
update();
|
|
|
|
} catch (e) {
|
2012-01-26 11:13:04 +00:00
|
|
|
console.warn(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (localStorage['update_feeds'] == 1 && (d.getTime() > feeds_last_updated + feeds_update_interval || prefs_updated != prefs_last_updated)) {
|
|
|
|
|
|
|
|
feeds_last_updated = d.getTime();
|
|
|
|
|
|
|
|
try {
|
|
|
|
update_feeds();
|
|
|
|
} catch (e) {
|
|
|
|
console.warn(e);
|
2010-02-17 11:26:25 +00:00
|
|
|
}
|
2012-01-26 11:13:04 +00:00
|
|
|
|
2010-02-17 11:26:25 +00:00
|
|
|
}
|
|
|
|
|
2012-01-26 11:13:04 +00:00
|
|
|
prefs_last_updated = prefs_updated;
|
|
|
|
|
2010-02-17 11:26:25 +00:00
|
|
|
window.setTimeout("timeout()", 1000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function init() {
|
|
|
|
|
|
|
|
chrome.browserAction.onClicked.addListener(function() {
|
|
|
|
var site_url = localStorage['site_url'];
|
|
|
|
|
|
|
|
if (site_url) {
|
|
|
|
var cp = new Object();
|
|
|
|
|
|
|
|
cp.url = site_url;
|
|
|
|
|
|
|
|
chrome.tabs.create(cp);
|
|
|
|
}
|
|
|
|
|
2010-02-17 12:53:38 +00:00
|
|
|
});
|
2010-02-17 11:26:25 +00:00
|
|
|
|
|
|
|
window.setTimeout("timeout()", 1000);
|
|
|
|
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<body onload="init()"> </body>
|
|
|
|
|
|
|
|
</html>
|