Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Thorrents.com JSONP embedded search example

Example of embedded http://thorrents.com search, and a tribute to Cory Doctorow ;) tnx to @thedod

See it live here.

If you want to embed this (or any other search) in an existing page:

  • Remove first and last line and paste this where you want it in the <body/>.
  • Change query to whatever you want to search (and maybe change limit).
  • Optionally, do some css (please fork this if you do something cool).
<html><body>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type='text/javascript'>
$(function(){
var query = "doctorow"
var element = "#thorrents"
var limit = 5
// TODO: jquery function - $("element").thorrents()
var domain = "thorrents.com"
var url = 'http://'+domain+'/search/'+query+'.json?callback=?'
$.getJSON(url, function(data) {
$(element).append("<ul></ul>")
$.each(data.results, function(idx, result) {
$(element+" ul").append("<li><a href='"+result.magnet+"'><span>"+result.seeds+"</span>"+result.name+"</a></li>")
if (idx+1 >= limit)
return false
})
})
});
</script>
<style text='type/css'>
#thorrents li {
display: block;
}
#thorrents li span {
display: block;
float: left;
text-align: right;
width: 80px;
margin-right: 12px
}
</style>
<div id='thorrents'></div>
</body></html>
{
"results": [{
"name": "ubuntu desktop 10.10 i386",
"magnet": "magnet:?xt=urn:btih:bcf2e587afd4d3....80%2Fannounce",
"seeds": "157"
}, {
"name": "Ubuntu 10.10 amd64",
"magnet": "magnet:?xt=urn:btih:4af6fb7cbfb87....80%2Fannounce",
"seeds": "63"
}, {
"name": "Ubuntu Ultimate Edition",
"magnet": "magnet:?xt=urn:btih:429f2330241....80%2Fannounce",
"seeds": "36"
}]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment