Created
August 27, 2008 22:18
-
-
Save al3x/7594 to your computer and use it in GitHub Desktop.
Twitter Search command for Mozilla Ubiquity
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
makeSearchCommand({ | |
name: "tsearch", | |
url: "http://search.twitter.com/search?q={QUERY}", | |
icon: "http://twitter.com/favicon.ico", | |
description: "Searches Twitter for your words.", | |
preview: function(pblock, directObject) { | |
var searchTerm = directObject.text; | |
var pTemplate = "Searches Twitter for <b>${query}</b>"; | |
var pData = {query: searchTerm}; | |
pblock.innerHTML = CmdUtils.renderTemplate(pTemplate, pData); | |
var url = "http://search.twitter.com/search.json"; | |
var params = { q: searchTerm }; | |
jQuery.get( url, params, function(data) { | |
var results = data.results.splice( 0, 5 ); | |
var previewTemplate = "{for result in results}"; | |
previewTemplate += '<div style="clear: both; margin: 20px 0 30px 0;"><img src="${result.profile_image_url}" style="float: left; margin-right: 5px;" /><span>${result.from_user}: ${result.text}</span></div>'; | |
previewTemplate += "{/for}"; | |
var previewData = { | |
results: results | |
}; | |
if (!results) { | |
pblock.innerHTML = "<p>Unable to retrieve preview.</p>"; | |
} else { | |
pblock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData); | |
} | |
}, "json"); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment