Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ubiqutiy Command for Places
//Derived from http://people.mozilla.org/~dietrich/ubiquity.js
var sources = ["history", "bookmarks", "starred", "tagged", "session"];
var sorts = ["freshness", "age", "frequency", "infrequency", "recency", "staleness"]
var noun_type_places_datasource = new CmdUtils.NounType("datasource", sources);
var noun_type_places_sorts = new CmdUtils.NounType(" sort attribute", sorts);
var debugMode = false;
/*
The sort order to use for the results.
0
Natural bookmark order
1
Sort by title, A-Z
2
Sort by title, Z-A
3
Sort by visit date, most recent last
4
Sort by visit date, most recent first
5
Sort by uri, A-Z
6
Sort by uri, Z-A
7
Sort by visit count, ascending
8
Sort by visit count, descending
Sort by date added, most recent last
12
Sort by date added, most recent first
13
Sort by last modified date, most recent last
14
Sort by last modified date, most recent first
17
Sort by tags, ascending
18
Sort by tags, descending
19
Sort by annotation, ascending
20
Sort by annotation, descending
*/
// https://developer.mozilla.org/En/Places_query_URIs
// command to execute places URI queries
CmdUtils.CreateCommand({
name: "places",
icon: "chrome://browser/skin/places/query.png",
description: "Query your local history and bookmarks by keyword.",
takes : {"term" : noun_arb_text},
modifiers: {in: noun_type_places_datasource, sorton: noun_type_places_sorts, site: noun_arb_text},
preview: function(pblock, term, mods) {
if (!term.text.length && !mods.in.text.length && !mods.site.text.length) {
pblock.innerHTML = "Enter terms or use the in modifier to get history, bookmarks, or starred. Optional sorton.";
return;
}
var Cc = Components.classes;
var Ci = Components.interfaces;
var hs = Cc["@mozilla.org/browser/nav-history-service;1"].
getService(Ci.nsINavHistoryService);
var msg = '* <a href="${url}" title="${url}">${title}<br/><small>&nbsp;&nbsp;${url}</small></a><br/>';
// convert URI to queries and options
var options = { };
var queries = { };
var size = { };
var sortBy = 0;
var queryType = 0;
var extras = '';
if(mods.in && mods.in.text.length) {
if(debugMode) CmdUtils.log(mods.in.text);
switch(mods.in.text) {
case "history":
queryType = 0;
break;
case "bookmarks":
queryType = 1;
break;
case "starred":
extras = '&folder=UNFILED_BOOKMARKS'
queryType = 1;
break;
}
}
if(mods.site.text.length) {
extras+="&domain=" + mods.site.text;
}
if(mods.sorton && mods.sorton.text.length) {
switch(mods.sorton.text) {
case "freshness":
sortBy = 4;
break;
case "age":
sortBy = 3;
break;
case "frequency":
sortBy = 8;
break;
case "infrequency":
sortBy = 7;
break;
case "recency":
sortBy = 12;
break;
case "staleness":
sortBy = 11;
break;
}
}
aPlaceURI = "place:queryType=" + queryType;
if(extras.length) aPlaceURI += extras;
aPlaceURI += "&terms=" + term.text;
aPlaceURI += "&sort=" + sortBy + "&maxResults=10";
if(debugMode) CmdUtils.log(aPlaceURI);
hs.queryStringToQueries(aPlaceURI, queries, size, options);
// reasonableness
if (!options.value.maxResults || options.value.maxResults > 10)
options.value.maxResults = 10;
// execute query
var result = hs.executeQueries(queries.value, size.value, options.value);
var root = result.root;
root.containerOpen = true;
var count = root.childCount;
pblock.innerHTML = "Results (" + count + ")<br/>";
if (count) {
for (var i = 0; i < count; i++) {
var node = root.getChild(i);
pblock.innerHTML += CmdUtils.renderTemplate( msg, {url: node.uri, title: node.title} );
}
root.containerOpen = false;
}
}
});
/*
andyed's example:
[10:37am] andyed: for command line, i want things like
[10:37am][10:37am][10:37am][10:37am][10:37am][10:37am][10:37am][10:37am][10:37am][10:37am][10:37am]
andyed: "yesterday afternoon I had a big google sesssion, show me all
my queries with clicks and the links clicked grouped by query"
[10:37am] andyed: sometime last week I had a session looking at media wiki extensions, show it to me with thumbnails
...
[10:38am] andyed: but i'm finding myself using starring
[10:38am] andyed: but with no good way to consume those links again later other than the awesome bar
[10:38am] andyed: so even just some good temporal queries on starred and a timeline view would rock
[10:38am] dietrich: {yesterday afternoon} {google.com} {visit-type=clicked}{not sure what you mean by "grouped by query"}
[10:39am] andyed: {ref:google.com}
[10:39am] andyed: listed out ordered by time grouped by query
[10:39am] andyed: query is a heading
"yesterday afternoon I had a big google session, show me all
my queries with clicks and the links-clicked grouped by query"
recomputed: show me all the visits from yesterday afternoon that have
a google search as the referrer, grouped by the query string of the
referring search.
summarized further: show google searches from yesterday afternoon
{date: yesterday afternoon}
{referrer: google.com}
{group by: referrer's queryString}
{visit type: clicked}
vocabulary:
"show" -> verb
"source" -> data type
"from" -> date range
"with" -> search terms
mappings:
"recent" maxResults=20? all in the last week?
"history" queryType=0
"bookmarks" queryType=1
"starred" queryType=1
examples:
show starred from yesterday
show history from today with storks
andyed: show session from yesterday with amazon
*/
var ranges = [
"today", "earlier-today", /* excluding current session */
"yesterday",
"this-week", "last-week",
"this-month", "last-month",
"long-ago"];
//var noun_type_date_range = new CmdUtils.NounType("date-range", ranges);
var noun_type_date_range = {
_name: "date-range",
suggest: function( text, html ) {
var suggestions = [];
for ( var word in ranges) {
// Do the match in a non-case sensitive way
if ( word.indexOf( text.toLowerCase() ) > -1 ) {
var sugg = CmdUtils.makeSugg(word, word, word);
suggestions.push( sugg );
}
}
return suggestions;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.