Skip to content

Instantly share code, notes, and snippets.

@cnicodeme
Created March 30, 2012 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cnicodeme/2250981 to your computer and use it in GitHub Desktop.
Save cnicodeme/2250981 to your computer and use it in GitHub Desktop.
ShowDates.me improving script.
var oCouchLis = $('#section-watchlist>li'), oSeriesLis = $('#main>div .list-episodes>ul>li');
function processCouch() {
var $this = $(this),
title = $this.find ('>p>a:first-of-type').text(),
cleanTitle = title.replace (/( )/g, '_').replace(/:/g, ''),
code = $this.find ('>p>span.episode-code').text().substring(1),
season = code.substring(0, code.indexOf("E")).replace(/^[0]+/g,""),
episode = code.substring(code.indexOf("E") + 1).replace(/^[0]+/g,""),
// Variables for KAT.ph
oBinsearch = $this.find ('>a.button-binsearch'),
sSearchQuery = oBinsearch.prop('href').substr(oBinsearch.prop('href').lastIndexOf('search?f=') + 9);
// This will Add a button to Addicted
$this.append ($('<a />', {'href': 'http://www.addic7ed.com/serie/' + cleanTitle + '/' + season + '/' + episode + '/1', 'title': 'Download subtitles for ' + title, 'class': 'button-link link-episode'}).append ($('<img />', {'src': 'http://www.addic7ed.com/favicon.ico', 'alt': 'Addic7ed'})));
// This will switch from Torrentz to KAT.ph and remove the target=_blank
oBinsearch.prop('target', null).children(':first').prop('src', 'http://kastatic.com/images/favicon.ico');
}
function processSerie() {
var $this = $(this),
title = $('#main .show-imageheading h1').text(),
cleanTitle = title.replace (/( )/g, '_').replace(/:/g, ''),
oBinsearch = $this.find ('>a.button-binsearch');
if (oBinsearch.length === 1) {
var sSearchQuery = oBinsearch.prop('href').substr(oBinsearch.prop('href').lastIndexOf('search?f=') + 9),
code = sSearchQuery.substr(sSearchQuery.lastIndexOf('+') + 1),
season = code.substring(1, code.indexOf("E")).replace(/^[0]+/g,""),
episode = code.substring(code.indexOf("E") + 1).replace(/^[0]+/g,"");
// This will Add a button to Addicted
$this.find ('>span').before ($('<a />', {'href': 'http://www.addic7ed.com/serie/' + cleanTitle + '/' + season + '/' + episode + '/1', 'title': 'Download subtitles for ' + title, 'class': 'button-link link-episode'}).append ($('<img />', {'src': 'http://www.addic7ed.com/favicon.ico', 'alt': 'Addic7ed'})));
$this.find ('>p').css ({'width': '65%'}); // Little fix
// This will switch from Torrentz to KAT.ph and remove the target=_blank
oBinsearch.prop('target', null).children(':first').prop('src', 'http://kastatic.com/images/favicon.ico');
}
// scroll to the last non see episode, avoiding the specials episodes
if ('specials' === $('.list-episodes>li:first-child').text().toLowerCase().substring(0, 8))
$('.list-episodes>ul:not(:first) img[src$="img/unwatched.png"]:first').closest('ul').prev()[0].scrollIntoView(true);
else
$('.list-episodes>ul img[src$="img/unwatched.png"]:first').closest('ul').prev()[0].scrollIntoView(true);
}
if (oCouchLis.length > 0) oCouchLis.each(processCouch);
else if (oSeriesLis.length > 0) oSeriesLis.each(processSerie);
@cnicodeme
Copy link
Author

Note : I used this link to minify the code (default options), then this link to make the bookmarlet.

@cnicodeme
Copy link
Author

UPDATE has been made to the script, so here is the updated bookmarklet :

javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.7.1",function($,L){var oCouchLis=$("#section-watchlist>li"),oSeriesLis=$("#main>div .list-episodes>ul>li");if(oCouchLis.length>0){oCouchLis.each(function(){var g=$(this),h=g.find(">p>a:first-of-type").text(),f=h.replace(/( )/g,"_").replace(/:/g,""),d=g.find(">p>span.episode-code").text().substring(1),e=d.substring(0,d.indexOf("E")).replace(/^[0]+/g,""),c=d.substring(d.indexOf("E")+1).replace(/^[0]+/g,""),b=g.find(">a.button-binsearch"),a=b.prop("href").substr(b.prop("href").lastIndexOf("search?f=")+9);g.append($("<a />",{href:"http://www.addic7ed.com/serie/"+f+"/"+e+"/"+c+"/1",title:"Download subtitles for "+h,"class":"button-link link-episode"}).append($("<img />",{src:"http://www.addic7ed.com/favicon.ico",alt:"Addic7ed"})));b.prop("target",null).children(":first").prop("src","http://kastatic.com/images/favicon.ico")})}else{if(oSeriesLis.length>0){oSeriesLis.each(function(){var g=$(this),h=$("#main .show-imageheading h1").text(),f=h.replace(/( )/g,"_").replace(/:/g,""),b=g.find(">a.button-binsearch");if(b.length===1){var a=b.prop("href").substr(b.prop("href").lastIndexOf("search?f=")+9),d=a.substr(a.lastIndexOf("+")+1),e=d.substring(1,d.indexOf("E")).replace(/^[0]+/g,""),c=d.substring(d.indexOf("E")+1).replace(/^[0]+/g,"");g.find(">span").before($("<a />",{href:"http://www.addic7ed.com/serie/"+f+"/"+e+"/"+c+"/1",title:"Download subtitles for "+h,"class":"button-link link-episode"}).append($("<img />",{src:"http://www.addic7ed.com/favicon.ico",alt:"Addic7ed"})));g.find(">p").css({width:"65%"});b.prop("target",null).children(":first").prop("src","http://kastatic.com/images/favicon.ico")}if("specials"===$(".list-episodes>li:first-child").text().toLowerCase().substring(0,8)){$('.list-episodes>ul:not(:first) img[src$="img/unwatched.png"]:first').closest("ul").prev()[0].scrollIntoView(true)}else{$('.list-episodes>ul img[src$="img/unwatched.png"]:first').closest("ul").prev()[0].scrollIntoView(true)}})}};});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment