There are 1 previous version of this script.
// This is a script for the IMDB site. It emphasize links to movies in your
// "My Movies" and "Vote History" lists. For instance, on an actor's page,
// you'll easily notice which of his/her movies you've already seen/voted.
//
// Copyright (c) 2008, Ricardo Mendonça Ferreira (ric@mpcnet.com.br)
// Released under the GPL license - http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name IMDB "My Movies" enhancer
// @description Emphasize the links for movies on your "My Movies" & "Vote History" list
// @namespace http://www.flickr.com/photos/ricardo_ferreira/2502798105/
// @include http://*imdb.com/*
// @exclude http://i.imdb.com/*
// @version 2008.08.27
// ==/UserScript==
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://www.greasespot.net/
// Install Greasemonkey, then restart Firefox and revisit this script.
//
// To uninstall, go to Tools/Greasemonkey/Manage User Scripts,
// select this script and click Uninstall.
//
// --------------------------------------------------------------------
//
// History:
// --------
// 2008.08.27 Explicitly send cookies (needed to be compatible with FF3)
// 2008.07.27 Fixed bug where removed movies where not actually removed;
// now also highlight the title of the movies
// 2008.06.11 Fixed bug that ketp growing the movie data in Firefox;
// now also get the vote history
// 2008.05.18 First public release
// 2008.05.12 First test version, private use only
//
(function() {
var myname = 'IMDB "My Movies" Enhancer';
// Find current logged user, or quit script
var user = '';
var account = document.getElementById('nb15personal');
if (account) {
var result = account.innerHTML.match(/\s*([^>]+)'s account/);
if (result && result[1]) {
user = result[1];
}
}
if (!user)
return;
// Movie data is loaded as string, and split into an array
//GM_setValue("mymovies:"+user, '');
var mymovies = new Array;
if (GM_getValue("mymovies:"+user))
{ mymovies=GM_getValue("mymovies:"+user).split('|'); }
function addMovies(responseDetails) {
links = responseDetails.responseText.match(/<a href=".title.tt[0]*(\d+)\//g);
if (!links) {
GM_log('No links found in movies list!'); // responseDetails.responseText
return;
}
for (var i=0; i < links.length; i++) {
var m = links[i].match(/tt[0]*(\d+)\/$/);
if (!m) continue;
// I "encode" the movie number with "base 36" to save memory
num = parseInt(m[1]).toString(36);
if (mymovies.indexOf(num) == -1)
{ mymovies.push(num); }
}
GM_setValue("mymovies:"+user, mymovies.join('|'));
responseDetails.responseText = '';
links = '';
}
var firstRun = 0;
// this callback function receives the MyMovies HTML page
function gotList1(responseDetails, firstRun) {
mymovies = new Array;
addMovies(responseDetails);
// Get VoteHistory full page
GM_xmlhttpRequest({
method : 'GET',
url : 'http://www.imdb.com/mymovies/list?votehistory&a=1',
headers: { 'Cookie': document.cookie },
onload : function(responseDetails) { gotList2(responseDetails, firstRun) },
onerror: function(responseDetails) { gotListError(responseDetails) }
});
}
// this callback function receives the VoteHistory HTML page
function gotList2(responseDetails, firstRun) {
if (firstRun) {
alert("Done!\n\n" +
"Next time you load an IMDB page the '" + myname +
"' will work.\n\nEnjoy!");
}
addMovies(responseDetails);
}
function gotListError(responseDetails) {
alert('Error loading your list of movies: '+
responseDetails.status + ' ' + responseDetails.statusText);
}
function updateMovieList() {
if (!GM_xmlhttpRequest) {
alert('Please upgrade to the latest version of Greasemonkey.');
return;
}
// First run?
firstRun = 0;
if (!mymovies.length) {
firstRun++;
alert("We have to update the data for the '"+myname+"'\nPress OK and wait a moment, please...");
}
// Get MyMovies full page
GM_xmlhttpRequest({
method : 'GET',
url : 'http://www.imdb.com/mymovies/list?a=1',
headers: { 'Cookie': document.cookie },
onload : function(responseDetails) { gotList1(responseDetails, firstRun) },
onerror: function(responseDetails) { gotListError(responseDetails) }
});
}
function scanLinks() {
if (!mymovies.length)
updateMovieList();
// Verify if the current page has a title to be highlighted
var m = document.location.href.match(/tt[0]*(\d+)\/$/);
if (m) {
var num = parseInt(m[1]).toString(36);
if (mymovies.indexOf(num) != -1) {
var title = document.getElementsByTagName('h1');
if (title) { title[0].style.color='green'; }
}
}
// Check all links in the page
var anchors = document.getElementsByTagName('a');
for (var i=0; i < anchors.length; i++) {
var a = anchors[i];
m = a.href.match(/tt[0]*(\d+)\/$/);
if (!m) continue;
// I "encode" the movie number with "base 36" to save memory
num = parseInt(m[1]).toString(36);
if (mymovies.indexOf(num) != -1) {
a.style.fontWeight='bold';
//a.style.fontStyle='italic';
a.style.color='green';
}
}
}
//-------- "main" --------
if (document.location.href.indexOf('/mymovies/list') != -1)
{ updateMovieList(); }
else { scanLinks(); }
})()
