aboutsummaryrefslogtreecommitdiff
path: root/chrome/content/redirector.js
diff options
context:
space:
mode:
authorEinar Egilsson2007-05-21 23:21:52 +0000
committerEinar Egilsson2007-05-21 23:21:52 +0000
commita7da44a01a575246c9fb55665c15ce9a9a400814 (patch)
treeaf6695987b18e529a2f76eac2268f5b1cc8541d8 /chrome/content/redirector.js
parent502c24f18cdfa0f808d9383313bb4f965c7fb11f (diff)
Redirector
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@54 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome/content/redirector.js')
-rw-r--r--chrome/content/redirector.js46
1 files changed, 41 insertions, 5 deletions
diff --git a/chrome/content/redirector.js b/chrome/content/redirector.js
index 6767840..732602b 100644
--- a/chrome/content/redirector.js
+++ b/chrome/content/redirector.js
@@ -17,6 +17,9 @@ var Redirector = {
$('contentAreaContextMenu')
.addEventListener("popupshowing", function(e) { Redirector.showContextMenu(e); }, false);
+
+ this.redirects = eval(RedirLib.getCharPref('redirects'));
+
var appcontent = window.document.getElementById('appcontent');
if (appcontent && !appcontent.processed) {
@@ -44,17 +47,48 @@ var Redirector = {
},
onDOMContentLoaded : function(event) {
- var redirect;
- try {
+ var redirect, link, links, url;
+
+ url = window.content.location.href;
+
+ RedirLib.debug('Processing url %1'._(url));
+
for each (redirect in this.redirects) {
- if (RedirectorCommon.wildcardMatch(redirect.pattern, window.content.location.href)) {
- window.content.location.href = redirect.redirectUrl;
+ if (RedirectorCommon.wildcardMatch(redirect.pattern, url)) {
+ RedirLib.debug('%1 matches %2'._(redirect.pattern, url));
+
+ if (redirect.onlyIfLinkExists) {
+
+ links = window.content.document.getElementsByTagName('a');
+
+ for each(link in links) {
+
+ if (link.href && link.href.toString() == redirect.redirectUrl) {
+ RedirLib.debug('Found a link for %1'._(redirect.redirectUrl));
+ this.goto(redirect);
+ return;
+ }
+ }
+
+ RedirLib.debug('Did not find a link for %1'._(redirect.redirectUrl));
+
+ } else {
+ this.goto(redirect);
+ }
}
}
- } catch(e) {alert(e);}
},
+ goto : function(redirect) {
+
+ if (redirect.redirectUrl == window.content.location.href) {
+ RedirLib.msgBox(this.strings.getString('extensionName'), this.strings.getFormattedString('recursiveError', [redirect.pattern, redirect.redirectUrl]));
+ } else {
+ window.content.location.href = redirect.redirectUrl;
+ }
+ },
+
onUnload : function(event) {
//Clean up here
RedirLib.debug("Finished cleanup");
@@ -82,6 +116,8 @@ var Redirector = {
if (params.out.pattern) {
this.redirects.push(params.out);
}
+
+ RedirLib.setCharPref('redirects', this.redirects.toSource());
},
onMenuItemCommand: function(event) {