diff options
author | Einar Egilsson | 2007-06-02 00:24:35 +0000 |
---|---|---|
committer | Einar Egilsson | 2007-06-02 00:24:35 +0000 |
commit | b0c6f7a2bff3d57f1c8d05a561dbd0bbca0228ca (patch) | |
tree | b9d11f284141f8aacd80e917bcd05877c3aee6e1 /chrome/content/redirector.js | |
parent | f77a93fe56b90c89d3a881d9af84d43e451efe8d (diff) |
Redirector: All main functionality except Regex working.
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@57 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome/content/redirector.js')
-rw-r--r-- | chrome/content/redirector.js | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/chrome/content/redirector.js b/chrome/content/redirector.js index 63ee85d..8ec4af7 100644 --- a/chrome/content/redirector.js +++ b/chrome/content/redirector.js @@ -5,6 +5,8 @@ var Redirector = { list : [], + enabled : true, + init : function() { this.load(); this.prefObserver.register(); @@ -43,42 +45,67 @@ var Redirector = { this.save(); }, + deleteAt : function(index) { + this.list.splice(index, 1); + this.save(); + }, + processUrl : function(url) { - var redirect, link, links; + var redirect, link, links, redirectUrl, match; + + if (!this.enabled) { + return; + } + for each (redirect in this.list) { - if (redirect.patternType == kRedirectorWildcard && this.wildcardMatch(redirect.pattern, url)) { + var redirectUrl; + + if (redirect.patternType == kRedirectorWildcard) { + match = this.wildcardMatch(redirect.pattern, url); + redirectUrl = redirect.redirectUrl; + } else if (redirect.patternType == kRedirectorRegex) { + match = this.regexMatch(redirect.pattern, url); + redirectUrl = redirect.redirectUrl; + } + + if (match) { 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); + if (link.href && link.href.toString() == redirectUrl) { + RedirLib.debug('Found a link for %1'._(redirectUrl)); + this._goto(redirectUrl, redirect.pattern); return; } } - RedirLib.debug('Did not find a link for %1'._(redirect.redirectUrl)); + RedirLib.debug('Did not find a link for %1'._(redirectUrl)); } else { - this._goto(redirect); + this._goto(redirectUrl, redirect.pattern); } } } }, - _goto : function(redirect) { + _goto : function(redirectUrl, pattern) { - if (redirect.redirectUrl == window.content.location.href) { - RedirLib.msgBox(this.strings.getString('extensionName'), this.strings.getFormattedString('recursiveError', [redirect.pattern, redirect.redirectUrl])); + if (redirectUrl == window.content.location.href) { + RedirLib.msgBox(this.strings.getString('extensionName'), this.strings.getFormattedString('recursiveError', [pattern, redirectUrl])); } else { - window.content.location.href = redirect.redirectUrl; + window.content.location.href = redirectUrl; } }, + regexMatch : function(pattern, text) { + alert('regexmatch'); + + }, + wildcardMatch : function(pattern, text) { var parts , part @@ -127,10 +154,16 @@ var Redirector = { }, observe : function(subject, topic, data) { - if (topic == 'nsPref:changed' && data == 'extensions.redirector.redirects') { + if (topic != 'nsPref:changed') { + return; + } + + if (data == 'extensions.redirector.redirects') { Redirector.load(); + } else if (data == 'extensions.redirector.enabled') { + Redirector.enabled = RedirLib.getBoolPref('enabled'); } } }, -};
\ No newline at end of file +}; |