aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chrome/content/redirect.js22
-rw-r--r--chrome/content/redirect.xul31
-rw-r--r--chrome/content/redirectList.xul2
-rw-r--r--chrome/content/redirector.js51
-rw-r--r--chrome/locale/en-US/redirect.dtd1
-rw-r--r--chrome/locale/en-US/redirector.properties5
-rw-r--r--install.rdf4
7 files changed, 82 insertions, 34 deletions
diff --git a/chrome/content/redirect.js b/chrome/content/redirect.js
index 5be85f7..f4609e3 100644
--- a/chrome/content/redirect.js
+++ b/chrome/content/redirect.js
@@ -10,6 +10,8 @@ var Redirect = {
$('txtRedirectUrl').value = item.redirectUrl || '';
$('chkOnlyIfLinkExists').checked = item.onlyIfLinkExists || false;
+ this.strings = document.getElementById("redirector-strings");
+
if (item.patternType == kRedirectorRegex) {
$('rdoRegex').setAttribute('selected', true);
$('rdoWildcard').setAttribute('selected', false);
@@ -34,9 +36,25 @@ var Redirect = {
},
testPattern : function() {
- var match;
+ var redirectUrl, pattern, example, extName;
+
+ redirectUrl = $('txtRedirectUrl').value;
+ pattern = $('txtPattern').value;
+ example = $('txtExampleUrl').value;
+
+ extName = this.strings.getString('extensionName');
- alert(Redirector.wildcardMatch($('txtPattern').value, $('txtExampleUrl').value));
+ if ($('rdoRegex').selected) {
+ redirectUrl = Redirector.regexMatch(pattern, example, redirectUrl);
+ } else {
+ redirectUrl = Redirector.wildcardMatch(pattern, example, redirectUrl);
+ }
+
+ if (redirectUrl || (redirectUrl === '' && $('txtRedirectUrl').value === '')) {
+ RedirLib.msgBox(extName, this.strings.getFormattedString('testPatternSuccess', [pattern, example, redirectUrl]));
+ } else {
+ RedirLib.msgBox(extName, this.strings.getFormattedString('testPatternFailure', [pattern, example]));
+ }
}
}; \ No newline at end of file
diff --git a/chrome/content/redirect.xul b/chrome/content/redirect.xul
index 8db1891..479729a 100644
--- a/chrome/content/redirect.xul
+++ b/chrome/content/redirect.xul
@@ -13,33 +13,38 @@
<script type="application/x-javascript" src="redirlib.js"/>
<script type="application/x-javascript" src="redirector.js"/>
<script type="application/x-javascript" src="redirect.js"/>
- <style type="text/css">
- textbox { width:500px; }
- </style>
+ <stringbundleset id="stringbundleset">
+ <stringbundle id="redirector-strings" src="chrome://redirector/locale/redirector.properties"/>
+ </stringbundleset>
<grid>
<rows>
<row>
- <text value="&txtExampleUrl.label;"/>
- <textbox id="txtExampleUrl" disabled="true" />
+ <text value="&txtExampleUrl.label;" style="margin-top:6px;"/>
+ <textbox id="txtExampleUrl" disabled="true" style="width:400px;"/>
</row>
<row>
- <text value="&txtPattern.label;"/>
- <textbox id="txtPattern"/>
- <button id="btnTestPattern" label="&btnTestPattern.label;" onclick="Redirect.testPattern();" />
+ <text value="&txtPattern.label;" style="margin-top:6px;"/>
+ <textbox id="txtPattern" taborder="1"/>
+ <button id="btnTestPattern" label="&btnTestPattern.label;" onclick="Redirect.testPattern();" taborder="2"/>
</row>
<row>
- <text value="&txtRedirectUrl.label;"/>
- <textbox id="txtRedirectUrl"/>
+ <text value="&txtRedirectUrl.label;" style="margin-top:6px;"/>
+ <textbox id="txtRedirectUrl" taborder="3"/>
</row>
<row>
- <checkbox id="chkOnlyIfLinkExists" label="&chkOnlyIfLinkExists.label;"/>
+ <text value="&rdoPatternTypes.label;"/>
<radiogroup>
- <radio id="rdoWildcard" label="&rdoWildcard.label;" accesskey="&rdoWildcard.accessKey;" selected="true"/>
- <radio id="rdoRegex" label="&rdoRegex.label;" accesskey="&rdoRegex.accessKey;"/>
+ <radio id="rdoWildcard" label="&rdoWildcard.label;" accesskey="&rdoWildcard.accessKey;" selected="true" taborder="4"/>
+ <radio id="rdoRegex" label="&rdoRegex.label;" accesskey="&rdoRegex.accessKey;" taborder="5"/>
</radiogroup>
</row>
+ <row>
+ <text value="&chkOnlyIfLinkExists.label;" />
+ <checkbox id="chkOnlyIfLinkExists" label="" taborder="6"/>
+ </row>
</rows>
+
</grid>
</dialog>
diff --git a/chrome/content/redirectList.xul b/chrome/content/redirectList.xul
index 688457b..264baa2 100644
--- a/chrome/content/redirectList.xul
+++ b/chrome/content/redirectList.xul
@@ -16,7 +16,7 @@
<script type="application/x-javascript" src="redirectList.js"/>
<vbox>
- <listbox id="lstRedirects" height="300px" ondblclick="RedirectList.editRedirect();" onselect="RedirectList.selectionChange();">
+ <listbox id="lstRedirects" style="margin-bottom:5px;" height="330px" ondblclick="RedirectList.editRedirect();" onselect="RedirectList.selectionChange();">
<listhead>
<listheader label="&colPattern.label;"/>
diff --git a/chrome/content/redirector.js b/chrome/content/redirector.js
index 8ec4af7..18ac1f9 100644
--- a/chrome/content/redirector.js
+++ b/chrome/content/redirector.js
@@ -51,7 +51,7 @@ var Redirector = {
},
processUrl : function(url) {
- var redirect, link, links, redirectUrl, match;
+ var redirect, link, links, redirectUrl;
if (!this.enabled) {
return;
@@ -59,17 +59,14 @@ var Redirector = {
for each (redirect in this.list) {
- var redirectUrl;
if (redirect.patternType == kRedirectorWildcard) {
- match = this.wildcardMatch(redirect.pattern, url);
- redirectUrl = redirect.redirectUrl;
+ redirectUrl = this.wildcardMatch(redirect.pattern, url, redirect.redirectUrl);
} else if (redirect.patternType == kRedirectorRegex) {
- match = this.regexMatch(redirect.pattern, url);
- redirectUrl = redirect.redirectUrl;
+ redirectUrl = this.regexMatch(redirect.pattern, url, redirect.redirectUrl);
}
- if (match) {
+ if (redirectUrl) {
RedirLib.debug('%1 matches %2'._(redirect.pattern, url));
if (redirect.onlyIfLinkExists) {
links = window.content.document.getElementsByTagName('a');
@@ -101,12 +98,38 @@ var Redirector = {
}
},
- regexMatch : function(pattern, text) {
- alert('regexmatch');
+ regexMatch : function(pattern, text, redirectUrl) {
+
+ var strings, rx, match;
+ try {
+ rx = new RegExp(pattern, 'gi');
+ match = rx.exec(text);
+ } catch(e) {
+ //HACK, need to make this better
+ if (window.RedirectorOverlay) {
+ strings = window.RedirectorOverlay.strings;
+ } else if(window.Redirect) {
+ strings = window.Redirect.strings;
+ }
+ RedirLib.msgBox(strings.getString('extensionName'), strings.getFormattedString('regexPatternError', [pattern, e.toString()]));
+ return null;
+ }
+
+ var rxrepl;
+
+ if (match) {
+ for (var i = 1; i < match.length; i++) {
+ rxrepl = new RegExp('\\$' + i, 'gi');
+ redirectUrl = redirectUrl.replace(rxrepl, match[i]);
+ }
+ return redirectUrl;
+ }
+
+ return null;
},
- wildcardMatch : function(pattern, text) {
+ wildcardMatch : function(pattern, text, redirectUrl) {
var parts
, part
, i
@@ -121,22 +144,22 @@ var Redirector = {
pos = text.indexOf(part);
if (pos == -1) {
- return false;
+ return null;
}
if (i == 0 && pos != 0) {
- return false;
+ return null;
}
if (i == parts.length -1 && i != "" && text.substr(text.length - part.length) != part) {
- return false;
+ return null;
}
text = text.substr(pos + part.length);
}
- return true;
+ return redirectUrl;
},
prefObserver : {
diff --git a/chrome/locale/en-US/redirect.dtd b/chrome/locale/en-US/redirect.dtd
index d5ff86c..45a1d30 100644
--- a/chrome/locale/en-US/redirect.dtd
+++ b/chrome/locale/en-US/redirect.dtd
@@ -8,5 +8,6 @@
<!ENTITY rdoWildcard.label "Wildcard">
<!ENTITY rdoWildcard.accessKey "W">
<!ENTITY rdoRegex.label "Regular Expression">
+<!ENTITY rdoPatternTypes.label "Pattern Type">
<!ENTITY rdoRegex.accessKey "R">
diff --git a/chrome/locale/en-US/redirector.properties b/chrome/locale/en-US/redirector.properties
index df70f6b..66a0287 100644
--- a/chrome/locale/en-US/redirector.properties
+++ b/chrome/locale/en-US/redirector.properties
@@ -6,5 +6,6 @@ addLinkUrl=Add link url to Redirector
recursiveError=A redirect with the pattern %S matches %S and is trying to redirect to it again. You should change this rule so it won't work recursively.
enabledTooltip=Redirector is enabled
disabledTooltip=Redirector is disabled
-testPatternSuccess=The pattern %S matches example URL %S, and would redirect you to %S
-testPatternFailure=The pattern %S does not match example URL %S \ No newline at end of file
+testPatternSuccess=The pattern %S matches example URL %S, and would redirect you to url: %S
+testPatternFailure=The pattern %S does not match example URL %S
+regexPatternError=The pattern '%S' is not a legal regular expression pattern. Details: %S \ No newline at end of file
diff --git a/install.rdf b/install.rdf
index 5507f7d..3b3fd7e 100644
--- a/install.rdf
+++ b/install.rdf
@@ -5,10 +5,10 @@
<Description about="urn:mozilla:install-manifest">
<em:id>redirector@einaregilsson.com</em:id>
<em:name>Redirector</em:name>
- <em:version>0.0.1</em:version>
+ <em:version>0.9.1</em:version>
<em:creator>Einar Egilsson</em:creator>
<em:description>Automatically redirects to user-defined urls on certain pages</em:description>
- <!-- <em:homepageURL>http://addons.mozilla.org/{app}/xxx/</em:homepageURL> --> <!-- Add after upload to addons.mozilla.org -->
+ <em:homepageURL>https://addons.mozilla.org/en-US/firefox/addon/5064</em:homepageURL>
<em:optionsURL>chrome://redirector/content/redirectList.xul</em:optionsURL>
<em:iconURL>chrome://redirector/content/redirector.png</em:iconURL>
<em:targetApplication>