0.91/chrome/content/overlay.js
Back to the directory
/*
--------------------------------------------------------
Notify
--------------------------------------------------------
Copyright (C) 2006, Gemme.pl
http://notify.torino.pl/en/
All rights reserved.
See attached file: LICENCE.TXT
--------------------------------------------------------
*/
var NotifyOverlay = {
onMenuItemCommand: function()
{
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var existingWindow = wm.getMostRecentWindow("notify:Sites");
if (existingWindow)
existingWindow.focus();
else
window.open("chrome://notify/content/notify.xul", "Notify", "centerscreen,chrome,resizable");
},
onContextCommand: function()
{
var url = getWebNavigation().currentURI.spec;
var Prompt = Components.classes["@mozilla.org/network/default-prompt;1"].createInstance(Components.interfaces.nsIPrompt);
if (gNotify.Prefs.sites.addObservedSite(url))
{
Prompt.alert(
gNotify.StrBundle.GetStringFromName("notify"),
gNotify.StrBundle.GetStringFromName("SiteAdded")
);
}
else
{
Prompt.alert(
gNotify.StrBundle.GetStringFromName("notify"),
gNotify.StrBundle.GetStringFromName("SiteAlreadyObserved2")
);
}
},
onContextClick: function(event)
{
document.getElementById("contentAreaContextMenu").hidePopup();
if (event.button == 1) // middle click
{
// open main window
this.onMenuItemCommand();
}
},
displayLastModified: function()
{
var d = new Date(window.content.document.lastModified);
var diff = 0;
if (window.content.document !== undefined &&
window.content.document.notifyDifference !== undefined &&
window.content.document.notifyDifference > 0)
{
diff = window.content.document.notifyDifference;
}
else
{
var now = new Date;
diff = (now - d);
window.content.document.notifyDifference = diff;
}
if (diff < 61000 // ms
// modified in the last minute - probably (99%?) server didn't sent
// correct Last-Modified header (eg. for a PHP document)
// - so don't display useless date
||
d.getFullYear() == 1970) // the "0" date - useless too
{
document.getElementById("notify-status-panel").hidden = true;
}
else
{
document.getElementById("notify-status-panel-label").value =
gNotify.StrBundle.GetStringFromName("StatusLastModified") + ' ' +
d.toLocaleDateString();
document.getElementById("notify-status-panel").hidden = false;
}
},
onLoad: function()
{
// concept from Uri Statusbar extension, https://addons.mozilla.org/firefox/1535/
var appcontent = document.getElementById("appcontent");
if (appcontent)
{
appcontent.addEventListener("load", NotifyOverlay.displayLastModified, true);
appcontent.addEventListener("focus", NotifyOverlay.displayLastModified, true);
}
}
};
var gNotify =
Components.classes['@torino.pl/notify;1']
.getService(Components.interfaces.nsINotify)
.wrappedJSObject;
if (gNotify.Prefs.displayLastModified)
{
window.addEventListener("load", NotifyOverlay.onLoad, false);
}