IMDB Parental Guide

Parents guide on your movie title page.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name       IMDB Parental Guide
// @version    1.0
// @description  Parents guide on your movie title page.

// @include /^http://www\.imdb\.com/title/tt[0-9]*/\?ref*
// @include /^http://www\.imdb\.com/title/tt[0-9]*/$/
// @include /^http://www\.imdb\.com/title/tt[0-9]*$/
// @copyright  2014+, Jay V
// @require http://code.jquery.com/jquery-latest.js
// @namespace https://greatest.deepsurf.us/users/4016
// ==/UserScript==


function Tuple(title,rating,text) {
    this.title = title;
    this.rating = rating;
    this.text = text;
}

Tuple.prototype.getTitle  = function() {
    return this.title;
};
Tuple.prototype.getRating = function() {
    return this.rating;
};
Tuple.prototype.getText = function() {
    return this.text;
};

$( document ).ready( getRatings );

function getRatings() {
    $.get( "parentalguide", function( data ) {
        var parsedHTML = $.parseHTML(data);
        var sectiontitles = $('.section',parsedHTML).children('h3');
        var sectionElements =  $('.display', parsedHTML);
        var tuples = [];
        var sectionTitlesTxts = [];
        $.each(sectiontitles,function(i){
            sectionTitlesTxts.push($(this).text());
        });        
        if(sectionElements.length == sectiontitles.length+2)  {
            $.each(sectionElements,function(index) {
                if(index==0 || index == sectionElements.length-1) {
                    //skip first and last sections 
                    return;
                }
                else {
                    var text = $(this).text();
                    if(text.trim().length==0) return;
                    var rating = text.match(/(\d?\d)\/10/);
                    if (rating!=null) rating=rating[1];
                    else rating = 0;
                    tuples.push(new Tuple(sectionTitlesTxts[index-1].trim(),rating,text.trim()));
                }
            });  
        }
        else {
            return;
        }
        renderRatings(tuples);
    });
}

function renderRatings(tuples) {
    var parentalGuideStart = '<div class="aux-content-widget-3 links subnav" div="parentalguide">  <h3><a style="color:inherit!important" href="parentalguide">Parental Guide</a></h3>  <div id="maindetails_quicklinks">';
    var parentalGuideContent = '';
    var ratingStars = ' <div class="star-box-rating-widget"> <div class="rating rating-list" data-starbar-class="rating-list"> <span class="rating-bg">&nbsp;</span> <span class="rating-stars"> ';
    $.each(tuples,function(idx,tuple) {
        parentalGuideContent +=  '<span title="'+tuple.getText().replace(/"/g, '&quot;')+'">' + tuple.getTitle() +'</span>'+ ratingStars;
        var rating = tuple.getRating();
        $.each([1,2,3,4,5,6,7,8,9,10],function(i,value) {
            if(value<=rating) 
                parentalGuideContent += '<a rel="nofollow" class="rating-your"><span>' + value + '</span></a>';
            else 
                parentalGuideContent += '<a rel="nofollow" class><span>' + value + '</span></a>';
        });
        parentalGuideRating = '<span class="rating-rating"><span class="value">' + rating + '</span><span class="grey">/</span><span class="grey">10</span></span>';
        parentalGuideContent += '</span> ' + parentalGuideRating + ' </div> </div>';
    });  
    if(parentalGuideContent!='') {
        var finalContent = parentalGuideStart + parentalGuideContent + ' </div> </div>'
        $('#maindetails_sidebar_bottom').filter(":first").prepend($(finalContent).hide().fadeIn('slow'));
    }    
}