Skip to content

Instantly share code, notes, and snippets.

@Yengas
Last active December 26, 2015 20:18
Show Gist options
  • Save Yengas/7207217 to your computer and use it in GitHub Desktop.
Save Yengas/7207217 to your computer and use it in GitHub Desktop.
Makes torrent download from Horrible Subs easier.Usage: "Hunter x Hunter".download([10,20],720);Enable opening .torrent files after the download(an option that your browser gives you).
String.prototype.endsWith = function(suffix) { return this.indexOf(suffix, this.length - suffix.length) !== -1; };
Object.prototype.forEach = function(callback){ for(var i = 0; i < this.length; i++){ if(typeof this[i] == "object"){ callback(this[i]); } } };
function getElement(html){ var d = document.createElement("div"); d.setAttribute('style', 'display: none;'); d.innerHTML = html; document.body.appendChild(d); return d; }
function download(url){ var frame = document.createElement("iframe"); frame.src = url; document.body.appendChild(frame); }
String.prototype.download = function (ea, q){
var e, d, x = new XMLHttpRequest();
if(ea[0] > ea[1] || ea[0] < 0 || ea[1] <= 0 || [360,480,720,1080].indexOf(q) == -1){ return; }
for(var i = ea[0]; i <= ea[1]; i++){
e = this+" "+((i < 10) ? "0": "") + i;
x.open("GET","http://horriblesubs.info/lib/search.php?value="+encodeURIComponent(e),false);
x.onload = function(){
d = getElement(this.responseText);
try{
d.getElementsByClassName("episode").forEach(function($e){
if($e.id.endsWith("-"+((i < 10) ? "0": "") + i)){
$e.getElementsByClassName("linkful").forEach(function($l){
if($l.getElementsByTagName("a")[0].innerHTML == q+"p"){
$l.getElementsByTagName("a").forEach(function($i){
if($i.innerHTML == "Torrent"){ console.log("Trying to download Episode "+i+" URL: "+$i.href); download($i.href); }
});
}
});
}
});
}catch(e){ console.log(e); }
};
x.send();
document.body.removeChild(d);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment