您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Rozšíření profilů filmů na ČSFD.
当前为
- // ==UserScript==
- // @name ČSFD Extended
- // @namespace CSFD-E
- // @version 0.2.1
- // @description Rozšíření profilů filmů na ČSFD.
- // @author Jakub Rychecký <jakub@rychecky.cz>
- // @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+' 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+' recenzí');
- $('#csfd-e-rating .tomato-audience .rating').html(this.userMeter+'%');
- $('#csfd-e-rating .tomato-audience .votes').html(this.userReviews+' 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;
- this.request;
- var parent = this;
- this.init = function(){
- var html = '<img id="csfd-e-floating" src="" alt="" />';
- $('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.hide();
- parent.floating.attr('src', '');
- parent.request.abort();
- });
- }
- 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.floating.attr('src', poster_url);
- parent.floating.css({'display': 'inline'});
- });
- this.refresh(poster);
- }
- this.bindCreator = function(){
- var links = $('body a');
- links.mouseenter(function(e){
- var href = $(this).attr('href');
- parent.floating.css({'display': 'inline'});
- if(href.indexOf('/tvurce/') == -1){
- return false;
- }
- parent.request = $.ajax({
- method: 'GET',
- url: href
- });
- parent.request.done(function(response){
- var img = $(response).find('#profile .image img').attr('src');
- parent.floating.attr('src', img);
- });
- return true;
- });
- this.refresh(links);
- }
- };