-
-
Save dgraversen/22889 to your computer and use it in GitHub Desktop.
This file contains 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
var noun_type_pi_history = { | |
_name: "pi_history", | |
suggest: function(text,html){ | |
var suggestions = []; | |
var historyService = Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsINavHistoryService); | |
var options = historyService.getNewQueryOptions(); | |
// first query object searches for "firefox" in title/URL | |
var query1 = historyService.getNewQuery(); | |
query1.searchTerms = text + " /start/index.jsp" ; | |
var result = historyService.executeQuery(query1,options); | |
var cont = result.root; | |
cont.containerOpen = true; | |
for (var i = 0; i < cont.childCount; i ++) { | |
var node = cont.getChild(i); | |
var Ci = Components.interfaces; | |
switch(node.type) { | |
case node.RESULT_TYPE_URI: | |
//Application.console.log("URI result " + node.uri + "\n"); | |
//resultHTML += "<a href='" + node.uri + "' >" + node.title + "</a><br />"; | |
suggestions.push(CmdUtils.makeSugg(node.title,"<b style=\"color:yellow\">%s</b>".replace(/%s/, node.title),node)); | |
break; | |
} | |
} | |
cont.containerOpen = false; | |
return suggestions.splice(0, 5); | |
} | |
} | |
noun_piresource_type = new CmdUtils.NounType( "PI resources", | |
["repository", "directory", "communicationchannel", "nwa", "cpacache","cpacacherefresh", "sld", "rwb","tools", "messagingsystem"]); | |
CmdUtils.CreateCommand({ | |
name: "pi", | |
icon: "chrome://ubiquity/content/icons/search.png", | |
description: "Direct access to PI resourses", | |
homepage: "http://figaf.com/", | |
author: { name: "Daniel Graversen", email: "sdn@figaf.com"}, | |
license: "MPL", | |
takes: { keyword: noun_type_pi_history}, | |
modifiers: {open: noun_piresource_type,}, | |
typemap: {"repository": "rep/start/repository.jnlp", "directory":"dir/start/directory.jnlp", "communicationchannel": "mdt/channelmonitorservlet", "nwa": "nwa/" ,"cpacache": "CPACache" , "cpacacherefresh":"CPACache/refresh?mode=full", "sld" :"sld/", "rwb": "rwb/","tools":"xx", "messagingsystem":"MessagingSystem/" }, | |
preview: function(pblock,directObject,modifiers){ | |
if(directObject.keyword.text == null || directObject.keyword.text == ''){ | |
var searchTerm = directObject.keyword.text; | |
var pTemplate = "Input some keyword to search history in your firefox"; | |
var pData = {query: searchTerm}; | |
pblock.innerHTML = CmdUtils.renderTemplate(pTemplate, pData); | |
}else{ | |
pblock.innerHTML = "Open PI <b style=\"color:yellow\">%s</b> .".replace(/%s/, directObject.data.title); | |
} | |
if (modifiers.open) { | |
pblock.innerHTML += "to " + modifiers.open.text + " "; | |
} | |
}, | |
execute: function(directObject,modifiers) { | |
function url(spec) { | |
var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); | |
return ios.newURI(spec, null, null); | |
} | |
var server = directObject.data.uri; | |
var server = server.replace("rep/start/index.jsp", ""); | |
var activeWin = Application.activeWindow; | |
var browserTab = activeWin.open(url( server+ this.typemap[modifiers.open.text] )); | |
browserTab.focus(); | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment