Modification of script
![]() |
I've modified this script to do some useful things (for me) & thought I'd share. If these changes make sense to the developer, it would be cool if they were included in the official script so they will carry over into future updates. What it does: 1. Changes the RT tomato icon link to be a search query rather than a direct link to the movie page, since in some cases a direct link generated by this script will not accord with the actual movie page URL at RT. For instance, the page URL for Moonlighting (1982) is http://www.rottentomatoes.com/m/1014215-moonlig... rather than the expected & generated http://www.rottentomatoes.com/m/moonlighting/ . The script cannot predict something like this so it seems more useful to have a search link that will always return something useful rather than a direct page link that may give only a 404 error.
This way, if the rottenTomatoesName generated does not match an actual movie page name at RT, the unable to find text will link to a site search. If the rottenTomatoesName generated does match an actual movie page name at RT, the big rating tomato will link directly to that page. In either case, there is always a link to the site search for the movie title available, the little tomato in the lower row of icons, so that there will always be a quick link to useful information even if attempts to find the movie's direct page fail. In addition, I have changed the code in 'var rottenTomatoesName' to replace periods rather than stripping them, since RT expects underscores in place of periods in its movie page URLs. So a movie such as Life 2.0 needs to be Life_2_0 rather than Life_20. Then I have made a separate variable that doesn't replace spaces with underscores, since this is needed for building search URLs. I think replacing spaces with - (hyphens, dashes) would work too, but leaving them as spaces works just as well. I've changed the code in three other places in order to get this all working. I'm pasting the complete code below. The old code is commented out & the new code inserted below it in all three places. Cheers,
-----
// ==UserScript==
// @name Netflix Customization: Adding Rotten Tomatoes, Pirate Bay and Apple Trailers Links
// @description Adds custom features to Netflix
// @include http://www.netflix.com/Movie/*
// @include http://www.netflix.com/WiMovie/*
// @include http://movies.netflix.com/*
// @include https://www.netflix.com/Movie/*
// @include https://www.netflix.com/WiMovie/*
// @include https://movies.netflix.com/*
// @version 1.1.4
// ==/UserScript==
$ = unsafeWindow.jQuery;
var ratingsdiv = document.getElementById('mdp-boxshot');
if (ratingsdiv != null) {
var htmlcode = ratingsdiv.innerHTML;
//Changed to replace periods with underscores rather than stripping them - this is needed for making links to individual movie pages
var rottenTomatoesName = document.title.substring(9,document.title.length).toLowerCase().replace(/( |\.|-)/g, "_").replace(/&/g, "and").replace(/('|,|\?|\/|:|\[|\])/g, "").replace(/^(the|a)_/, "");
//Adding another variable that doesn't replace spaces with underscores - this is needed for site search rather than individual movie pages
var rottenTomatoesNameNoUnderscore = document.title.substring(9,document.title.length).toLowerCase().replace(/(\.|-)/g, "_").replace(/&/g, "and").replace(/('|,|\?|\/|:|\[|\])/g, "").replace(/^(the|a)_/, "");
// htmlcode = htmlcode + "<a href=\"http://www.rottentomatoes.com/m/"+rottenTomatoesName+"/\" target=\"_blank\"><img alt=\"RotTom\" style=\"height: 16px;\" title=\"Rotten Tomatoes\" src=\"http://images.rottentomatoes.com/images/tomatoes/fresh.gif\"&ht;</a> | ";
htmlcode = htmlcode + "<a href=\"http://www.rottentomatoes.com/search/?search="+rottenTomatoesNameNoUnderscore+"&sitesearch=rt\" target=\"_blank\"><img alt=\"RotTom\" style=\"height: 16px;\" title=\"Rotten Tomatoes\" src=\"http://images.rottentomatoes.com/images/tomatoes/fresh.gif\"></a> | ";
ratingsdiv.innerHTML = htmlcode;
var appleName = document.title.substring(9,document.title.length).toLowerCase().replace(/:/g,'').replace(/&/g, "and");
var prefix = appleName.substr(0,4);
if ('the_' == prefix) {
appleName = appleName.substr(4, rottenTomatoesName.length-4);
}
htmlcode = htmlcode + "<a href=\"http://www.thepiratebay.com/search/"+appleName+"/0/7/200"+"/\" target=\"_blank\"><img alt=\"The Pirate Bay\" style=\"height: 16px;\" title=\"The Pirate Bay\" src=\"http://thepiratebay.com/favicon.ico\"></a> | ";
ratingsdiv.innerHTML = htmlcode;
htmlcode = htmlcode + "<a href=\"http://www.apple.com/search/?q="+appleName+"\" target=\"_blank\"><img alt=\"Apple\" style=\"height: 16px;\" title=\"Apple Trailers\" src=\"http://cdn1.iconfinder.com/data/icons/vector_social_media_icons/16px/apple.png\"></a><br>";
ratingsdiv.innerHTML = htmlcode;
}
addRottenText();
getRottenRating(rottenTomatoesName);
function addRottenText() {
var findPattern = "//div[contains(@class, 'ratingsInfo')]";
var results = document.evaluate( findPattern, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
var link = results.snapshotItem(0);
var addedDivRotten = document.createElement('div');
var addedDivRotten_text;
addedDivRotten.innerHTML = '\nchecking';
addedDivRotten.setAttribute('id','greaseTextRotten');
addedDivRotten.setAttribute('style','color:#627d11;text-align:center;font-size:28px;font-weight:bold');
link.parentNode.insertBefore(addedDivRotten, link.nextSibling);
}
function getRottenRating(rottenTomatoesName) {
var rottenTomatoesURL = "http://www.rottentomatoes.com/m/" + rottenTomatoesName;
GM_xmlhttpRequest({
method: 'GET',
url: rottenTomatoesURL,
onload: function(responseDetails) {
var search_string_start = "all-critics-meter";
var match = responseDetails.responseText.search(search_string_start);
var responseHTML = responseDetails.responseText;
var rotten_rating = $('#all-critics-meter', responseHTML).html();
var testRating = rotten_rating;
var number_rotten_rating = parseInt(rotten_rating);
if (rotten_rating == "N/A")
{
rotten_rating = "n/a";
} else
{
rotten_rating = number_rotten_rating + "%";
}
if (match != -1) {
// found a rotten_rating
if ( number_rotten_rating == -1)
{
addedDivRotten.innerHTML = '\nNot enough reviews for a rating\n';
addedDivRotten.style.color='#627d11';
}
else { // best default case
var rotten_rating_image_url, rotten_rating_text;
var addedDivRotten = document.getElementById('greaseTextRotten');
if (number_rotten_rating >= 60) { // it's fresh
rotten_rating_image_url = 'http://images.rottentomatoes.com/images/tomatoes/fresh.gif';
rotten_rating_text = "Fresh";
}
else { // it's rotten
rotten_rating_image_url = 'http://images.rottentomatoes.com/images/tomatoes/rotten.gif';
rotten_rating_text = "Rotten";
}
// addedDivRotten.innerHTML = '\n' + rotten_rating + ' \n'<IMG SRC="' + rotten_rating_image_url + '" ALT="' + rotten_rating_text + '" title="' + rotten_rating_text + '" vertical-align="middle">\n';
addedDivRotten.innerHTML = '\n' + rotten_rating + ' \n <a href=\"'+rottenTomatoesURL+'\"><img src="' + rotten_rating_image_url + '" alt="' + rotten_rating_text + '" title="' + rotten_rating_text + '" vertical-align="middle"><\/a>\n';
}
} else {
// did not find rotten_rating
var addedDivRotten = document.getElementById('greaseTextRotten');
// htmlcode = "<a href=\"http://www.rottentomatoes.com/m/"+rottenTomatoesName+"/\" target=\"_blank\">Unable to find</a>";
htmlcode = "<a href=\"http://www.rottentomatoes.com/search/?search="+rottenTomatoesNameNoUnderscore+"&sitesearch=rt\" target=\"_blank\">Unable to find</a>";
addedDivRotten.innerHTML = htmlcode;
addedDivRotten.style.color='red';
}
}
});
} // end function getRottenRating
|
![]() |
Since search URLs at RT cannot have underscores, I have further modified the new variable I created not to make underscores out of spaces, periods, or hyphens.
|
![]() ![]() |
Henry, I like the changes you implemented. Doing a search query is much better than trying to guess the address using the movie name. I have updated my script to include your changes. You're more than welcome to keep on improving on the script. Thanks! --Brian |

