Skip to content

Instantly share code, notes, and snippets.

@makevoid
Created January 17, 2012 22:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save makevoid/1629412 to your computer and use it in GitHub Desktop.
Save makevoid/1629412 to your computer and use it in GitHub Desktop.
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