Advertisement
tonyrulez

Myep + nCore [UserScript]

Feb 5th, 2015
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           MyEpisodes.com + nCore
  3. // @namespace      ghoofy007
  4. // @description    Minden epizód mellé belinkeli az nCore keresést Sorozatok kategóriában
  5. // @include        http://www.myepisodes.com/*
  6. // ==/UserScript==
  7.  
  8. // I hope the guys at the forum myepisodes.com don't mind that I kind of copied their NZB-search script and rewrote it to
  9. // let it search on ThePirateBay.se
  10. // Szintúgy módosítva, csak nCore-hoz :D
  11.  
  12. // Version 1.1
  13.  
  14. // Javítva: "Season X" helyett "S0X", így évadpakkra is ad találatot.
  15. // Fixed search attributes in nCore link
  16. var searchAttributes = "&miben=name&tipus=kivalasztottak_kozott&tags=";
  17.  
  18. // Find all the rows in the table that makes up the
  19. // episodes list.
  20. var mylistRows = document.evaluate(
  21.     '//table[@class="mylist"]/tbody/tr',
  22.     document,
  23.     null,
  24.     XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  25.     null);
  26.  
  27. var seasonHeaders = new Array();
  28. var showName;
  29.    
  30. for(var i=0 ; i < mylistRows.snapshotLength ; i++){
  31.    var row = mylistRows.snapshotItem(i);
  32.    if(row.className == "header"){
  33.       // Header row, need only extend it to add tbp colum
  34.       th = getEmptyHeaderCell();
  35.       row.appendChild(th);
  36.       if(row.childNodes[1].className=="season"){
  37.          seasonHeaders[seasonHeaders.length]=th;
  38.       }
  39.      
  40.    } else if(row.className.substring(0,7)=="Episode"){
  41.       // Episode row. Extract information and add link.
  42.      
  43.       // Find episode data
  44.       var theDate;
  45.       var episodeNumber;
  46.       var episodeName;
  47.      
  48.       for(var j=0 ; j<row.childNodes.length; j++){
  49.          var td = row.childNodes[j];
  50.          
  51.          // DATE
  52.          if(td.className=="date"){
  53.             // Date can also be time.
  54.             // Proper date contains either an A tag or is 11 characters
  55.             // dd-MM-yyyy, either way the innerHTML length is > 6
  56.             if(td.innerHTML.length>6){
  57.                // Got the one.
  58.                if(td.childNodes[0].nodeType==1){
  59.                   // Date is inside an A tag.
  60.                   theDate = td.childNodes[0].innerHTML;
  61.                } else {
  62.                   theDate = td.innerHTML;
  63.                }
  64.             }
  65.            
  66.          // SHOW NAME
  67.          } else if(td.className=="showname"){
  68.             // May be inside an A tag
  69.             if(td.childNodes[0].nodeType==1){
  70.                // Date is inside an A tag.
  71.                showName = td.childNodes[0].innerHTML;
  72.             } else {
  73.                showName = td.innerHTML;
  74.             }
  75.          
  76.          // EPISODE NUMBER
  77.          } else if(td.className=="longnumber"){
  78.             episodeNumber = "S"+ td.innerHTML.replace("x","E");
  79.            
  80.          // EPISODE NAME
  81.          } else if(td.className=="epname"){
  82.             // Always inside an A tag
  83.             episodeName = td.childNodes[0].innerHTML;
  84.          }
  85.            
  86.       }
  87.      
  88.       // Add link.
  89.       row.appendChild(
  90.          getTPBcell(
  91.             createSearchURL(
  92.                showName,
  93.                episodeNumber,
  94.                episodeName),
  95.             hasNotAired(theDate)
  96.             )
  97.          );
  98.    }
  99.  
  100. }
  101.  
  102. for(var i=0 ; i<seasonHeaders.length ; i++){
  103.    var th = seasonHeaders[i];
  104.    th.appendChild(getShowSeasonLink(showName,i+1));
  105.    th.style.paddingRight="2px";
  106. }
  107.  
  108. if(seasonHeaders.length>0){
  109.    // Add Episodes by Show link to find all episodes on ThePirateBay
  110.    var offset = 11;
  111.    
  112.    // Check if the episode is on 'my list'
  113.    var tvRageLink = document.evaluate(
  114.          '/html/body/table/tbody/tr/td[2]/div[@id="divContainer"]/div[@id="myepisodes_views"]/table[5]/tbody/tr[2]/td/a',
  115.          document,
  116.          null,
  117.          XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  118.          null).snapshotItem(0);
  119.    if(tvRageLink==null){
  120.       tvRageLink = document.evaluate(
  121.             '/html/body/table/tbody/tr/td[2]/div[@id="divContainer"]/div[@id="myepisodes_views"]/table[2]/tbody/tr[2]/td/a',
  122.             document,
  123.             null,
  124.             XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  125.             null).snapshotItem(0);
  126.       offset = 5;
  127.    }
  128.    
  129.    tvRageLink.innerHTML="Info"
  130.    
  131.    var theDiv = document.evaluate(
  132.          '//div[@id="myepisodes_views"]',
  133.          document,
  134.          null,
  135.          XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  136.          null).snapshotItem(0);
  137.    
  138.    var tvrageTable = theDiv.childNodes[offset];
  139.    tvrageTable.style.cssFloat= "left";
  140.    tvrageTable.style.marginRight= "10px";
  141.  
  142.    var table = document.createElement("table");
  143.    table.style.border = "1px solid black";
  144.    table.cellPadding = "6";
  145.    table.cellSpacing = "0";
  146.    
  147.    theDiv.insertBefore(table,theDiv.childNodes[offset+1]);
  148.  
  149.    table.innerHTML+="<tbody><tr class='header' align='center'><td style='border-bottom: 1px solid black;'>ThePirateBay</td></tr><tr align='center'><td><a href='https://ncore.cc/torrents.php?nyit_sorozat_resz=true&kivalasztott_tipus%5B%5D=xvidser_hun&kivalasztott_tipus%5B%5D=xvidser&kivalasztott_tipus%5B%5D=dvdser_hun&kivalasztott_tipus%5B%5D=dvdser&kivalasztott_tipus%5B%5D=hdser_hun&kivalasztott_tipus%5B%5D=hdser&mire=" + showName + searchAttributes + "' target='_blank' class='flatbutton'>Search</a></td></tr></tbody>";
  150.  
  151.    var epByShowHeader = document.evaluate(
  152.           '/html/body/table/tbody/tr/td[2]/div[@id="divContainer"]/div[@id="myepisodes_views"]/div/div',
  153.           document,
  154.           null,
  155.           XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  156.           null).snapshotItem(0)
  157.    epByShowHeader.innerHTML = "<div style='float:right; padding-top: 8px; padding-right: 2px; font-size: 12pt;'>" + showName + "</div>";
  158.  
  159. }
  160.  
  161.  
  162.  
  163. // ***************
  164. // Functions begin
  165. // ***************
  166.  
  167.  
  168. // Create empty header cell (th) used for cosmetic effect
  169. function getEmptyHeaderCell(){
  170.    var th = document.createElement("th");
  171.    th.appendChild(document.createTextNode("\u00a0"));
  172.    return th;
  173. }
  174.  
  175. // Create the table cell (td) that contains the nCore link.
  176. function getTPBcell(linkURL, fadeLink){
  177.    var td = document.createElement("td");
  178.    td.style.paddingLeft="2px";
  179.    td.style.paddingRight="2px";
  180.  
  181.    var link = document.createElement("a");
  182.    link.href=linkURL;
  183.    link.target = "_blank";
  184.    link.addEventListener("mouseover",linkOver,false);
  185.    link.addEventListener("mouseout",linkOut,false);
  186.    link.appendChild(document.createTextNode("nCore"));
  187.    if(fadeLink){
  188.       link.style.color = "grey";
  189.    }
  190.  
  191.    td.appendChild(link);
  192.    return td;
  193. }
  194.  
  195. function getShowSeasonLink(showName, season){
  196.    var link = document.createElement("a");
  197.    link.href= createSimpleSearchURL(showName + " S0" + season);
  198.    link.target = "_blank";
  199.    link.addEventListener("mouseover",linkOver,false);
  200.    link.addEventListener("mouseout",linkOut,false);
  201.    link.appendChild(document.createTextNode("nCore"));
  202.    link.style.fontWeight="normal";
  203.    return link;
  204. }
  205.  
  206. // Create the PirateBay search URL
  207. function createSearchURL(showName, episodeNumber, episodeName){
  208.    searchterm = showName + " " + trimNumber(episodeNumber);
  209.    return createSimpleSearchURL(searchterm);
  210. }
  211.  
  212. function createSimpleSearchURL(searchterm){
  213.    var url = "https://ncore.cc/torrents.php?nyit_sorozat_resz=true&kivalasztott_tipus%5B%5D=xvidser_hun&kivalasztott_tipus%5B%5D=xvidser&kivalasztott_tipus%5B%5D=dvdser_hun&kivalasztott_tipus%5B%5D=dvdser&kivalasztott_tipus%5B%5D=hdser_hun&kivalasztott_tipus%5B%5D=hdser&mire=" +
  214.           searchterm + searchAttributes;
  215.    return url;
  216. }
  217.  
  218. // Trim leading zeros from episode number
  219. function trimNumber(s) {
  220.    return s.replace(/^0+/, '');
  221. }
  222.  
  223. // Event handler when mouseover a link
  224. function linkOver(){
  225.    this.style.textDecoration = "underline";
  226. }
  227.  
  228. // Event handler when mouseout a link
  229. function linkOut(){
  230.    this.style.textDecoration = "none";
  231. }
  232.  
  233. // Is the supplied date in the future?
  234. // dateString format: dd-MMM-yyyy (e.g. 16-Dec-2008)
  235. function hasNotAired(dateString){
  236.    if(dateString == "Unknown"){
  237.       return true;
  238.    }
  239.    var theDate = new Date();
  240.    year = dateString.substring(7,11);
  241.    day = dateString.substring(0,2);
  242.    month = dateString.substring(3,6);
  243.    
  244.    switch(month) {
  245.       case "Jan": month = 0; break;  
  246.       case "Feb": month = 1; break;  
  247.       case "Mar": month = 2; break;  
  248.       case "Apr": month = 3; break;  
  249.       case "May": month = 4; break;  
  250.       case "Jun": month = 5; break;  
  251.       case "Jul": month = 6; break;  
  252.       case "Aug": month = 7; break;  
  253.       case "Sep": month = 8; break;  
  254.       case "Okt": month = 9; break;  
  255.       case "Nov": month = 10; break;  
  256.       case "Dec": month = 11; break;  
  257.       default: month = 1;
  258.    }
  259.    theDate.setFullYear(year,month,day);
  260.    
  261.    var today = new Date();
  262.    
  263.    return theDate>today;
  264.  
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement