aboutsummaryrefslogtreecommitdiff
path: root/chrome/content/redirector.js
diff options
context:
space:
mode:
authorEinar Egilsson2007-05-21 22:03:05 +0000
committerEinar Egilsson2007-05-21 22:03:05 +0000
commit502c24f18cdfa0f808d9383313bb4f965c7fb11f (patch)
treec9f2523995b6fc59e3bf6cc3bcc9200bbedd5e95 /chrome/content/redirector.js
Redirector
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@53 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome/content/redirector.js')
-rw-r--r--chrome/content/redirector.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/chrome/content/redirector.js b/chrome/content/redirector.js
new file mode 100644
index 0000000..6767840
--- /dev/null
+++ b/chrome/content/redirector.js
@@ -0,0 +1,97 @@
+//// $Id$
+
+var Redirector = {
+
+ id : "redirector@einaregilsson.com",
+ name : "Redirector",
+ initialized : false,
+ strings : null,
+ redirects : [],
+
+ onLoad : function(event) {
+ try {
+
+ // initialization code
+ RedirLib.initialize(this);
+ RedirLib.debug("Initializing...");
+
+ $('contentAreaContextMenu')
+ .addEventListener("popupshowing", function(e) { Redirector.showContextMenu(e); }, false);
+ var appcontent = window.document.getElementById('appcontent');
+
+ if (appcontent && !appcontent.processed) {
+ appcontent.processed = true;
+
+ appcontent.addEventListener('DOMContentLoaded', function(event) {
+
+ Redirector.onDOMContentLoaded(event);
+
+ }, false);
+ }
+ this.strings = document.getElementById("redirector-strings");
+
+ RedirLib.debug("Finished initialization");
+ this.initialized = true;
+
+ } catch(e) {
+ //Don't use RedirLib because it's initialization might have failed.
+ if (this.strings) {
+ alert(this.strings.getString("initError")._(this.name) + "\n\n" + e);
+ } else {
+ alert(e);
+ }
+ }
+ },
+
+ onDOMContentLoaded : function(event) {
+ var redirect;
+ try {
+ for each (redirect in this.redirects) {
+ if (RedirectorCommon.wildcardMatch(redirect.pattern, window.content.location.href)) {
+ window.content.location.href = redirect.redirectUrl;
+ }
+ }
+ } catch(e) {alert(e);}
+
+ },
+
+ onUnload : function(event) {
+ //Clean up here
+ RedirLib.debug("Finished cleanup");
+ },
+
+ showContextMenu : function(event) {
+ if (gContextMenu.onLink) {
+ $("redirector-context").label = this.strings.getString('addLinkUrl');
+ } else {
+ $("redirector-context").label = this.strings.getString('addCurrentUrl');
+ }
+ },
+
+ onContextMenuCommand: function(event) {
+
+ params = { inn : { url : window.content.location.href}, out : {} };
+ if (gContextMenu.onLink) {
+ params.inn.redirect = gContextMenu.link.toString();
+ }
+
+ window.openDialog("chrome://redirector/content/redirect.xul",
+ "redirect",
+ "chrome,dialog,modal,centerscreen", params);
+
+ if (params.out.pattern) {
+ this.redirects.push(params.out);
+ }
+ },
+
+ onMenuItemCommand: function(event) {
+ window.openDialog("chrome://redirector/content/redirectList.xul",
+ "redirectList",
+ "chrome,dialog,modal,centerscreen", this);
+
+ },
+
+};
+
+window.addEventListener("load", function(event) { Redirector.onLoad(event); }, false);
+window.addEventListener("unload", function(event) { Redirector.onUnload(event); }, false); \ No newline at end of file