Created
July 11, 2009 01:52
-
-
Save andyed/144985 to your computer and use it in GitHub Desktop.
Places for Ubiquity next-gen beta, using semantic roles
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Derived from http://people.mozilla.org/~dietrich/ubiquity.js | |
var sources = ["history", "bookmarks", "starred", "tagged", "session"]; | |
var sorts = ["revisit", "rediscover", "top", "rare", "new", "old"] | |
var noun_type_places_datasource = new CmdUtils.NounType("datasource", sources); | |
var noun_type_places_sorts = new CmdUtils.NounType(" sort attribute", sorts); | |
var debugMode = false; | |
// https://developer.mozilla.org/En/Places_query_URIs | |
// command to execute places URI queries | |
CmdUtils.CreateCommand({ | |
names: ["places"], | |
icon: "chrome://browser/skin/places/query.png", | |
description: "Query your local history and bookmarks by keyword.", | |
arguments: [{role: "object", nountype: noun_arb_text, label: "keyword"}, {role: "format", nountype: noun_type_places_datasource, label:"source"}, {role: "source", nountype: noun_type_places_sorts, label: "sort"} ,{ role: "instrument", nountype: noun_arb_text, label: "site"}], | |
preview: function(pblock, mods) { | |
if (!mods.object.text.length && !mods.format.text.length && !mods.instrument.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}" style="text-decoration:none;">${title}<br/> <span style="font-size:.8em;text-decoration:underline;">${url}</span></a><br/><br style="font-size:.3em;"/>'; | |
// convert URI to queries and options | |
var options = { }; | |
var queries = { }; | |
var size = { }; | |
var sortBy = 4;// Default sort by last visit desc | |
var queryType = 1; // Default sort to bookmarks | |
var extras = ''; | |
if(mods.format && mods.format.text.length) { | |
if(debugMode) CmdUtils.log(mods.format.text); | |
switch(mods.format.text) { | |
case "history": | |
queryType = 0; | |
break; | |
case "bookmarks": | |
queryType = 1; | |
break; | |
case "starred": | |
extras = '&folder=UNFILED_BOOKMARKS' | |
queryType = 1; | |
break; | |
} | |
} | |
if(mods.instrument.text.length) { | |
extras+="&domain=" + mods.instrument.text; | |
} | |
if(mods.source && mods.source.text.length) { | |
switch(mods.source.text) { | |
case "revisit": | |
sortBy = 4; | |
break; | |
case "rediscover": | |
sortBy = 3; | |
break; | |
case "top": | |
sortBy = 8; | |
break; | |
case "rare": | |
sortBy = 7; | |
break; | |
case "new": | |
sortBy = 12; | |
break; | |
case "old": | |
sortBy = 11; | |
break; | |
} | |
} | |
aPlaceURI = "place:redirectMode=false&queryType=" + queryType; | |
if(extras.length) aPlaceURI += extras; | |
aPlaceURI += "&terms=" + mods.object.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; | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment