// ==UserScript==
// @name IMDb to CMA Link Creator
// @namespace http://www.ogndb.com
// @description Adds a link on IMDb.com by the celebrity's name to the search results for them on CelebrityMovieArchive.com.
// @match *.imdb.com/*
// @version 1.0d
// @copyright 2011+, Lassik
// @downloadURL https://update.greasyfork.icu/scripts/3905/IMDb%20to%20CMA%20Link%20Creator.user.js
// @updateURL https://update.greasyfork.icu/scripts/3905/IMDb%20to%20CMA%20Link%20Creator.meta.js
// ==/UserScript==
/****************************************************************
* This script is very simple and is only really a few actual *
* lines of code. I heavily commented this script so that it *
* would be easy to understand for anyone wanting to adjust it *
* to fit their needs or just to know what is being done. *
****************************************************************/
/****************************************************************
* Change the variable below if you'd like to use a different *
* site other than Celebrity Movie Archive *
****************************************************************/
var searchURL = "http://www.celebritymoviearchive.com/tour/search.php?searchstring=";
/****************************************************************
* Change the variable below if you'd like the text for the *
* created link to say something else. You can also comment it *
* out and uncomment the line below it if you'd like the *
* Celebrity Movie Archive fav icon image to show instead of *
* text. *
****************************************************************/
var linkText = "CMA";
//var linkText = "
";
/****************************************************************
* The following if statement is just used to verify that *
* you're on the actual celebrity's page vs the page of a movie *
* they were in. *
****************************************************************/
if(window.location.href.indexOf('name') != -1) {
/****************************************************************
* Grabbing the existing links on the page. *
****************************************************************/
var pageLinks = document.getElementsByClassName("infobar")[0].innerHTML;
/****************************************************************
* Grabbing the celebrity's name. *
****************************************************************/
var celebName = document.getElementsByClassName("header")[0].innerHTML;
/****************************************************************
* Replacing the spaces with + signs for a proper URL format. *
* Yes I know I could just use the encodeURIComponent() *
* function but since it's just spaces i'm working with, why *
* bother. *
****************************************************************/
celebName = celebName.replace(/\s/g, "+");
/****************************************************************
* There's an extra space at the end of the name that ends up *
* being an additional + sign. The following line just knocks *
* it off. *
****************************************************************/
celebName = celebName.slice(0, -1);
/****************************************************************
* Building the link from all the collected data. *
****************************************************************/
var cmaLink = " | " + "" + linkText + "";
/****************************************************************
* Inserting the link in to the page. *
****************************************************************/
document.getElementsByClassName("infobar")[0].innerHTML = pageLinks + cmaLink;
}
/****************************************************************
* The following if statement is just used to verify that *
* you're on the page of a movie vs the actual page for the *
* celebrity themselves. *
****************************************************************/
if(window.location.href.indexOf('title') != -1) {
/****************************************************************
* There are 2 different styles of pages depending on if you're *
* looking at the full cast of a movie or just the original *
* overview page that only shows a few main cast members. The *
* following if statement is used to verify which page you're *
* looking at. *
****************************************************************/
if(window.location.href.indexOf('combined') != -1) {
/****************************************************************
* Createing an array of all the links containing the *
* celebrity's names. (full cast page) *
****************************************************************/
var celebArray = document.getElementsByClassName("nm");
/****************************************************************
* The following loop just cycles through the array that was *
* created earlier, inserting the new links. *
****************************************************************/
for (i=0; i| " + "" +
linkText + "";
}
}else {
/****************************************************************
* Createing an array of all the links containing the *
* celebrity's names. (brief cast page) *
****************************************************************/
var celebArray = document.getElementsByClassName("cast_list")[0].
getElementsByClassName("itemprop");
/****************************************************************
* The following loop just cycles through the array that was *
* created earlier, inserting the new links. *
****************************************************************/
for (i=0; i| " + "" +
linkText + "";
}
}
}
}
/****************************************************************
* The following if statement is just used to verify that *
* you're on a list page. *
****************************************************************/
if(window.location.href.indexOf('list') != -1) {
/****************************************************************
* Createing an array of all the links containing the *
* celebrity's names. *
****************************************************************/
var celebArray = document.getElementsByClassName("info");
/****************************************************************
* The following loop just cycles through the array that was *
* created earlier, inserting the new links. *
****************************************************************/
for (i=0; i" +
linkText + "";
}
}
}