From abc92ba06bb84d544a0d1deb065eb608cac8190e Mon Sep 17 00:00:00 2001 From: Einar Egilsson Date: Mon, 7 Jan 2008 22:44:06 +0000 Subject: Redirector 1.5 git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@102 119bf307-c92d-0410-89bd-8f53e6181181 --- chrome/content/help.html | 76 ++++++++++++++++++++++++++++++++++++--- chrome/content/overlay.js | 77 ++++++++++++++++++++++++++++------------ chrome/content/overlay.xul | 4 ++- chrome/content/redirectList.js | 8 ++--- chrome/content/redirectList.xul | 4 +-- chrome/content/redirector.js | 8 +++-- chrome/content/redirector.tws | Bin 0 -> 783 bytes 7 files changed, 140 insertions(+), 37 deletions(-) create mode 100644 chrome/content/redirector.tws (limited to 'chrome') diff --git a/chrome/content/help.html b/chrome/content/help.html index a9f5245..b4846aa 100644 --- a/chrome/content/help.html +++ b/chrome/content/help.html @@ -9,7 +9,7 @@

Redirector Help

Table of contents

-
    +
+
  • Examples +
      +
    1. Static redirect
    2. +
    3. Redirect using query string parameter and wildcards
    4. +
    5. Redirect using query string parameter and regular expressions
    6. +
    7. Redirect to a different folder using wildcards
    8. +
    9. Redirect http to https using wildcards
    10. +
    + +
  • + @@ -114,7 +123,64 @@

    Examples

    - -

    To be continued in next version...

    + +
      +
    1. + Static redirect
      + Redirects from http://example.com/foo to http://example.com/bar +

      + Include pattern: http://example.com/foo
      + Exclude pattern:
      + Redirect to: http://example.com/bar
      + Pattern type: Wildcard
      +

      + +
    2. +
    3. + Redirect using query string parameter and wildcards
      + Redirects from http://example.com/index.php?id=12345&a=b to http://example.com/printerfriendly.php?id=12345&a=b + where 12345 could be any number. +

      + Include pattern: http://example.com/index.php?id=*&a=b
      + Exclude pattern:
      + Redirect to: http://example.com/printerfriendly.com?id=$1&a=b
      + Pattern type: Wildcard
      +

      +
    4. +
    5. + Redirect using query string parameter and regular expressions
      + Redirects from http://example.com/index.php?id=12345&a=b to http://example.com/printerfriendly.php?id=12345&a=b + where 12345 could be any number. +

      + Include pattern: http://example.com/index.php\?id=(\d+)&a=b
      + Exclude pattern:
      + Redirect to: http://example.com/printerfriendly.com?id=$1&a=b
      + Pattern type: Regular Expression
      +

      +
    6. +
    7. + Redirect to a different folder using wildcards
      + Redirects from http://example.com/category/fish/index.php to http://example.com/category/cats/index.php + where fish could be any word. The exclude pattern makes sure that there is only one + folder there, so for instance http://example.com/category/fish/cat/mouse/index.php would not match. +

      + Include pattern: http://example.com/category/*/index.php
      + Exclude pattern: http://example.com/category/*/*/index.php
      + Redirect to: http://example.com/category/cats/index.php
      + Pattern type: Wildcard
      +

      +
    8. +
    9. + Redirect http to https using wildcards
      + Redirects from http://mail.google.com/randomcharacters to https://mail.google.com/randomcharacters + where randomcharacters could be anything. +

      + Include pattern: http://mail.google.com*
      + Exclude pattern:
      + Redirect to: https://mail.google.com$1
      + Pattern type: Wildcard
      +

      +
    10. +
    \ No newline at end of file diff --git a/chrome/content/overlay.js b/chrome/content/overlay.js index dd6f527..f1d2241 100644 --- a/chrome/content/overlay.js +++ b/chrome/content/overlay.js @@ -16,7 +16,9 @@ var RedirectorOverlay = { RedirLib.debug("Initializing..."); $('contentAreaContextMenu') .addEventListener("popupshowing", function(e) { RedirectorOverlay.showContextMenu(e); }, false); - + + this.ffversion = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULAppInfo).version; + if (!RedirLib.getBoolPref('showContextMenu')) { $('redirector-context').hidden = true; } @@ -44,12 +46,15 @@ var RedirectorOverlay = { } } }, + + isVersion3 : function() { + return this.ffversion.toString().charAt(0) == '3'; + }, overrideOnStateChange : function() { var origOnStateChange = nsBrowserStatusHandler.prototype.onStateChange; nsBrowserStatusHandler.prototype.onStateChange = function(aWebProgress, aRequest, aStateFlags, aStatus) { - if(aStateFlags & Ci.nsIWebProgressListener.STATE_START && aStateFlags| Ci.nsIWebProgressListener.STATE_IS_NETWORK && aStateFlags| Ci.nsIWebProgressListener.STATE_IS_REQUEST @@ -96,32 +101,61 @@ var RedirectorOverlay = { }, overrideOpenNewWindowWith: function() { - + window.__openNewWindowWith = window.openNewWindowWith; - window.openNewWindowWith = function (href, sourceURL, postData, allowThirdPartyFixup) { - var redirectUrl = Redirector.getRedirectUrlForInstantRedirect(href); - if (redirectUrl.url) { - __openNewWindowWith(redirectUrl.url, href, postData, allowThirdPartyFixup); - } else { - __openNewWindowWith(href, sourceURL, postData, allowThirdPartyFixup); - } - }; + + if (this.isVersion3()) { + + window.openNewWindowWith = function (aUrl, aDocument, aPostData, aAllowThirdPartyFixup, aReferrer) { + var redirectUrl = Redirector.getRedirectUrlForInstantRedirect(aUrl); + if (redirectUrl.url) { + __openNewWindowWith(redirectUrl.url, aDocument, aPostData, aAllowThirdPartyFixup, aUrl); + } else { + __openNewWindowWith(aUrl, aDocument, aPostData, aAllowThirdPartyFixup, aReferrer); + } + }; + + } else { //version 2.* + + window.openNewWindowWith = function (href, sourceURL, postData, allowThirdPartyFixup) { + var redirectUrl = Redirector.getRedirectUrlForInstantRedirect(href); + if (redirectUrl.url) { + __openNewWindowWith(redirectUrl.url, href, postData, allowThirdPartyFixup); + } else { + __openNewWindowWith(href, sourceURL, postData, allowThirdPartyFixup); + } + }; + } }, overrideOpenNewTabWith: function() { window.__openNewTabWith = window.openNewTabWith; - window.openNewTabWith = function (href, sourceURL, postData, event, allowThirdPartyFixup) { - var redirectUrl = Redirector.getRedirectUrlForInstantRedirect(href); - if (redirectUrl.url) { - __openNewTabWith(redirectUrl.url, href, postData, event, allowThirdPartyFixup); - } else { - __openNewTabWith(href, sourceURL, postData, event, allowThirdPartyFixup); - } + if (this.isVersion3()) { + window.openNewTabWith = function (aUrl, aDocument, aPostData, aEvent, aAllowThirdPartyFixup, aReferrer) { + var redirectUrl = Redirector.getRedirectUrlForInstantRedirect(aUrl); + if (redirectUrl.url) { + __openNewTabWith(redirectUrl.url, aDocument, aPostData, aEvent, aAllowThirdPartyFixup, aUrl); + } else { + __openNewTabWith(aUrl, aDocument, aPostData, aEvent, aAllowThirdPartyFixup, aReferrer); + } + + }; - }; + } else { //version 2.* + window.openNewTabWith = function (href, sourceURL, postData, event, allowThirdPartyFixup) { + var redirectUrl = Redirector.getRedirectUrlForInstantRedirect(href); + if (redirectUrl.url) { + __openNewTabWith(redirectUrl.url, href, postData, event, allowThirdPartyFixup); + } else { + __openNewTabWith(href, sourceURL, postData, event, allowThirdPartyFixup); + } + + }; + + } }, @@ -182,12 +216,11 @@ var RedirectorOverlay = { statusBarClick : function(event) { var LEFT = 0, RIGHT = 2; - alert($('redirector-status-popup').style.right); if (event.button == LEFT) { RedirectorOverlay.toggleEnabled(); } else if (event.button == RIGHT) { - $('redirector-status-popup').left = $('redirector-status').left; - $('redirector-status-popup').showPopup(); + Redirector.openSettings(); + //$('redirector-status-popup').showPopup(); } }, diff --git a/chrome/content/overlay.xul b/chrome/content/overlay.xul index 3333be1..5bd827f 100644 --- a/chrome/content/overlay.xul +++ b/chrome/content/overlay.xul @@ -26,10 +26,12 @@ - + 0) { - list.selectedIndex = 0; - } - list.clearSelection(); + }, onLoad : function() { @@ -32,12 +30,12 @@ var RedirectList = { Redirector.init(); this.lstRedirects = $('lstRedirects'); + this.lstRedirects.selType = 'single'; //For fx3 this.template = document.getElementsByTagName('richlistitem')[0]; this.lstRedirects.removeChild(this.template); this.btnDelete = $('btnDelete'); this.btnEdit = $('btnEdit'); this.addItemsToListBox(Redirector.list); - this.lstRedirects.selectedIndex = -1; } catch(e) { alert(e); } diff --git a/chrome/content/redirectList.xul b/chrome/content/redirectList.xul index ed0a130..e3638b0 100644 --- a/chrome/content/redirectList.xul +++ b/chrome/content/redirectList.xul @@ -16,8 +16,8 @@