Labs/Ubiquity/Ubiquity Source Tip Author Tutorial: Difference between revisions

Line 773: Line 773:
http://img363.imageshack.us/img363/1906/picture7cm5.png
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.
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 for 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>
<pre>
Line 789: Line 789:


CmdUtils.CreateCommand({
CmdUtils.CreateCommand({
   name: "get-lyrics",
   names: ["get lyrics"],
   takes: {song: noun_type_song},
   arguments: {modifier: noun_type_song},
   preview: function(pblock, directObject) {
   preview: function(pblock, arguments) {
      
      
     searchText = jQuery.trim(directObject.text);
     searchText = jQuery.trim(arguments.modifier.text);
     if(searchText.length < 1) {
     if(searchText.length < 1) {
       pblock.innerHTML = "Searches for lyrics of the song";
       pblock.innerHTML = "Searches for lyrics of the song";
Line 804: Line 804:


   },
   },
   execute: function(directObject) {
   execute: function(arguments) {
     var url = "http://www.google.com/search?q={QUERY}"
     var url = "http://www.google.com/search?q={QUERY}"
     var query = directObject.text + " lyrics";
     var query = arguments.object.text + " lyrics";
     var urlString = url.replace("{QUERY}", query);
     var urlString = url.replace("{QUERY}", query);
     Utils.openUrlInBrowser(urlString);
     Utils.openUrlInBrowser(urlString);
Line 812: Line 812:
});
});
</pre>
</pre>


== Implementing Asynchronous Noun Suggestions ==
== Implementing Asynchronous Noun Suggestions ==
1,007

edits