]> git.wh0rd.org - tt-rss.git/blobdiff - functions.js
unify update_daemon, update_feeds and update_feedbrowser into update.php; move update...
[tt-rss.git] / functions.js
index b2bd2a9efc7289dc379d7f893069455b9eeb7efa..ae7ecee35e311d38ac875b5bd603a87739cfaeb1 100644 (file)
@@ -2,6 +2,7 @@ var hotkeys_enabled = true;
 var notify_silent = false;
 var last_progress_point = 0;
 var async_counters_work = false;
+var sanity_check_done = false;
 
 /* add method to remove element from array */
 
@@ -11,14 +12,17 @@ Array.prototype.remove = function(s) {
        }
 }
 
-function is_opera() {
-       return window.opera;
-}
+/* create console.log if it doesn't exist */
+
+if (!window.console) console = {};
+console.log = console.log || function(msg) { };
+console.warn = console.warn || function(msg) { };
+console.error = console.error || function(msg) { };
 
 function exception_error(location, e, ext_info) {
        var msg = format_exception_error(location, e);
 
-       if (!ext_info) ext_info = "N/A";
+       if (!ext_info) ext_info = false;
 
        disableHotkeys();
 
@@ -39,9 +43,15 @@ function exception_error(location, e, ext_info) {
        
                        ebc.innerHTML = 
                                "<div><b>Error message:</b></div>" +
-                               "<pre>" + msg + "</pre>" +
-                               "<div><b>Additional information:</b></div>" +
+                               "<pre>" + msg + "</pre>";
+
+                       if (ext_info) {
+                               ebc.innerHTML += "<div><b>Additional information:</b></div>" +
                                "<textarea readonly=\"1\">" + ext_info + "</textarea>";
+                       }
+
+                       ebc.innerHTML += "<div><b>Stack trace:</b></div>" +
+                               "<textarea readonly=\"1\">" + e.stack + "</textarea>";
        
                } else {
                        alert(msg);
@@ -70,7 +80,7 @@ function format_exception_error(location, e) {
                msg = "Exception: " + e + "\nFunction: " + location + "()";
        }
 
-       debug("<b>EXCEPTION: " + msg + "</b>");
+       console.error("EXCEPTION: " + msg);
 
        return msg;
 }
@@ -162,13 +172,13 @@ function notify_real(msg, no_hide, n_type) {
                n.className = "notify";
        } else if (n_type == 2) {
                n.className = "notifyProgress";
-               msg = "<img src='images/indicator_white.gif'> " + msg;
+               msg = "<img src='"+getInitParam("sign_progress")+"'> " + msg;
        } else if (n_type == 3) {
                n.className = "notifyError";
-               msg = "<img src='images/sign_excl.gif'> " + msg;
+               msg = "<img src='"+getInitParam("sign_excl")+"'> " + msg;
        } else if (n_type == 4) {
                n.className = "notifyInfo";
-               msg = "<img src='images/sign_info.gif'> " + msg;
+               msg = "<img src='"+getInitParam("sign_info")+"'> " + msg;
        }
 
 //     msg = "<img src='images/live_com_loading.gif'> " + msg;
@@ -313,7 +323,7 @@ function setCookie(name, value, lifetime, path, domain, secure) {
                d.setTime(d.getTime() + (lifetime * 1000));
        }
 
-       debug("setCookie: " + name + " => " + value + ": " + d);
+       console.log("setCookie: " + name + " => " + value + ": " + d);
        
        int_setCookie(name, value, d, path, domain, secure);
 
@@ -356,39 +366,6 @@ function getCookie(name) {
        return unescape(dc.substring(begin + prefix.length, end));
 }
 
-function disableContainerChildren(id, disable, doc) {
-
-       if (!doc) doc = document;
-
-       var container = $(id);
-
-       if (!container) {
-               //alert("disableContainerChildren: element " + id + " not found");
-               return;
-       }
-
-       for (var i = 0; i < container.childNodes.length; i++) {
-               var child = container.childNodes[i];
-
-               try {
-                       child.disabled = disable;
-               } catch (E) {
-
-               }
-
-               if (disable) {
-                       if (child.className && child.className.match("button")) {
-                               child.className = "disabledButton";
-                       }
-               } else {
-                       if (child.className && child.className.match("disabledButton")) {
-                               child.className = "button";
-                       }
-               } 
-       }
-
-}
-
 function gotoPreferences() {
        document.location.href = "prefs.php";
 }
@@ -406,18 +383,18 @@ function parse_counters(reply, scheduled_call) {
 
                var feeds_found = 0;
 
-               var elems = reply.getElementsByTagName("counter");
+               var elems = JSON.parse(reply.firstChild.nodeValue);
 
                for (var l = 0; l < elems.length; l++) {
 
-                       var id = elems[l].getAttribute("id");
-                       var t = elems[l].getAttribute("type");
-                       var ctr = elems[l].getAttribute("counter");
-                       var error = elems[l].getAttribute("error");
-                       var has_img = elems[l].getAttribute("hi");
-                       var updated = elems[l].getAttribute("updated");
-                       var title = elems[l].getAttribute("title");
-                       var xmsg = elems[l].getAttribute("xmsg");
+                       var id = elems[l].id
+                       var kind = elems[l].kind;
+                       var ctr = parseInt(elems[l].counter)
+                       var error = elems[l].error;
+                       var has_img = elems[l].has_img;
+                       var updated = elems[l].updated;
+                       var title = elems[l].title;
+                       var xmsg = elems[l].xmsg;
        
                        if (id == "global-unread") {
 
@@ -435,7 +412,7 @@ function parse_counters(reply, scheduled_call) {
                                continue;
                        }
        
-                       if (t == "category") {
+                       if (kind && kind == "cat") {
                                var catctr = $("FCATCTR-" + id);
                                if (catctr) {
                                        catctr.innerHTML = "(" + ctr + ")";
@@ -483,7 +460,7 @@ function parse_counters(reply, scheduled_call) {
 
                        if (has_img && feed_img) {
                                if (!feed_img.src.match(id + ".ico")) {
-                                       feed_img.src = getInitParam("icons_location") + "/" + id + ".ico";
+                                       feed_img.src = getInitParam("icons_url") + "/" + id + ".ico";
                                }
                        }
 
@@ -526,7 +503,8 @@ function parse_counters(reply, scheduled_call) {
                                                
                                        }
 
-                                       if (row_needs_hl && getInitParam("theme") != 'neon') { 
+                                       if (row_needs_hl && 
+                                                       !getInitParam("theme_options").match('no_highlights')) { 
                                                new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
                                                        queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
 
@@ -543,13 +521,13 @@ function parse_counters(reply, scheduled_call) {
 
                var feeds_stored = number_of_feeds;
 
-               debug("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
+               console.log("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
 
                if (feeds_stored != feeds_found) {
                        number_of_feeds = feeds_found;
 
                        if (feeds_stored != 0 && feeds_found != 0) {
-                               debug("Subscribed feed number changed, refreshing feedlist");
+                               console.log("Subscribed feed number changed, refreshing feedlist");
                                setTimeout('updateFeedList(false, false)', 50);
                        }
                } else {
@@ -584,11 +562,13 @@ function parse_counters_reply(transport, scheduled_call) {
 
        var counters = reply.getElementsByTagName("counters")[0];
        
-       parse_counters(counters, scheduled_call);
+       if (counters)
+               parse_counters(counters, scheduled_call);
 
        var runtime_info = reply.getElementsByTagName("runtime-info")[0];
 
-       parse_runtime_info(runtime_info);
+       if (runtime_info)
+               parse_runtime_info(runtime_info);
 
        if (feedsSortByUnread()) {
                resort_feedlist();
@@ -601,12 +581,9 @@ function parse_counters_reply(transport, scheduled_call) {
 function all_counters_callback2(transport, async_call) {
        try {
                if (async_call) async_counters_work = true;
-               
                if (offline_mode) return;
 
-               debug("<b>all_counters_callback2 IN: " + transport + "</b>");
                parse_counters_reply(transport);
-               debug("<b>all_counters_callback2 OUT: " + transport + "</b>");
 
        } catch (e) {
                exception_error("all_counters_callback2", e, transport);
@@ -657,7 +634,7 @@ function resort_category(node, cat_mode) {
 
        try {
 
-               debug("resort_category: " + node + " CM=" + cat_mode);
+               console.log("resort_category: " + node + " CM=" + cat_mode);
        
                var by_unread = feedsSortByUnread();
        
@@ -673,8 +650,10 @@ function resort_category(node, cat_mode) {
                                var tmp_name = get_feed_entry_name(list[i]);
                                var cur_name = get_feed_entry_name(list[j]);
 
-                               var valid_pair = cat_mode || (list[i].id.match(/FEEDR-[0-9]/) &&
-                                               list[j].id.match(/FEEDR-[0-9]/));
+                               /* we don't want to match FEEDR-0 - e.g. Archived articles */
+
+                               var valid_pair = cat_mode || (list[i].id.match(/FEEDR-[1-9]/) &&
+                                               list[j].id.match(/FEEDR-[1-9]/));
 
                                if (valid_pair && ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name)))) {
                                        tempnode_i = list[i].cloneNode(true);
@@ -692,7 +671,7 @@ function resort_category(node, cat_mode) {
 }
 
 function resort_feedlist() {
-       debug("resort_feedlist");
+       console.log("resort_feedlist");
 
        if ($("FCATLIST--1")) {
 
@@ -747,7 +726,7 @@ function hideOrShowFeeds(hide) {
 
        try {
 
-       debug("hideOrShowFeeds: " + hide);
+       console.log("hideOrShowFeeds: " + hide);
 
        if ($("FCATLIST--1")) {
 
@@ -784,16 +763,16 @@ function hideOrShowFeedsCategory(id, hide) {
                        node = $("feedList"); // no categories
                }
 
-       //      debug("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
+       //      console.log("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
        
                var cat_unread = 0;
        
                if (!node) {
-                       debug("hideOrShowFeeds: passed node is null, aborting");
+                       console.log("hideOrShowFeeds: passed node is null, aborting");
                        return;
                }
        
-       //      debug("cat: " + node.id);
+       //      console.log("cat: " + node.id);
        
                if (node.hasChildNodes() && node.firstChild.nextSibling != false) {  
                        for (i = 0; i < node.childNodes.length; i++) {
@@ -808,7 +787,7 @@ function hideOrShowFeedsCategory(id, hide) {
                                                node.childNodes[i].className != "error" && 
                                                node.childNodes[i].className != "tag");
                
-       //                              debug(node.childNodes[i].id + " --> " + has_unread);
+       //                              console.log(node.childNodes[i].id + " --> " + has_unread);
                
                                        if (hide && !has_unread) {
                                                //node.childNodes[i].style.display = "none";
@@ -832,13 +811,13 @@ function hideOrShowFeedsCategory(id, hide) {
                        }
                }       
        
-       //      debug("end cat: " + node.id + " unread " + cat_unread);
+       //      console.log("end cat: " + node.id + " unread " + cat_unread);
 
                if (cat_node) {
 
                        if (cat_unread == 0) {
                                if (cat_node.style == undefined) {
-                                       debug("ERROR: supplied cat_node " + cat_node + 
+                                       console.log("ERROR: supplied cat_node " + cat_node + 
                                                " has no styles. WTF?");
                                        return;
                                }
@@ -853,12 +832,12 @@ function hideOrShowFeedsCategory(id, hide) {
                                try {
                                        cat_node.style.display = "list-item";
                                } catch (e) {
-                                       debug(e);
+                                       console.log(e);
                                }
                        }
                }
 
-//     debug("unread for category: " + cat_unread);
+//     console.log("unread for category: " + cat_unread);
 
        } catch (e) {
                exception_error("hideOrShowFeedsCategory", e);
@@ -899,7 +878,7 @@ function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
        var content = $(content_id);
 
        if (!content) {
-               alert("[selectTableRows] Element " + content_id + " not found.");
+               console.log("[selectTableRows] Element " + content_id + " not found.");
                return;
        }
 
@@ -947,8 +926,8 @@ function getSelectedTableRowIds(content_id, prefix) {
        var content = $(content_id);
 
        if (!content) {
-               alert("[getSelectedTableRowIds] Element " + content_id + " not found.");
-               return;
+               console.log("[getSelectedTableRowIds] Element " + content_id + " not found.");
+               return new Array();
        }
 
        var sel_rows = new Array();
@@ -1115,71 +1094,6 @@ function getRelativeFeedId2(id, is_cat, direction, unread_only) {
        }
 }
 
-
-function getRelativeFeedId(list, id, direction, unread_only) { 
-       var rows = list.getElementsByTagName("LI");
-       var feeds = new Array();
-
-       for (var i = 0; i < rows.length; i++) {
-               if (rows[i].id.match("FEEDR-")) {
-
-                       if (rows[i].id == "FEEDR-" + id || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
-
-                               if (!unread_only || 
-                                               (rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
-                                       feeds.push(rows[i].id.replace("FEEDR-", ""));
-                               }
-                       }
-               }
-       }
-
-       if (!id) {
-               if (direction == "next") {
-                       return feeds.shift();
-               } else {
-                       return feeds.pop();
-               }
-       } else {
-               if (direction == "next") {
-                       var idx = feeds.indexOf(id);
-                       if (idx != -1 && idx < feeds.length) {
-                               return feeds[idx+1];                                    
-                       } else {
-                               return getRelativeFeedId(list, false, direction, unread_only);
-                       }
-               } else {
-                       var idx = feeds.indexOf(id);
-                       if (idx > 0) {
-                               return feeds[idx-1];
-                       } else {
-                               return getRelativeFeedId(list, false, direction, unread_only);
-                       }
-               }
-
-       }
-}
-
-function showBlockElement(id, h_id) {
-       var elem = $(id);
-
-       if (elem) {
-               elem.style.display = "block";
-
-               if (h_id) {
-                       elem = $(h_id);
-                       if (elem) {
-                               elem.style.display = "none";
-                       }
-               }
-       } else {
-               alert("[showBlockElement] can't find element with id " + id);
-       } 
-}
-
-function appearBlockElement_afh(effect) {
-
-}
-
 function checkboxToggleElement(elem, id) {
        if (elem.checked) {
                Effect.Appear(id, {duration : 0.5});
@@ -1188,23 +1102,6 @@ function checkboxToggleElement(elem, id) {
        }
 }
 
-function appearBlockElement(id, h_id) {
-
-       try {
-               if (h_id) {
-                       Effect.Fade(h_id);
-               }
-               Effect.SlideDown(id, {duration : 1.0, afterFinish: appearBlockElement_afh});
-       } catch (e) {
-               exception_error("appearBlockElement", e);
-       }
-
-}
-
-function hideParentElement(e) {
-       e.parentNode.style.display = "none";
-}
-
 function dropboxSelect(e, v) {
        for (i = 0; i < e.length; i++) {
                if (e[i].value == v) {
@@ -1244,6 +1141,14 @@ function leading_zero(p) {
        return s;
 }
 
+function make_timestamp() {
+       var d = new Date();
+
+       return leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
+                       ":" + leading_zero(d.getSeconds());
+}
+
+
 function closeErrorBox() {
 
        if (Element.visible("errorBoxShadow")) {
@@ -1265,7 +1170,7 @@ function closeInfoBox(cleanup) {
                        Element.hide("dialog_overlay");
                        Element.hide("infoBoxShadow");
 
-                       if (cleanup) $("infoBoxShadow").innerHTML = "&nbsp;";
+                       if (cleanup) $("infoBox").innerHTML = "&nbsp;";
                }
        } catch (e) {
                exception_error("closeInfoBox", e);
@@ -1312,7 +1217,7 @@ function infobox_submit_callback2(transport) {
 function infobox_callback2(transport) {
        try {
 
-               debug("infobox_callback2");
+               console.log("infobox_callback2");
 
                var box = $('infoBox');
                
@@ -1388,7 +1293,7 @@ function subscribeToFeed() {
 
        var query = Form.serialize("feed_add_form");
        
-       debug("subscribe q: " + query);
+       console.log("subscribe q: " + query);
 
        Form.disable("feed_add_form");
 
@@ -1416,6 +1321,7 @@ function subscribeToFeed() {
                                }
                                break;
                        case 2:
+                       case 3:
                                alert(__("Can't subscribe to the specified URL."));
                                break;
                        case 0:
@@ -1453,30 +1359,6 @@ function filterCR(e, f)
        }
 }
 
-var debug_last_class = "even";
-
-function debug(msg) {
-
-       if (debug_last_class == "even") {
-               debug_last_class = "odd";
-       } else {
-               debug_last_class = "even";
-       }
-
-       var c = $('debug_output');
-       if (c && Element.visible(c)) {
-               while (c.lastChild != 'undefined' && c.childNodes.length > 100) {
-                       c.removeChild(c.lastChild);
-               }
-       
-               var d = new Date();
-               var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) +
-                       ":" + leading_zero(d.getSeconds());
-               c.innerHTML = "<li class=\"" + debug_last_class + "\"><span class=\"debugTS\">[" + ts + "]</span> " + 
-                       msg + "</li>" + c.innerHTML;
-       }
-}
-
 function getInitParam(key) {
        return init_params[key];
 }
@@ -1493,7 +1375,7 @@ function fatalError(code, msg, ext_info) {
                if (code == 6) {
                        window.location.href = "tt-rss.php";                    
                } else if (code == 5) {
-                       window.location.href = "update.php";
+                       window.location.href = "db-updater.php";
                } else {
        
                        if (msg == "") msg = "Unknown error";
@@ -1553,7 +1435,7 @@ function filterDlgCheckType(sender) {
                }
 
                if (!form) {
-                       debug("filterDlgCheckType: can't find form!");
+                       console.log("filterDlgCheckType: can't find form!");
                        return;
                }
 
@@ -1586,14 +1468,14 @@ function filterDlgCheckAction(sender) {
                }
 
                if (!form) {
-                       debug("filterDlgCheckAction: can't find form!");
+                       console.log("filterDlgCheckAction: can't find form!");
                        return;
                }
 
                var action_param = $("filter_dlg_param_box");
 
                if (!action_param) {
-                       debug("filterDlgCheckAction: can't find action param box!");
+                       console.log("filterDlgCheckAction: can't find action param box!");
                        return;
                }
 
@@ -1626,7 +1508,7 @@ function filterDlgCheckDate() {
                }
 
                if (!form) {
-                       debug("filterDlgCheckAction: can't find form!");
+                       console.log("filterDlgCheckAction: can't find form!");
                        return;
                }
 
@@ -1676,7 +1558,7 @@ function getRelativePostIds(id, limit) {
 
        if (!limit) limit = 3;
 
-       debug("getRelativePostIds: " + id + " limit=" + limit);
+       console.log("getRelativePostIds: " + id + " limit=" + limit);
 
        var ids = new Array();
        var container = $("headlinesList");
@@ -1708,12 +1590,12 @@ function getRelativePostIds(id, limit) {
 
 function openArticleInNewWindow(id) {
        try {
-               debug("openArticleInNewWindow: " + id);
+               console.log("openArticleInNewWindow: " + id);
 
                var query = "?op=rpc&subop=getArticleLink&id=" + id;
                var wname = "ttrss_article_" + id;
 
-               debug(query + " " + wname);
+               console.log(query + " " + wname);
 
                var w = window.open("", wname);
 
@@ -1726,13 +1608,13 @@ function openArticleInNewWindow(id) {
                                        var link = transport.responseXML.getElementsByTagName("link")[0];
                                        var id = transport.responseXML.getElementsByTagName("id")[0];
                
-                                       debug("open_article received link: " + link);
+                                       console.log("open_article received link: " + link);
                
                                        if (link && id) {
                
                                                var wname = "ttrss_article_" + id.firstChild.nodeValue;
                
-                                               debug("link url: " + link.firstChild.nodeValue + ", wname " + wname);
+                                               console.log("link url: " + link.firstChild.nodeValue + ", wname " + wname);
                
                                                var w = window.open(link.firstChild.nodeValue, wname);
                
@@ -1754,36 +1636,6 @@ function openArticleInNewWindow(id) {
        }
 }
 
-/* http://textsnippets.com/posts/show/835 */
-
-Position.GetWindowSize = function(w) {
-        w = w ? w : window;
-        var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth);
-        var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight);
-        return [width, height]
-}
-
-/* http://textsnippets.com/posts/show/836 */
-
-Position.Center = function(element, parent) {
-        var w, h, pw, ph;
-        var d = Element.getDimensions(element);
-        w = d.width;
-        h = d.height;
-        Position.prepare();
-        if (!parent) {
-                var ws = Position.GetWindowSize();
-                pw = ws[0];
-                ph = ws[1];
-        } else {
-                pw = parent.offsetWidth;
-                ph = parent.offsetHeight;
-        }
-        element.style.top = (ph/2) - (h/2) -  Position.deltaY + "px";
-        element.style.left = (pw/2) - (w/2) -  Position.deltaX + "px";
-}
-
-
 function isCdmMode() {
        return !$("headlinesList");
 }
@@ -1819,21 +1671,11 @@ function displayHelpInfobox(topic_id) {
 
 }
 
-function focus_element(id) {
-       try {
-               var e = $(id);
-               if (e) e.focus();
-       } catch (e) {
-               exception_error("focus_element", e);
-       }
-       return false;
-}
-
 function loading_set_progress(p) {
        try {
                if (p < last_progress_point || !Element.visible("overlay")) return;
 
-               debug("<b>loading_set_progress : " + p + " (" + last_progress_point + ")</b>");
+               console.log("loading_set_progress : " + p + " (" + last_progress_point + ")");
 
                var o = $("l_progress_i");
 
@@ -1854,136 +1696,15 @@ function loading_set_progress(p) {
 
 function remove_splash() {
        if (Element.visible("overlay")) {
-               debug("about to remove splash, OMG!");
+               console.log("about to remove splash, OMG!");
                Element.hide("overlay");
-               debug("removed splash!");
-       }
-}
-
-function addLabelExample() {
-       try {
-               var form = document.forms["label_edit_form"];
-
-               var text = form.sql_exp;
-               var op = form.label_fields[form.label_fields.selectedIndex];
-               var p = form.label_fields_param;
-
-               if (op) {
-                       op = op.value;
-
-                       var tmp = "";
-
-                       if (text.value != "") {                 
-                               if (text.value.substring(text.value.length-3, 3).toUpperCase() != "AND") {
-                                       tmp = " AND ";
-                               } else {
-                                       tmp = " ";
-                               }
-                       }
-
-                       if (op == "unread") {
-                               tmp = tmp + "unread = true";
-                       }
-
-                       if (op == "updated") {
-                               tmp = tmp + "last_read is null and unread = false";
-                       }
-
-                       if (op == "kw_title") {
-                               if (p.value == "") {
-                                       alert("This action requires a parameter.");
-                                       return false;
-                               }
-                               tmp = tmp + "ttrss_entries.title like '%"+p.value+"%'";
-                       }
-
-                       if (op == "kw_content") {
-                               if (p.value == "") {
-                                       alert("This action requires a parameter.");
-                                       return false;
-                               }
-
-                               tmp = tmp + "ttrss_entries.content like '%"+p.value+"%'";
-                       }
-
-                       if (op == "scoreE") {
-                               if (isNaN(parseInt(p.value))) {
-                                       alert("This action expects numeric parameter.");
-                                       return false;
-                               }
-                               tmp = tmp + "score = " + p.value;
-                       }
-
-                       if (op == "scoreG") {
-                               if (isNaN(parseInt(p.value))) {
-                                       alert("This action expects numeric parameter.");
-                                       return false;
-                               }
-                               tmp = tmp + "score > " + p.value;
-                       }
-
-                       if (op == "scoreL") {
-                               if (isNaN(parseInt(p.value))) {
-                                       alert("This action expects numeric parameter.");
-                                       return false;
-                               }
-                               tmp = tmp + "score < " + p.value;
-                       }
-
-                       if (op == "newerD") {
-                               if (isNaN(parseInt(p.value))) {
-                                       alert("This action expects numeric parameter.");
-                                       return false;
-                               }
-                               tmp = tmp + "updated > NOW() - INTERVAL '"+parseInt(p.value)+" days'";
-                       }
-
-                       if (op == "newerH") {
-                               if (isNaN(parseInt(p.value))) {
-                                       alert("This action expects numeric parameter.");
-                                       return false;
-                               }
-
-                               tmp = tmp + "updated > NOW() - INTERVAL '"+parseInt(p.value)+" hours'";
-                       }
-
-                       text.value = text.value + tmp;
-
-                       p.value = "";
-
-               }
-               
-       } catch (e) {
-               exception_error("addLabelExample", e);
-       }
-
-       return false;
-}
-
-function labelFieldsCheck(elem) {
-       try {
-               var op = elem[elem.selectedIndex].value;
-
-               var p = document.forms["label_edit_form"].label_fields_param;
-
-               if (op == "kw_title" || op == "kw_content" || op == "scoreL" || 
-                               op == "scoreG" ||       op == "scoreE" || op == "newerD" ||
-                               op == "newerH" ) {
-                       Element.show(p);
-               } else {
-                       Element.hide(p);
-               }
-
-       } catch (e) {
-               exception_error("labelFieldsCheck", e);
-
+               console.log("removed splash!");
        }
 }
 
 function getSelectedFeedsFromBrowser() {
 
        var list = $("browseFeedList");
-       if (!list) list = $("browseBigFeedList");
 
        var selected = new Array();
        
@@ -2040,28 +1761,6 @@ function updateFeedBrowser() {
 
 }
 
-function browseFeeds(limit) {
-
-       try {
-
-/*             var query = "?op=ialog&subop=browse";
-
-               notify_progress("Loading, please wait...", true);
-
-               new Ajax.Request("backend.php", {
-                       parameters: query,
-                       onComplete: function(transport) { 
-                               infobox_callback2(transport);
-                       } }); */
-
-               displayDlg('feedBrowser');
-
-               return false;
-       } catch (e) {
-               exception_error("browseFeeds", e);
-       }
-}
-
 function transport_error_check(transport) {
        try {
                if (transport.responseXML) {
@@ -2093,43 +1792,6 @@ function truncate_string(s, length) {
        return tmp;
 }
 
-/*
-function switchToFlash(e) {
-       try {
-               var targ = e;
-               if (!e) var e = window.event;
-               if (e.target) targ = e.target;
-               else if (e.srcElement) targ = e.srcElement;
-               if (targ.nodeType == 3) // defeat Safari bug
-                       targ = targ.parentNode;
-               
-               //targ is the link that was clicked
-               var audioTag=targ;
-               do {
-                       audioTag=audioTag.previousSibling;
-               } while(audioTag && audioTag.nodeType != 1)
-               
-               var flashPlayer = audioTag.getElementsByTagName('span')[0];
-               targ.parentNode.insertBefore(flashPlayer,targ);
-               targ.parentNode.removeChild(targ);
-               audioTag.parentNode.removeChild(audioTag);
-
-               return false;
-       } catch (e) {
-               exception_error("switchToFlash", e);
-       }
-}
-
-function html5AudioOrFlash(type) {
-       var audioTag = document.createElement('audio');
-       if(! audioTag.canPlayType || audioTag.canPlayType(type) == "no" ||
-                       audioTag.canPlayType(type) == ""){
-               if($('switchToFlashLink')){
-                       switchToFlash($('switchToFlashLink'));
-               }
-       }
-} */
-
 function hotkey_prefix_timeout() {
        try {
 
@@ -2137,7 +1799,7 @@ function hotkey_prefix_timeout() {
                var ts = Math.round(date.getTime() / 1000);
 
                if (hotkey_prefix_pressed && ts - hotkey_prefix_pressed >= 5) {
-                       debug("hotkey_prefix seems to be stuck, aborting");
+                       console.log("hotkey_prefix seems to be stuck, aborting");
                        hotkey_prefix_pressed = false;
                        hotkey_prefix = false;
                        Element.hide('cmdline');
@@ -2168,7 +1830,7 @@ function displayNewContentPrompt(id) {
 
                $('auxDlg').innerHTML = msg;
 
-               Element.show('auxDlg');
+               new Effect.Appear('auxDlg', {duration : 0.5});
 
        } catch (e) {
                exception_error("displayNewContentPrompt", e);
@@ -2279,7 +1941,7 @@ function removeFeedIcon(id) {
                if (confirm(__("Remove stored feed icon?"))) {
                        var query = "backend.php?op=pref-feeds&subop=removeicon&feed_id=" + param_escape(id);
 
-                       debug(query);
+                       console.log(query);
 
                        notify_progress("Removing feed icon...", true);
 
@@ -2323,3 +1985,327 @@ function uploadFeedIcon() {
        }
 }
 
+function addLabel(select, callback) {
+
+       try {
+
+               var caption = prompt(__("Please enter label caption:"), "");
+
+               if (caption != undefined) {
+       
+                       if (caption == "") {
+                               alert(__("Can't create label: missing caption."));
+                               return false;
+                       }
+
+                       var query = "?op=pref-labels&subop=add&caption=" + 
+                               param_escape(caption);
+
+                       if (select)
+                               query += "&output=select";
+
+                       notify_progress("Loading, please wait...", true);
+
+                       if (inPreferences() && !select) active_tab = "labelConfig";
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) { 
+                                       if (callback) {
+                                               callback(transport);
+                                       } else if (inPreferences()) {
+                                               infobox_submit_callback2(transport);
+                                       } else {
+                                               updateFeedList();
+                                       }
+                       } });
+
+               }
+
+       } catch (e) {
+               exception_error("addLabel", e);
+       }
+}
+
+function quickAddFeed() {
+       displayDlg('quickAddFeed', '',
+          function () {$('feed_url').focus();});
+}
+
+function quickAddFilter() {
+       displayDlg('quickAddFilter', '',
+          function () {document.forms['filter_add_form'].reg_exp.focus();});
+}
+
+function unsubscribeFeed(feed_id, title) {
+
+       var msg = __("Unsubscribe from %s?").replace("%s", title);
+
+       if (title == undefined || confirm(msg)) {
+               notify_progress("Removing feed...");
+
+               var query = "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id;
+
+               new Ajax.Request("backend.php", {
+                       parameters: query,
+                       onComplete: function(transport) {
+
+                                       closeInfoBox();
+
+                                       if (inPreferences()) {
+                                               updateFeedList();                               
+                                       } else {
+                                               dlg_frefresh_callback(transport, feed_id);
+                                       }
+
+                               } });
+       }
+
+       return false;
+}
+
+
+function backend_sanity_check_callback(transport) {
+
+       try {
+
+               if (sanity_check_done) {
+                       fatalError(11, "Sanity check request received twice. This can indicate "+
+                     "presence of Firebug or some other disrupting extension. "+
+                               "Please disable it and try again.");
+                       return;
+               }
+
+               if (!transport.responseXML) {
+                       if (!store) {
+                               fatalError(3, "Sanity check: Received reply is not XML", 
+                                       transport.responseText);
+                               return;
+                       } else {
+                               init_offline();
+                               return;
+                       }
+               }
+
+               if (getURLParam("offline")) {
+                       return init_offline();
+               }
+
+               var reply = transport.responseXML.getElementsByTagName("error")[0];
+
+               if (!reply) {
+                       fatalError(3, "Sanity check: invalid RPC reply", transport.responseText);
+                       return;
+               }
+
+               var error_code = reply.getAttribute("error-code");
+       
+               if (error_code && error_code != 0) {
+                       return fatalError(error_code, reply.getAttribute("error-msg"));
+               }
+
+               console.log("sanity check ok");
+
+               var params = transport.responseXML.getElementsByTagName("init-params")[0];
+
+               if (params) {
+                       console.log('reading init-params...');
+
+                       params = JSON.parse(params.firstChild.nodeValue);
+
+                       if (params) {
+                               for (var i = 0; i < params.length; i++) {
+       
+                                       var k = params[i].param;
+                                       var v = params[i].value;
+       
+                                       if (getURLParam('debug')) console.log(k + " => " + v);
+                                       init_params[k] = v;                                     
+       
+                                       if (db) {
+                                               db.execute("DELETE FROM init_params WHERE key = ?", [k]);
+                                               db.execute("INSERT INTO init_params (key,value) VALUES (?, ?)",
+                                                       [k, v]);
+                                       }
+                               }
+                       }
+               }
+
+               sanity_check_done = true;
+
+               init_second_stage();
+
+       } catch (e) {
+               exception_error("backend_sanity_check_callback", e, transport); 
+       } 
+}
+
+function has_local_storage() {
+       try {
+               return 'localStorage' in window && window['localStorage'] != null;
+       } catch (e) {
+               return false;
+       }
+}
+
+function catSelectOnChange(elem) {
+       try {
+               var value = elem[elem.selectedIndex].value;
+               var def = elem.getAttribute('default');
+
+               if (value == "ADD_CAT") {
+
+                       if (def)
+                               dropboxSelect(elem, def);
+                       else
+                               elem.selectedIndex = 0;
+
+                       quickAddCat(elem);
+               }
+
+       } catch (e) {
+               exception_error("catSelectOnChange", e);
+       }
+}
+
+function quickAddCat(elem) {
+       try {
+               var cat = prompt(__("Please enter category title:"));
+
+               if (cat) {
+
+                       var query = "?op=rpc&subop=quickAddCat&cat=" + param_escape(cat);
+
+                       notify_progress("Loading, please wait...", true);
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function (transport) {
+                                       var response = transport.responseXML;
+                                       var select = response.getElementsByTagName("select")[0];
+                                       var options = select.getElementsByTagName("option");
+
+                                       dropbox_replace_options(elem, options);
+
+                                       notify('');
+
+                       } });
+
+               }
+
+       } catch (e) {
+               exception_error("quickAddCat", e);
+       }
+}
+
+function genUrlChangeKey(feed, is_cat) {
+
+       try {
+               var ok = confirm(__("Generate new syndication address for this feed?"));
+       
+               if (ok) {
+       
+                       notify_progress("Trying to change address...", true);
+       
+                       var query = "?op=rpc&subop=regenFeedKey&id=" + param_escape(feed) + 
+                               "&is_cat=" + param_escape(is_cat);
+
+                       new Ajax.Request("backend.php", {
+                               parameters: query,
+                               onComplete: function(transport) {
+                                               var new_link = transport.responseXML.getElementsByTagName("link")[0];
+       
+                                               var e = $('gen_feed_url');
+       
+                                               if (new_link) {
+                                                       
+                                                       new_link = new_link.firstChild.nodeValue;
+
+                                                       e.innerHTML = e.innerHTML.replace(/\&amp;key=.*$/, 
+                                                               "&amp;key=" + new_link);
+
+                                                       e.href = e.href.replace(/\&amp;key=.*$/,
+                                                               "&amp;key=" + new_link);
+
+                                                       new Effect.Highlight(e);
+
+                                                       notify('');
+       
+                                               } else {
+                                                       notify_error("Could not change feed URL.");
+                                               }
+                               } });
+               }
+       } catch (e) {
+               exception_error("genUrlChangeKey", e);
+       }
+       return false;
+}
+
+function labelSelectOnChange(elem) {
+       try {
+               var value = elem[elem.selectedIndex].value;
+               var def = elem.getAttribute('default');
+
+               if (value == "ADD_LABEL") {
+
+                       if (def)
+                               dropboxSelect(elem, def);
+                       else
+                               elem.selectedIndex = 0;
+
+                       addLabel(elem, function(transport) {
+
+                                       try {
+
+                                               var response = transport.responseXML;
+                                               var select = response.getElementsByTagName("select")[0];
+                                               var options = select.getElementsByTagName("option");
+
+                                               dropbox_replace_options(elem, options);
+
+                                               notify('');
+                                       } catch (e) {
+                                               exception_error("addLabel", e);
+                                       }
+                       });
+               }
+
+       } catch (e) {
+               exception_error("labelSelectOnChange", e);
+       }
+}
+
+function dropbox_replace_options(elem, options) {
+
+       try {
+               while (elem.hasChildNodes())
+                       elem.removeChild(elem.firstChild);
+
+               var sel_idx = -1;
+
+               for (var i = 0; i < options.length; i++) {
+                       var text = options[i].firstChild.nodeValue;
+                       var value = options[i].getAttribute("value");
+
+                       if (value == undefined) value = text;
+
+                       var issel = options[i].getAttribute("selected") == "1";
+
+                       var option = new Option(text, value, issel);
+
+                       if (options[i].getAttribute("disabled"))
+                               option.setAttribute("disabled", true);
+
+                       elem.insert(option);
+
+                       if (issel) sel_idx = i;
+               }
+
+               // Chrome doesn't seem to just select stuff when you pass new Option(x, y, true)
+               if (sel_idx >= 0) elem.selectedIndex = sel_idx;
+
+       } catch (e) {
+               exception_error("dropbox_replace_options", e);
+       }
+}