Advertisement
Guest User

myepisodes.js

a guest
Jun 2nd, 2013
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name MyEpisodes torrent link
  3. // @description Change the link on the episode from tvrage to torrentpage - piratebay
  4. // @include http://myepisodes.com/*
  5. // @include http://*.myepisodes.com/*
  6. // @match http://myepisodes.com/*
  7. // @match http://*.myepisodes.com/*
  8. // @version 1.1
  9. // @author kamilio
  10. // ==/UserScript==
  11.  
  12. // settings
  13. // %s will be replaced with searched expression
  14. // search engine - default pirate bay
  15. var engine = "http://thepiratebay.org/search/%s/0/7/0";
  16. // var engine = "http://www.mininova.org/search/%s/seeds";
  17.                                                          
  18.  
  19. (function( ) {
  20.  
  21.     // include jQuery
  22.     var headID = document.getElementsByTagName("head")[0];        
  23.     var newScript = document.createElement('script');
  24.     newScript.type = 'text/javascript';
  25.     newScript.id = 'myjQuery';
  26.     newScript.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js';
  27.     headID.appendChild(newScript);
  28.  
  29.     // format 01x02 -> S01E02
  30.     function getEpisode(string) {
  31.         return "S"+string.replace("x","E");
  32.     }
  33.    
  34.     // replace whitespace to +
  35.     function replaceSpace(string) {
  36.        return string.replace(" ","+");
  37.     }
  38.    
  39.     // get the search expression    
  40.     function getExpression(selector) {
  41.         var showname = replaceSpace($(".showname a",$(selector).parent()).text());
  42.     if (showname.trim() == "") { // didnt work in series view
  43.         showname = replaceSpace($(".showname",$(selector).parent()).text());
  44.     }
  45.         var episode = getEpisode($(".longnumber",$(selector).parent()).text());  
  46.         return showname+"+"+episode;    
  47.     }                                                      
  48.                                  
  49.                                  
  50.     // get the search link
  51.     function search(selector) {        
  52.         return engine.replace("%s",getExpression(selector))
  53.     }
  54.     window.addEventListener('load', function (e)  {
  55.       // jquery usage
  56.        $(document).ready(function(){
  57.        $(".epname").each(function(){ // foreach epname
  58.           $("a",this).attr("href",search(this)); // replace link in the name of episode      
  59.         });                                                                            
  60.        })          
  61.  
  62.     }, false);
  63.  
  64. })( );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement