ČSFD Extended

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

当前为 2015-12-31 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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


var title, name, year, rating, rate_count;
var imdb, imdb_url, imdb_code;

css_init();

csfd_parse_basic();
csfd_parse_imdb();
csfd_parse_rating();


csfd_score_redone();
create_toolbar();

imdb_api_fetch();

csfd_poster();


$('#show-all-posters').click(csfd_poster);





function csfd_parse_basic(){
    var title_regex;
    
    title = $('meta[property=\'og:title\']').attr("content");
    title = title.replace(/\(TV seriál\)/, '');
    title = title.replace(/\(TV film\)/, '');
    title_regex = title.match(/(.+)\((\d{4})\)/);

    name = title_regex[1];
    name = name.replace(/.+\//, '');
    name = $.trim(name);
    
    year = parseInt(title_regex[2]);
}




function csfd_parse_imdb(){
    imdb_url =  $('a[data-ga-event="imdb-film|click|logged"]').attr('href');
    imdb_url = imdb_url.replace('/combined', '');
    
    imdb_code = imdb_url.match(/(tt\d+)/);
    imdb_code = imdb_code[1]; 
}





function csfd_parse_rating(){  
    rating = $('meta[itemprop="ratingValue"]').attr('content');
    rating = parseInt(rating);
    
    rate_count = $('meta[itemprop="ratingCount"]').attr('content');
    rate_count = parseInt(rate_count); 
}




function create_toolbar(){
  var toolbar, name_url;
    
  name_url = encodeURIComponent(name);
    
  toolbar = '<div id="csfd-e-toolbar" class="'+csfd_toolbar_class()+'">';
  
  toolbar += '<a href="'+imdb_url+'" target="_blank">IMDB</a>';
  toolbar += '<a href="http://www.titulky.com/?Fulltext='+name_url+'" target="_blank">Titulky.com</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').prepend(toolbar);
}




function imdb_api_fetch(){
 var request;

 request = $.ajax({
     method: 'GET',
     url: 'http://www.omdbapi.com/',
     data: {
         i: imdb_code,
         plot: 'short',
         r: 'json'
     }
 });
    
  request.done(function(response){
      imdb = response;      
      imdb_score_expand();
  });       
}





function csfd_score_redone(){
  var html;
    
 
  html = '<table id="csfd-e-rating"><tr>';
    
  html += '<td class="csfd"><div class="title">ČSFD</div>';
  html += '<h2 class="rating">'+rating+'&nbsp;%</h2>';
  html += '<div class="count">'+rate_count+'&nbsp;hlasů</div></td>';
    
  html += '<td class="imdb" onclick="window.open(\''+imdb_url+'\');"><div class="title">IMDB</div>';
  html += '<h2 class="rating">n/a</h2>';
  html += '<div class="count">n/a</div></td>';
    
  html += '</tr></table>';


  html += '<div class="metascore" title="Hodnocení z profesionálních kritik agregované přes Metacritic">Metascore: <span class="value">n/a</span></div>'; 
    
  if($('#rating .charts').length > 0){
   html += '<p class="charts">'+$('#rating .charts').html()+'</p>';
  }
    
    
  $('#rating').html(html);
}



function imdb_score_expand(){
 var html;
    
 $('#csfd-e-rating .imdb .rating').html(imdb.imdbRating);
 $('#csfd-e-rating .imdb .count').html(imdb.imdbVotes+'&nbsp;hlasů');  
 $('.metascore .value').html(imdb.Metascore);     
}






function csfd_poster(){
    var poster_url, poster_html;
    
    poster_html = '<img src="" id="csfd-e-poster" alt="" />';
    
    $('body').append(poster_html);
    
    $("#poster img, #posters img").mouseenter(function(e){
        poster_url = $(this).attr('src');
        poster_url = poster_url.replace('?h180', '');
      
       
        $('#csfd-e-poster').attr('src', poster_url);
        $('#csfd-e-poster').css({'display': 'inline'});
    });
    
    $("#poster img, #posters img").mousemove(function(e){
        $('#csfd-e-poster').css({'top': e.clientY + 20, 'left': e.clientX + 20});
    });
    
    $("#poster img, #posters img").mouseout(function(e){
        $('#csfd-e-poster').css({'display': 'none'});
    });
}






function css_init(){
   var css_url, css_html;
    
   css_url = 'http://csfd-extended.rychecky.cz/css/csfd-extended.css';
   css_html = '<link rel="stylesheet" type="text/css" href="'+css_url+'" />'; 
    
   $('head').append(css_html);
}


function csfd_toolbar_class(){
  if(rating >= 70){
    return 'red';
  }
  
  return 'blue';
}