ČSFD Extended

Rozšíření profilů filmů na ČSFD.

目前為 2016-01-09 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         ČSFD Extended
// @namespace    CSFD-E
// @version      0.2.0
// @description  Rozšíření profilů filmů na ČSFD.
// @author       Jakub Rychecký <[email protected]>
// @include      *csfd.cz/film/*
// ==/UserScript==











var csfd = new Csfd(); // Instance třídy pro práci s profilem filmu na ČSFD
var omdb = new OmdbApi(csfd.parseCsfdImdbCode()); // Instance třídy pro práci s API OMDB a stažení informací o filmu
var imdb = new Imdb(csfd.parseCsfdImdbCode()); // Instance třídy s informacemi z IMDB
var metacritic = new Metacritic(); // Instance třídy s informacemi z Metacritic
var tomato = new Tomato(); // Instance třídy s informacemi z RottenTomatoes

var html = new Html(); // Instance třídy pro práci s HTML a úpravou profilu filmu dle získaných dat
var floating = new Floating();


omdb.fetchOmdbData(); // Stažení dat z API OMDB

csfd.parseCsfdNameYear(); // Parsuje název filmu z profilu ČSFD.
csfd.parseCsfdRating(); // Parsuje hodnocení ČSFDs

html.cssInit(); // Přidání externího CSS do stránky
html.ratingTable(); // Předělání tabulky hodnocení na profilu filmu
html.toolbar(); // Vytvoření tlačítek pro rychlé vyhledávání na profilu filmu

floating.init();
floating.bindPoster();
floating.bindCreator();









/*
console.log(csfd);
console.log(omdb);
console.log(imdb);
console.log(metacritic);
console.log(tomato);
console.log(html);
*/











/**
  * @class Csfd
  * @classdesc Parsuje a zpracovává základní údaje z ČSFD profilu filmu.
  * 
  * @param {String} name - Originální název filmu
  * @param {Integer} year - Rok vzniku filmu
  * @param {Integer} rating - ČSFD hodnocení filmu v procentech
  * @param {Integer} votes - Počet hlasů na ČSFD
 */

function Csfd(){
 this.name;
 this.year;
 this.rating;
 this.votes;    
  
  
  
  
  
  /**
   * Parsuje název filmu z profilu ČSFD.
   * @return {undefined}
   */
    
  this.parseCsfdNameYear = function(){
    var title = $('meta[property=\'og:title\']').attr('content'); // Získání popisu ČSFD profilu z metatagu Open Graph (OG) http://ogp.me/
    title = title.replace(/\(TV seriál\)/, ''); // Odstranění označení TV seriálů z názvu
    title = title.replace(/\(TV film\)/, ''); // Odstranění označení TV filmů z názvu
    var title_regex = title.match(/(.+)\((\d{4})\)/); // Rozdělení na název a rok v závorce
     
     
    this.name = title_regex[1]; // Název filmu
    this.name = this.name.replace(/.+\//, ''); // Získání čehokoliv před lomítkem (= originální název)
    this.name = $.trim(this.name); // Oříznutí mezer názvu filmu
    
    
    this.year = parseInt(title_regex[2]); // Rok názvu jako integer
  }
    
  
  
  
    
  /**
   * Parsuje procentuální hodnocení a počet hlasů z profilu ČSFD.
   * @return {undefined}
   */
  
  this.parseCsfdRating = function(){
    this.rating = $('meta[itemprop="ratingValue"]').attr('content'); // Získání procentuálního hodnocení z metatagů
    this.rating = parseInt(this.rating); // Hodnocení v procentech jako integer
    
    this.votes = $('meta[itemprop="ratingCount"]').attr('content'); // Získání počtu hlasů z metatagů
    this.votes = parseInt(this.votes); // Počet hlasů jako integer
  }
    
    
    
    
 
  /**
   * Parsuje kód filmu na IMDB z tlačítka IMDB na profilu filmu na ČSFD.
   * @return {String} Kód filmu na IMDB
   */
    
  this.parseCsfdImdbCode = function(){
    var imdb_url =  $('a[data-ga-event="imdb-film|click|logged"]').attr('href'); // Získání odkazu z tlačítka IMDB
    
    var imdb_code = imdb_url.match(/(tt\d+)/); // Extrahování kódu filmu na IMDB
    
    return imdb_code[1]; // Vrací extrahovaný kód IMDB
  }

 
};






function OmdbApi(imdb_code){
 this.imdb_code = imdb_code;    
   
 
 
 
 
 this.fetchOmdbData = function(){
    var request = $.ajax({
      method: 'GET',
      url: 'http://www.omdbapi.com/',
      data: {
        i: this.imdb_code,
        tomatoes: 'true',
        r: 'json'
      }
    });

    request.done(function(response){
      imdb.rating = parseFloat(response.imdbRating);
      imdb.votes = response.imdbVotes.replace(',', '');
      imdb.votes = parseInt(imdb.votes);

      metacritic.metascore = parseInt(response.Metascore);

      tomato.meter = parseInt(response.tomatoMeter);
      tomato.rating = parseFloat(response.tomatoRating);
      tomato.reviews = parseInt(response.tomatoReviews);
      tomato.userMeter = parseInt(response.tomatoUserMeter);
      tomato.userRating = parseFloat(response.tomatoUserRating);
      tomato.userReviews = parseInt(response.tomatoUserReviews);
      tomato.url = response.tomatoURL;

      imdb.insertRatingHtml();
      metacritic.insertRatingHtml();
      tomato.insertRatingHtml();

      html.ratingTableShow();
    });   
  }


};











function Imdb(imdb_code){
 this.imdb_code = imdb_code;   
 this.rating;
 this.votes;
    

 
 
 this.insertRatingHtml = function(){
    if(this.rating > 0){
      $('#csfd-e-rating .imdb').show();   
    }
     
     $('#csfd-e-rating .imdb .rating').html(imdb.rating);
     $('#csfd-e-rating .imdb .votes').html(imdb.votes+'&nbsp;hlasů'); 
     
     $('#csfd-e-rating .imdb a').attr('href', this.link());
 }
 
 this.link = function(){
   return 'http://www.imdb.com/title/'+this.imdb_code+'/'; 
 }
 
};











function Metacritic(){
 this.metascore;
    

 
 this.insertRatingHtml = function(){
    if(this.metascore > 0){
      $('#csfd-e-rating .metacritic').show();   
    }
     
    $('#csfd-e-rating .metacritic .rating').html(this.metascore);
     
    $('#csfd-e-rating .metacritic a').attr('href', this.link());
 }
 
 
 this.link = function(){
   return 'http://www.imdb.com/title/'+imdb.imdb_code+'/criticreviews'; 
 }
 
};











function Tomato(){
 this.meter;
 this.rating;
 this.reviews;
 this.userMeter;
 this.userRating;
 this.userReviews;
 this.url;
    
 
 this.insertRatingHtml = function(){
     if(this.meter > 0){
       $('#csfd-e-rating .tomato').show();   
     }
     
     $('#csfd-e-rating .tomato-critic .rating').html(this.meter+'%');
     $('#csfd-e-rating .tomato-critic .votes').html(this.reviews+'&nbsp;recenzí');
     
     $('#csfd-e-rating .tomato-audience .rating').html(this.userMeter+'%');
     $('#csfd-e-rating .tomato-audience .votes').html(this.userReviews+'&nbsp;hodnocení');
     
     $('#csfd-e-rating .tomato a').attr('href', this.link());
 }
       
 this.link = function(){
   return this.url;   
 }
 
};











function Html(){   
 
    
 this.cssInit = function(){
   var css_url = 'http://csfd-extended.rychecky.cz/css/csfd-extended.css';
   var css_html = '<link rel="stylesheet" type="text/css" href="'+css_url+'" />'; 
    
   $('head').append(css_html);
 }
    
 
 
 
 
 this.ratingTable = function(){
  var html = '<div id="csfd-e-rating" class="ct-related" style="display: none;">';
    
  html += '<div class="header"><h3>ČSFD Extended</h3></div>';   
     
     
  html += '<div class="content">'; 
     
     html += '<table>';     

     html += '<tr class="imdb" title="Otevřít profil na IMDB">';
     html += '<td class="favicon"><img src="http://www.google.com/s2/favicons?domain=imdb.com" alt="" /></td>';
     html += '<td class="title"><a href="" class="link">IMDB</a></td>';
     html += '<td class="rating"></td>';
     html += '<td class="votes"></td>';
     html += '</tr>';

     html += '<tr class="metacritic" title="Otevřít seznam recenzí Metacritic">';
     html += '<td class="favicon"><img src="http://www.google.com/s2/favicons?domain=metacritic.com" alt="" /></td>';
     html += '<td class="title"><a href="" class="link">Metacritic</a></td>';
     html += '<td class="rating"></td>';
     html += '</tr>';

     html += '<tr class="tomato tomato-critic" title="Otevřít profil na Rotten Tomatoes">';
     html += '<td class="favicon"><img src="http://www.google.com/s2/favicons?domain=rottentomatoes.com" alt="" /></td>';
     html += '<td class="title"><a href="" class="link">Tomatoes: kritici</a></td>';
     html += '<td class="rating"></td>';
     html += '<td class="votes"></td>';
     html += '</tr>';

     html += '<tr class="tomato tomato-audience" title="Otevřít profil na Rotten Tomatoes">';
     html += '<td class="favicon"><img src="http://www.google.com/s2/favicons?domain=rottentomatoes.com" alt="" /></td>';
     html += '<td class="title"><a href="" class="link">Tomatoes: diváci</a></td>';
     html += '<td class="rating"></td>';
     html += '<td class="votes"></td>';
     html += '</tr>'; 

     html += '</table>';
     
     
     html += '<div class="footer">by jaCUBE via <a href="https://greasyfork.org/cs/scripts/15784-%C4%8Csfd-extended">Greasy Fork</a>';
     
     
  html += '</div>';


   
    
  $('#rating').after(html);   
 }
 
 
 this.ratingTableShow = function(){
  $('#csfd-e-rating').slideDown();   
 }
 
 
 
 
 
 
 this.creatorPreview = function(){
  $('body a').mouseenter(function(e){
     var link = $(this).attr('href');

     if(link.indexOf('/tvurce/') == -1){
      return false;   
     }
      
    var request = $.ajax({
      method: 'GET',
      url: link
    });

    request.done(function(response){
      var name = $(response).find('#profile .info h1').text();
      var age =  $(response).find('#profile .info .age').text(); 
      var img =  $(response).find('#profile .image img').attr('src'); 
        
        
        
      console.log(img);  
    });  
      
    return true;
  });
     
     
     
 }
 
 
 
 
 this.toolbar = function(){
  var name_url = encodeURIComponent(csfd.name);
    
  var toolbar = '<div id="csfd-e-toolbar" class="'+this.toolbarCssClass()+'">';
  
  toolbar += '<a href="'+imdb.link()+'" target="_blank">IMDB</a>';
  toolbar += '<a href="https://www.google.cz/search?q='+name_url+'" target="_blank">Google</a>';   
  toolbar += '<a href="http://www.titulky.com/?Fulltext='+name_url+'" target="_blank">Titulky</a>';  
  toolbar += '<a href="http://www.uloz.to/hledej?media=video&protected=notPassword&redir=0&q='+name_url+'" target="_blank">Ulož.to</a>'; 
  toolbar += '<a href="http://www.yify-movies.net/search/'+name_url+'/" target="_blank">YIFY</a>';  
  toolbar += '<a href="https://torrentz.eu/search?q='+name_url+'" target="_blank">Torrentz</a>'; 
    
  toolbar += '</div>';

  $('#profile .creators').before(toolbar);  
 }
 
 
 
 
 this.toolbarCssClass = function(){
  if(csfd.rating >= 70){
    return 'red';
  }else if(csfd.rating >= 30){
    return 'blue';
  }else{
    return 'black';   
  }
 }
 
 
 
 
 
 
 
};








function Floating(){
 this.content = '';
 this.floating;   
 
 var parent = this;

    
    
    
    
    
 this.init = function(){
    var html = '<div id="csfd-e-floating"></div>';
     
    $('body').append(html);
     
    this.floating = $('#csfd-e-floating');
 }
 
 
  
 this.refresh = function(obj){
   obj.mousemove(function(e){
       parent.floating.css({'top': e.clientY + 20, 'left': e.clientX + 20});  
   });
     
     
   obj.mouseout(function(){
      parent.floating.css({'display': 'none'});   
   });  
 }
 
  
 
 
 
 
 this.bindPoster = function(){
   var poster = $('#poster img, #posters img');

   $('#show-all-posters').click(function(){
      parent.bindPoster(); 
   });

     
   poster.mouseenter(function(e){
       var poster_url = $(this).attr('src');
       poster_url = poster_url.replace(/\?.+/, '');
               
       parent.content = '<img src="'+poster_url+'" alt="" />';
       parent.floating.html(parent.content);
       parent.floating.css({'display': 'inline'});  
   });
     
   this.refresh(poster);  

 }
 
 
 
 
 
 
 this.bindCreator = function(){
   var links = $('body a');

     
   links.mouseenter(function(e){
       var href = $(this).attr('href');
       
     if(href.indexOf('/tvurce/') == -1){
      return false;   
     }
      
       
    var request = $.ajax({
      method: 'GET',
      url: href
    });

    request.done(function(response){
      var name = $(response).find('#profile .info h1').text();
      var age =  $(response).find('#profile .info .age').text(); 
      var img =  $(response).find('#profile .image img').attr('src'); 
        
       parent.content = '<img src="'+img+'" alt="" />';
       parent.floating.html(parent.content);
       parent.floating.css({'display': 'inline'});  
    });  
      
    return true;
   });
     
     
   this.refresh(links);
 }
 
 
 

 
 
 
 
 
};