// ==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://greasyfork.org/users/4016 // @downloadURL https://update.greasyfork.icu/scripts/3745/IMDB%20Parental%20Guide.user.js // @updateURL https://update.greasyfork.icu/scripts/3745/IMDB%20Parental%20Guide.meta.js // ==/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 = '' $('#maindetails_sidebar_bottom').filter(":first").prepend($(finalContent).hide().fadeIn('slow')); } }