IMDB Parental Guide

Parents guide on your movie title page.

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

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

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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'));
    }    
}