PK
7q6 content/PK
=q6b7 7 content/options.js/* **************************************************************************************
* options.js
* ==========
*
* Author: Geva Zeichner
* Forum: http://forums.mozillazine.org/viewtopic.php?t=408043
* Date: 02/06/2006
* Edited: 16/03/2007
**************************************************************************************/
var imdbp_options =
{
Handle_Sync: function(item_id)
{
var item_node = document.getElementById(item_id);
var modify_id = item_node.getAttribute("modify_id");
var modify_node = document.getElementById(modify_id);
var pref_id = item_node.getAttribute("preference");
var pref_value = document.getElementById(pref_id).value;
if (item_node.disabled == false)
this.Disable(modify_node, !pref_value);
},
Disable: function(curr_node, set)
{
var i = 0;
var rc;
// Set disable for node
curr_node.disabled = set;
// Set disable for node's children
if (curr_node.hasChildNodes())
{
rc = this.Disable(curr_node.childNodes[0], set);
while (curr_node.childNodes[i].nextSibling != null)
{
if (!rc || set)
rc = this.Disable(curr_node.childNodes[i].nextSibling, set);
i++;
}
}
return (curr_node.hasAttribute("modify_id") && !curr_node.checked);
}
};
PK
q6LA% % content/options.xul
PK
q6@z @z content/overlay.js/* **************************************************************************************
* overlay.js
* ==========
*
* Author: Geva Zeichner
* Forum: http://forums.mozillazine.org/viewtopic.php?t=408043
* Date: 15/04/2006
* Edited: 17/03/2007
**************************************************************************************/
window.addEventListener("load", function(e){imdb_preview.Handle_Load(e);}, false);
var imdb_preview =
{
/*****************************************************************************************
* Handle_Load(e)
* ==============
* Listeners, defs, inits...
*****************************************************************************************/
Handle_Load: function(e)
{
this.strbundle = document.getElementById("imdbp_overlay.strbundle");
// Shhh... listen...
window.addEventListener("unload", function(e){imdb_preview.Handle_Unload(e);}, false);
window.addEventListener("mouseover", function(e){imdb_preview.Handle_Mouse_Over(e);}, false);
window.addEventListener("mousemove", function(e){imdb_preview.Handle_Mouse_Move(e);}, false);
window.addEventListener("click", function(e){imdb_preview.Handle_Mouse_Click(e);}, false);
// Consts
this.TITLE_REGEXP = /^((http:\/\/)(\w*\.)?((imdb\.com)(.*)(\/title\/tt\d{7})(\/)?))$/;
this.ACTOR_REGEXP = /^((http:\/\/)(\w*\.)?((imdb\.com)(.*)(\/name\/nm\d{7})(\/)?))$/;
this.IMG_REGEXP = /^((http:\/\/ia\.imdb\.com\/media)(.*\.)(jpg)?(gif)?(png)?)$/;
this.MOVIE_TYPE = 1;
this.ACTOR_TYPE = 2;
this.NOT_SUBMITTED_IMG_PATH = "chrome://imdb_preview/skin/not_submitted.png";
this.LOADING_IMG_PATH = "chrome://imdb_preview/skin/loading.gif";
this.LOADING_BG_PATH = "chrome://imdb_preview/skin/loading_bg.png";
this.E404_IMG_PATH = "chrome://imdb_preview/skin/error_404.png";
this.ERROR_IMG_PATH = "chrome://imdb_preview/skin/error.png";
// Set variables
this.prefs = Components.classes['@mozilla.org/preferences-service;1'].
getService(Components.interfaces.nsIPrefService).
getBranch('extensions.imdb_preview.');
this.move_timer = "";
this.terminate_timer = "";
this.terminate_timer_on = false;
this.mouse_over_url_target = "";
this.loaded_url = "";
this.last_url = " ";
this.last_owner_doc = "";
this.last_mouse_over_event = "";
this.http_req = new XMLHttpRequest();
this.is_showing = false;
this.lock_processing = false;
this.last_processing = false;
this.page_x = 0;
this.page_y = 0;
this.check_timer = "";
this.loading_start_time = 0;
this.complete_loading_time = 0;
// Init preview settings //
// Create preview divs
this.preview_div = window._content.document.createElement("div");
this.text_div = window._content.document.createElement("div");
this.title_div = window._content.document.createElement("div");
this.director_div = window._content.document.createElement("div");
this.writer_div = window._content.document.createElement("div");
this.poster_div = window._content.document.createElement("div");
this.genere_div = window._content.document.createElement("div");
this.plot_div = window._content.document.createElement("div");
this.rating_div = window._content.document.createElement("div");
this.cast_div = window._content.document.createElement("div");
this.runtime_div = window._content.document.createElement("div");
this.country_div = window._content.document.createElement("div");
this.language_div = window._content.document.createElement("div");
this.awards_div = window._content.document.createElement("div");
this.recommend_div = window._content.document.createElement("div");
this.birthdate_div = window._content.document.createElement("div");
this.minibio_div = window._content.document.createElement("div");
this.filmography_div = window._content.document.createElement("div");
// Mark as our own stuff
this.preview_div.setAttribute("imdb_preview", "true");
this.text_div.setAttribute("imdb_preview", "true");
this.title_div.setAttribute("imdb_preview", "true");
this.director_div.setAttribute("imdb_preview", "true");
this.writer_div.setAttribute("imdb_preview", "true");
this.poster_div.setAttribute("imdb_preview", "true");
this.genere_div.setAttribute("imdb_preview", "true");
this.plot_div.setAttribute("imdb_preview", "true");
this.rating_div.setAttribute("imdb_preview", "true");
this.cast_div.setAttribute("imdb_preview", "true");
this.runtime_div.setAttribute("imdb_preview", "true");
this.country_div.setAttribute("imdb_preview", "true");
this.language_div.setAttribute("imdb_preview", "true");
this.awards_div.setAttribute("imdb_preview", "true");
this.recommend_div.setAttribute("imdb_preview", "true");
this.birthdate_div.setAttribute("imdb_preview", "true");
this.minibio_div.setAttribute("imdb_preview", "true");
this.filmography_div.setAttribute("imdb_preview", "true");
// Append divs
this.preview_div.appendChild(this.poster_div);
this.preview_div.appendChild(this.text_div);
this.text_div.appendChild(this.title_div);
this.text_div.appendChild(this.rating_div);
this.text_div.appendChild(this.cast_div);
this.text_div.appendChild(this.plot_div);
this.text_div.appendChild(this.birthdate_div);
this.text_div.appendChild(this.filmography_div);
this.text_div.appendChild(this.minibio_div);
this.poster_div.innerHTML = this.Build_Poster_IMG(this.LOADING_IMG_PATH);
},
/*****************************************************************************************
* Handle_Unload()
* ===============
* Cleanups...
*****************************************************************************************/
Handle_Unload: function()
{
if (this.prefs.prefHasUserValue("actual_loading_time"))
{
this.prefs.clearUserPref("actual_loading_time");
this.prefs.clearUserPref("complete_loading_time");
this.prefs.clearUserPref("poster_loading_time");
}
// Not used with 0.4+
if (this.prefs.prefHasUserValue("start_check"))
this.prefs.clearUserPref("start_check");
if (this.prefs.prefHasUserValue("stop_check"))
this.prefs.clearUserPref("stop_check");
if (this.prefs.prefHasUserValue("poster_timeout"))
this.prefs.clearUserPref("poster_timeout");
// Not used with 0.3+
if (this.prefs.prefHasUserValue("halt_time"))
this.prefs.clearUserPref("halt_time");
},
/*****************************************************************************************
* Handle_Mouse_Click(e)
* =====================
*****************************************************************************************/
Handle_Mouse_Click: function(e)
{
// If our target AND left clicked
if (e.target.id == "toggle_text_div" && e.which == 1)
{
// If want to show
if (this.text_div.style.display == "none")
{
this.text_div.style.display = "";
this.poster_div.style.margin = "0 0 -6 0";
this.prefs.setBoolPref('text_show', true);
}
// If want to hide
else
{
this.text_div.style.display = "none";
this.poster_div.style.margin = "";
this.prefs.setBoolPref('text_show', false);
}
}
},
/*****************************************************************************************
* Handle_Mouse_Over(e)
* ====================
* Gets info about what we stepped into
*****************************************************************************************/
Handle_Mouse_Over: function(e)
{
this.page_x = e.pageX;
this.page_y = e.pageY;
this.mouse_over_url_target = unescape(e.target.href);
this.last_owner_doc = e.originalTarget.ownerDocument;
this.last_mouse_over_event = e;
// If not related to us
if (e.target.parentNode.nodeName != "#document")
{
if ((e.target.getAttribute("imdb_preview") != "true") &&
(e.target.parentNode.getAttribute("imdb_preview") != "true") &&
(this.mouse_over_url_target != this.loaded_url))
{
// Terminate preview
if (!this.terminate_timer_on)
{
this.terminate_timer = setTimeout(
function()
{
imdb_preview.Terminate_Preview();
imdb_preview.terminate_timer_on = false;
imdb_preview.Dump("\nTERMINATING.\n");
}, this.prefs.getIntPref("hide_delay_time"));
this.terminate_timer_on = true;
this.Dump("\nTERMINATE...\n");
}
}
else
{
if (this.terminate_timer_on)
{
clearTimeout(this.terminate_timer);
this.terminate_timer_on = false;
this.Dump("\nDON'T TERMINATE!\n");
}
}
}
},
/*****************************************************************************************
* Handle_Mouse_Move(e)
* ====================
* Checks if we are halting somewhere
*****************************************************************************************/
Handle_Mouse_Move: function(e)
{
// Clear timer
clearTimeout(this.move_timer);
// If no preview currently showing
if (this.loaded_url == "")
{
var movie_delay = this.prefs.getIntPref("movie_delay_time");
var actor_delay = this.prefs.getIntPref("actor_delay_time");
// If it's a movie link
if ((this.mouse_over_url_target.match(this.TITLE_REGEXP)) &&
(movie_delay >= 0) &&
(e.target.parentNode.getAttribute("imdb_preview") != "true"))
// Start timer
this.move_timer = setTimeout(function(){imdb_preview.Handle_Mouse_Halt();},
movie_delay);
// If it's an actor link
else if ((this.mouse_over_url_target.match(this.ACTOR_REGEXP)) &&
(actor_delay >= 0) &&
(e.target.parentNode.getAttribute("imdb_preview") != "true"))
this.move_timer = setTimeout(function(){imdb_preview.Handle_Mouse_Halt();},
actor_delay);
}
},
/*****************************************************************************************
* Handle_Mouse_Halt()
* ===================
* Checks if we halted on the right spot
*****************************************************************************************/
Handle_Mouse_Halt: function()
{
// If standing on url that is different from the one stood on before
if (this.mouse_over_url_target != this.last_url)
{
// If it's a movie link
if (this.mouse_over_url_target.match(this.TITLE_REGEXP))
{
// Load url
this.Load_Target(this.mouse_over_url_target, this.MOVIE_TYPE);
this.loaded_url = this.mouse_over_url_target;
}
// If it's an actor link
else if (this.mouse_over_url_target.match(this.ACTOR_REGEXP))
{
// Load url
this.Load_Target(this.mouse_over_url_target, this.ACTOR_TYPE);
this.loaded_url = this.mouse_over_url_target;
}
}
this.last_url = this.mouse_over_url_target;
},
/*****************************************************************************************
* Load_Target(url_target, target_type)
* ====================================
* Retrives the target's html code and triggers its processing
*****************************************************************************************/
Load_Target: function(url_target, target_type)
{
clearTimeout(this.terminate_timer);
this.terminate_timer_on = false;
this.Terminate_Preview();
this.is_showing = true;
this.Dump("\nLoading...\n");
this.complete_loading_time = 0;
this.loading_start_time = new Date();
// Start showing preview box
this.Start_Preview();
// Load target
this.http_req.open('GET', url_target, true);
// Try to process before loading completed
this.check_timer =
window.setInterval(
function()
{
// Process
imdb_preview.Process_Response(imdb_preview.http_req.responseText,
target_type);
},
imdb_preview.prefs.getIntPref("check_intervals"));
// When finished loading
this.http_req.onreadystatechange =
function()
{
// If loading completed
if (imdb_preview.http_req.readyState == 4)
imdb_preview.timer = setTimeout(
function ()
{
// Stop check html
window.clearInterval(imdb_preview.check_timer);
try
{
// With no error
if (imdb_preview.http_req.status == 200)
{
var curr_date = new Date();
// This is the last processing
imdb_preview.last_processing = true;
// Process
imdb_preview.Process_Response(imdb_preview.http_req.responseText,
target_type);
imdb_preview.complete_loading_time =
curr_date - imdb_preview.loading_start_time;
imdb_preview.Dump("complete: " +
imdb_preview.complete_loading_time + " ms\n");
imdb_preview.prefs.setIntPref("complete_loading_time",
imdb_preview.complete_loading_time);
}
else
{
var curr_date = new Date();
imdb_preview.loading_end_time = curr_date;
imdb_preview.Dump("Error loading page\n");
imdb_preview.poster_div.innerHTML =
imdb_preview.Build_Poster_IMG(imdb_preview.ERROR_IMG_PATH);
}
}
catch(err)
{
imdb_preview.Dump(err);
}
}, 0);
};
this.http_req.send(null);
},
/*****************************************************************************************
* Start_Preview()
* ===============
* Prepares the preview for display. Shows the preview.
*****************************************************************************************/
Start_Preview: function()
{
var doc = window._content.document;
var top, left;
var height = this.prefs.getIntPref("text_height");
var poster_width = 100;
var text_width = this.prefs.getIntPref("text_width");
var padding = 5;
var total_height = padding + height + padding;
var total_width = padding + poster_width + padding + text_width + padding;
// If in upper half
if (this.page_y < (doc.defaultView.innerHeight / 2) + doc.defaultView.pageYOffset)
top = this.page_y + 5;
else top = this.page_y - total_height - 5;
// If in left half
if (this.page_x < (doc.defaultView.innerWidth / 2) + doc.defaultView.pageXOffset)
left = this.page_x + 5;
else left = this.page_x - total_width - 5;
// Position preview and set divs style
this.preview_div.setAttribute("style", "position: absolute; \
top: " + top + "px; \
left: " + left + "px; \
background-color: #FFFFCC; \
border: 1px solid black; \
padding: " + padding + ";");
this.poster_div.setAttribute("style", "float: left; \
margin: 0 0 -" + (padding + 1) + " 0;");
this.text_div.setAttribute("style", "overflow: auto; \
padding: 0 0 0 " + padding + "; \
width: " + text_width + "px; \
height: " + height + "px;");
// If user doesn't want the text
if (!this.prefs.getBoolPref('text_show'))
{
this.text_div.style.display = "none";
this.poster_div.style.margin = "";
}
// Show preview
window._content.document.body.appendChild(this.preview_div);
},
/*****************************************************************************************
* Process_Response(html_source, target_type)
* ==========================================
*****************************************************************************************/
Process_Response: function(html_source, target_type)
{
var movie = new Array(5);
var actor = new Array(6);
// If a movie page
if (target_type == this.MOVIE_TYPE)
{
// Process movie
this.Process_Movie_HTML(html_source, movie);
// If found title
if (movie['title'] != -1 && this.prefs.getBoolPref('display_title'))
this.title_div.innerHTML = "Title: " + movie['title'];
// If found poster
if (movie['poster'] != -1)
this.poster_div.innerHTML = this.Build_Poster_IMG(movie['poster']);
// If found plot
if (movie['plot'] != -1 && this.prefs.getBoolPref('display_plot'))
this.plot_div.innerHTML = "Plot: " + movie['plot'];
// If found rating
if (movie['rating'] != -1 && this.prefs.getBoolPref('display_rating'))
this.rating_div.innerHTML = "Rating: " + movie['rating'];
// If found cast
if (movie['cast'] != -1 && this.prefs.getBoolPref('display_cast'))
this.cast_div.innerHTML = "Cast: " + movie['cast'];
}
// If an actor page
else if (target_type == this.ACTOR_TYPE)
{
// Process actor
this.Process_Actor_HTML(html_source, actor);
// If found title
if (actor['title'] != -1 && this.prefs.getBoolPref('display_name'))
this.title_div.innerHTML = "Name: " + actor['title'];
// If found poster
if (actor['poster'] != -1)
this.poster_div.innerHTML = this.Build_Poster_IMG(actor['poster']);
if (this.prefs.getBoolPref('display_birthdate'))
{
// If found birthdate & location
if (actor['birthdate'] != -1 && actor['location'] != -1)
this.birthdate_div.innerHTML = "Birthdate: " + actor['birthdate'] +
", " + actor['location'];
// If found birthdate
else if (actor['birthdate'] != -1)
this.birthdate_div.innerHTML = "Birthdate: " + actor['birthdate'];
// If found location
else if (actor['location'] != -1)
this.birthdate_div.innerHTML = "Birthplace: " + actor['location'];
}
// If found filmography
if (actor['filmography'] != -1 && this.prefs.getBoolPref('display_filmography'))
this.filmography_div.innerHTML = actor['filmography'];
// If found minibio
if (actor['minibio'] != -1 && this.prefs.getBoolPref('display_minibio'))
this.minibio_div.innerHTML = "Minibio: " + actor['minibio'];
}
this.last_processing = false;
},
/*****************************************************************************************
* Process_Movie_HTML(html_source, movie)
* ======================================
*****************************************************************************************/
Process_Movie_HTML: function(html_source, movie)
{
var max_actors = this.prefs.getIntPref('max_actors');
movie['title'] = -1;
movie['poster'] = -1;
movie['plot'] = -1;
movie['rating'] = -1;
movie['cast'] = -1;
// Title
movie['title'] = this.Retrieve_String(html_source, '
', '', '');
// Poster
movie['poster'] = this.Retrieve_String(html_source, '', '', '');
// Poster
actor['poster'] = this.Retrieve_String(html_source,
'', '');
// Location of birth
actor['location'] = this.Retrieve_Birth_Country(html_source);
// Filmography
actor['filmography'] = this.Retrieve_Filmography(html_source, max_films);
// Mini biography
actor['minibio'] = this.Retrieve_String(html_source,
'Mini Biography', '', '', ' votes');
top_250 = this.Retrieve_String(source, 'User Rating:', 'Top 250: #', '');
if (rating != -1)
{
rating += "/10";
if (votes != -1)
rating += " (" + votes + ")";
if (top_250 != -1)
rating += " #" + top_250;
}
return(rating);
},
/*****************************************************************************************
* Retrieve_Cast (source, max_actors)
* ==================================
*****************************************************************************************/
Retrieve_Cast: function(source, max_actors)
{
var actors_list = -1;
var actor_name, tr_pos;
var actors = 0;
// Leave only the cast
source = this.Retrieve_String(source,
'',
'');
if (source != -1)
{
actors_list = "";
tr_pos = source.indexOf('',
'| ',
' | ');
actors_list = actors_list + actor_name + ', ';
actors++;
tr_pos = source.indexOf('
', '');
year = this.Retrieve_String(source, 'BornInYear', '">', '');
if (month != -1 && year != -1)
found_string = month + " " + year;
else if (month != -1)
found_string = month;
else if (year != -1)
found_string = year;
return(found_string);
},
/*****************************************************************************************
* Retrieve_Birth_Country (source)
* ===============================
*****************************************************************************************/
Retrieve_Birth_Country: function(source)
{
var country = -1;
var location, parts;
// Get entire location
location = this.Retrieve_String(source, 'BornWhere', '">', '');
if (location != -1)
{
// If contains city as well
if (location.indexOf(",") != -1)
{
parts = location.split(",");
country = parts[parts.length - 1];
}
else
country = location;
this.Trim(country);
}
return(country);
},
/*****************************************************************************************
* Retrieve_Filmography (source, max_films)
* ========================================
*****************************************************************************************/
Retrieve_Filmography: function(source, max_films)
{
var films_list = -1;
var film_source, film_url, film_name, il_pos, label;
var films = 0;
// Get participation type
var type = this.Retrieve_String(source,
'