diff options
| author | Einar Egilsson <einar@einaregilsson.com> | 2007-05-21 23:21:52 +0000 | 
|---|---|---|
| committer | Einar Egilsson <einar@einaregilsson.com> | 2007-05-21 23:21:52 +0000 | 
| commit | a7da44a01a575246c9fb55665c15ce9a9a400814 (patch) | |
| tree | af6695987b18e529a2f76eac2268f5b1cc8541d8 /chrome/content | |
| parent | 502c24f18cdfa0f808d9383313bb4f965c7fb11f (diff) | |
Redirector
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@54 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome/content')
| -rw-r--r-- | chrome/content/redirector.js | 46 | ||||
| -rw-r--r-- | chrome/content/redirlib.js | 4 | 
2 files changed, 45 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) { diff --git a/chrome/content/redirlib.js b/chrome/content/redirlib.js index 493c583..71856dd 100644 --- a/chrome/content/redirlib.js +++ b/chrome/content/redirlib.js @@ -66,6 +66,10 @@ var RedirLib = {          return this._prefBranch.getCharPref(branch);
      },
 +    setCharPref : function(branch, value) {
 +        return this._prefBranch.setCharPref(branch, value);
 +    },
 +
      getBoolPref : function(branch) {
          return this._prefBranch.getBoolPref(branch);
      },
 | 
