]> git.wh0rd.org Git - tt-rss.git/commitdiff
notifier: support showing fresh articles in the badge
authorAndrew Dolgov <fox@bah.org.ru>
Wed, 17 Feb 2010 13:38:51 +0000 (16:38 +0300)
committerAndrew Dolgov <fox@bah.org.ru>
Wed, 17 Feb 2010 13:38:51 +0000 (16:38 +0300)
utils/notifier/background.html
utils/notifier/manifest.json
utils/notifier/options.html

index 8a3acb2beb70b4779fd6cd91955cbd9e0c2645b5..fdca37e90fdc8814dbde6a5fd0d04f482fcd6a52 100644 (file)
@@ -16,7 +16,7 @@ function update() {
        var login = localStorage["login"];
 
        var requestUrl = localStorage["site_url"] + "/backend.php";
-       var params = "op=getUnread&login=" + param_escape(login);
+       var params = "op=getUnread&fresh=1&login=" + param_escape(login);
 
        var xhr = new XMLHttpRequest();
 
@@ -31,17 +31,36 @@ function update() {
                        var icon = new Object();
                        var title = new Object();
                        var badge = new Object();
+                       var badge_color = new Object();
 
-                       var showBadge = localStorage["show_badge"];
-
+                       var show_badge = localStorage["show_badge"] == "1";
+                       var show_fresh = localStorage["show_fresh"] == "1";
+               
                        if (xhr.status == 200) {
-                               var unread = parseInt(xhr.responseText);
-       
-                               if (unread > 0) {
+                               var response = xhr.responseText.split(";");
+
+                               var unread = parseInt(response[0]);
+
+                               var fresh;
+
+                               if (response.length == 2)
+                                       fresh = parseInt(response[1]);
+                               else
+                                       fresh = 0;
 
+                               if (unread > 0) {
                                        icon.path = "images/alert.png";
                                        title.title = "You have %s unread articles.".replace("%s", unread);
-                                       badge.text = unread + "";
+
+                                       if (show_fresh) {
+                                               badge.text = fresh + "";
+                                               badge_color.color = [0, 200, 0, 255];
+
+                                       } else {
+                                               badge.text = unread + "";
+                                               badge_color.color = [255, 0, 0, 255];
+                                       }
+
                                } else if (unread == -1) {
                                        icon.path = "images/error.png";         
 
@@ -65,10 +84,10 @@ function update() {
                                title.title = "Error (%s) while updating.".replace("%s", xhr.status);
                        }
 
-                       if (showBadge !== "1") badge.text = ""; 
+                       if (!show_badge) badge.text = "";       
 
+                       chrome.browserAction.setBadgeBackgroundColor(badge_color);
                        chrome.browserAction.setBadgeText(badge);
-
                        chrome.browserAction.setTitle(title);
                        chrome.browserAction.setIcon(icon);
 
index 206dffd49726159b187a305ef939bd33bf7f6083..9142910ceadd4058837f8eb4234d1fec324ad2b0 100644 (file)
@@ -1,7 +1,7 @@
 {
   "name": "Tiny Tiny RSS Notifier",
   "background_page": "background.html",
-  "version": "0.2.1",
+  "version": "0.3",
   "description": "This extension displays the number of unread articles in your Tiny Tiny RSS installation",
   "options_page": "options.html",
   "icons": { "48": "images/icon.png", "128": "images/icon.png" },
index d7becf222fe19c180a49cd03747895291caaa0e0..2988f41c80b3b2cb01a45dd6ee4b8dbe7cd3e4e6 100644 (file)
@@ -38,6 +38,7 @@ function save() {
        }
 
        localStorage['show_badge'] = (f.show_badge.checked) ? "1" : "0";
+       localStorage['show_fresh'] = (f.show_fresh.checked) ? "1" : "0";
 
        var d = new Date();
 
@@ -71,6 +72,11 @@ function init() {
        else
                f.show_badge.checked = true;
 
+       if (localStorage['show_fresh'])
+               f.show_fresh.checked = localStorage['show_fresh'] == "1";
+       else
+               f.show_fresh.checked = false;
+
        var last_updated = $('last_updated');
 
        var d = new Date();
@@ -106,6 +112,11 @@ label {
 p.last-updated {
        color : gray;
 }
+fieldset span.note {
+       color : gray;
+       font-style : italic;
+}
+
 </style>
 
 <body onload="init()">
@@ -140,6 +151,12 @@ p.last-updated {
                        <input name="show_badge" type="checkbox"  value="1"/>
                </fieldset>
 
+               <fieldset>
+                       <label>Badge shows fresh articles:</label>
+                       <input name="show_fresh" type="checkbox"  value="1"/>
+                       <span class="note">(requires Tiny Tiny RSS 1.4.1 or trunk)</span>
+               </fieldset>
+
                <input type="submit" value="Save"/>
        </form>