// Time-stamp: "2015-01-30 09:48:44 phil"
// From: http://retroj.net/git/conkerorrc/history.js
dumpln("29history");

require("interactive");

// Make the global, unified browsing history accessible as a browser object
define_browser_object_class(
    "history-url", null,
    function (I, prompt) {
        check_buffer (I.buffer, content_buffer);
        var result = yield I.buffer.window.minibuffer.read_url(
            $prompt = prompt,  $use_webjumps = false, $use_history = true, $use_bookmarks = false);
        yield co_return (result);
    },
    $hint = "choose url from history");



interactive("find-url-from-history",
    "Find a page from history in the current buffer",
    "find-url",
    $browser_object = browser_object_history_url);

interactive("find-url-from-history-new-buffer",
    "Find a page from history in the current buffer",
    "find-url-new-buffer",
    $browser_object = browser_object_history_url);



function history_clear () {
    var history = Cc["@mozilla.org/browser/nav-history-service;1"]
        .getService(Ci.nsIBrowserHistory);
    history.removeAllPages();
}
interactive("history-clear", "Clear the history.", history_clear);


/*
 * History cleanup: dump qualifying entries
 */

// Return the function name or anonymous signature
function function_pretty_name (fn) {
    if (fn.name) {
        return fn.name;
    }
    var s = fn.toString().trimRight();
    var m = s.match(/^[^)]+\)\s*([^{;]+)$/);
    if (m) {
        return m[1];
    }
    return s;
}

define_keywords("$verbose", "$dry_run");
function history_clean (predicates) {
    keywords(arguments, $verbose = false, $dry_run = false);
    predicates = make_array(predicates);
    var npred = predicates.length;
    var predhits = [];
    var verbose = arguments.$verbose;
    var dry_run = arguments.$dry_run;
    var query = nav_history_service.getNewQuery();
    query.searchTerms = "";
    var options = nav_history_service.getNewQueryOptions();
    options.queryType = options.QUERY_TYPE_HISTORY;
    options.includeHidden = true;
    var root = nav_history_service.executeQuery(query, options).root;
    root.containerOpen = true;
    var count = root.childCount;
    if (verbose) {
        dump("History items: " + count);
    }
    var now = Date.now() / 86400000; // now in days
    var history = Cc["@mozilla.org/browser/nav-history-service;1"]
        .getService(Ci.nsIBrowserHistory);
    for (var i = count - 1; i >= 0; --i) {
        var o = root.getChild(i); // nsINavHistoryResultNode
        var age = now - o.time / 86400000000; // age in days
        var nomatch = true;
        for (var j = 0; nomatch && j < npred; ++j) {
            var p = predicates[j];
            if (p(o.uri, age, o.accessCount)) {
                predhits[j] = (predhits[j] || 0) + 1;
                if (! dry_run) {
                    history.removePage(make_uri(o.uri));
                }
                // Exit inner loop, continue outer loop
                nomatch = false;
            }
        }
    }
    if (verbose) {
        dumpln(" -> " + (count - predhits.reduce(function (a, b) a + b, 0)) +
               (dry_run ? " [DRY_RUN]" : ""));
        for (j = 0; j < npred; ++j) {
            var name = predicates[j].name;
            if (! name) {
                name = function_pretty_name(predicates[j]);
            }
            var hits = predhits[j] || 0;
            dumpln("  " + name + ": " + hits);
        }
    }
}

//history_clean(function (uri, age) age > 670, $verbose);

@@ -16,24 +16,24 @@
 %22201
-5-01-30 09:48:44
+8-12-27 19:55:26
  phi
@@ -479,16 +479,28 @@
  = true,
+%0A           
  $use_bo
@@ -3062,18 +3062,15 @@
 pln(
-%22
+%60
  -%3E 
-%22 + (
+$%7B
 coun
@@ -3114,17 +3114,18 @@
  + b, 0)
-)
+%7D%60
  +%0A     
@@ -3411,33 +3411,28 @@
 pln(
-%22  %22 + name + %22: %22 + 
+%60  $%7Bname%7D: $%7B
 hits
+%7D%60
 );%0A 

Use template strings.