166
edits
Line 616: | Line 616: | ||
[http://hg.toolness.com/ubiquity-firefox/file/tip/ubiquity/builtin-feeds/en/builtincmds.js builtincmds.js] | [http://hg.toolness.com/ubiquity-firefox/file/tip/ubiquity/builtin-feeds/en/builtincmds.js builtincmds.js] | ||
[http://hg.toolness.com/ubiquity-firefox/file/tip/ubiquity/feed-parts/header/en/nountypes.js nountypes.js] | [http://hg.toolness.com/ubiquity-firefox/file/tip/ubiquity/feed-parts/header/en/nountypes.js nountypes.js] | ||
== Interacting with Other Extensions == | |||
http://img363.imageshack.us/img363/1906/picture7cm5.png | |||
There isn't much to say here besides that it's easy. For example, here's a command (thanks to [http://foyrek.com/lyrics.html Abimanyu Raja] for writing this code) that finds the lyrics for a song. You can simply Ubiq something like "get-lyrics wild international" but the command will also interface with the FoxyTunes extension (if it is installed) and add the currently playing song to the suggestion list. Interfacing with other extensions, too, is easy because you can view the source code for every Firefox extension. | |||
<pre> | |||
var noun_type_song = { | |||
_name: "song name", | |||
suggest: function( text, html ) { | |||
var suggestions = [CmdUtils.makeSugg(text)]; | |||
if(window.foxytunesGetCurrentTrackTitle){ | |||
suggestions.push(CmdUtils.makeSugg(window.foxytunesGetCurrentTrackTitle())); | |||
} | |||
return suggestions; | |||
} | |||
} | |||
CmdUtils.CreateCommand({ | |||
name: "get-lyrics", | |||
takes: {song: noun_type_song}, | |||
preview: function(pblock, directObject) { | |||
searchText = jQuery.trim(directObject.text); | |||
if(searchText.length < 1) { | |||
pblock.innerHTML = "Searches for lyrics of the song"; | |||
return; | |||
} | |||
var previewTemplate = "Searches for the lyrics of <b>${query}</b>"; | |||
var previewData = {query: searchText}; | |||
pblock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData); | |||
}, | |||
execute: function(directObject) { | |||
var url = "http://www.google.com/search?q={QUERY}" | |||
var query = directObject.text + " lyrics"; | |||
var urlString = url.replace("{QUERY}", query); | |||
Utils.openUrlInBrowser(urlString); | |||
} | |||
}); | |||
</pre> |
edits