aboutsummaryrefslogtreecommitdiff
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/content/code/browserOverlay.xul.js (renamed from chrome/content/overlay.js)29
-rw-r--r--chrome/content/code/editRedirect.xul.js (renamed from chrome/content/redirect.js)8
-rw-r--r--chrome/content/code/redirectList.xul.js (renamed from chrome/content/redirectList.js)45
-rw-r--r--chrome/content/code/redirector.prototype.js (renamed from chrome/content/redirector.prototype.js)67
-rw-r--r--chrome/content/images/redirector.png (renamed from chrome/content/redirector.png)bin1462 -> 1462 bytes
-rw-r--r--chrome/content/images/statusactive.PNG (renamed from chrome/content/statusactive.PNG)bin360 -> 360 bytes
-rw-r--r--chrome/content/images/statusinactive.PNG (renamed from chrome/content/statusinactive.PNG)bin396 -> 396 bytes
-rw-r--r--chrome/content/ui/browserOverlay.xul (renamed from chrome/content/overlay.xul)6
-rw-r--r--chrome/content/ui/editRedirect.xul (renamed from chrome/content/redirect.xul)10
-rw-r--r--chrome/content/ui/help.html (renamed from chrome/content/help.html)0
-rw-r--r--chrome/content/ui/redirectList.xul (renamed from chrome/content/redirectList.xul)8
-rw-r--r--chrome/content/unittest/run.html (renamed from chrome/content/unittests.html)5
-rw-r--r--chrome/content/unittest/testcases.js (renamed from chrome/content/unittests.js)0
-rw-r--r--chrome/locale/en-US/browserOverlay.xul.dtd (renamed from chrome/locale/en-US/redirector.dtd)0
-rw-r--r--chrome/locale/en-US/editRedirect.xul.dtd (renamed from chrome/locale/en-US/redirect.dtd)0
-rw-r--r--chrome/locale/en-US/redirectList.xul.dtd (renamed from chrome/locale/en-US/redirectList.dtd)0
-rw-r--r--chrome/locale/en-US/redirector.properties5
17 files changed, 139 insertions, 44 deletions
diff --git a/chrome/content/overlay.js b/chrome/content/code/browserOverlay.xul.js
index 760f828..636c02b 100644
--- a/chrome/content/overlay.js
+++ b/chrome/content/code/browserOverlay.xul.js
@@ -2,10 +2,6 @@
var Redirector = Components.classes["@einaregilsson.com/redirector;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
-function $(id) {
- return document.getElementById(id);
-}
-
var RedirectorOverlay = {
id : "redirector@einaregilsson.com",
@@ -18,14 +14,14 @@ var RedirectorOverlay = {
// initialization code
Redirector.debug("Initializing...");
- $('contentAreaContextMenu')
+ document.getElementById('contentAreaContextMenu')
.addEventListener("popupshowing", function(e) { RedirectorOverlay.showContextMenu(e); }, false);
if (!Redirector.getBoolPref('showContextMenu')) {
- $('redirector-context').hidden = true;
+ document.getElementById('redirector-context').hidden = true;
}
if (!Redirector.getBoolPref('showStatusBarIcon')) {
- $('redirector-status').hidden = true;
+ document.getElementById('redirector-status').hidden = true;
}
this.strings = document.getElementById("redirector-strings");
this.prefObserver.register();
@@ -50,9 +46,9 @@ var RedirectorOverlay = {
showContextMenu : function(event) {
if (gContextMenu.onLink) {
- $("redirector-context").label = this.strings.getString('addLinkUrl');
+ document.getElementById("redirector-context").label = this.strings.getString('addLinkUrl');
} else {
- $("redirector-context").label = this.strings.getString('addCurrentUrl');
+ document.getElementById("redirector-context").label = this.strings.getString('addCurrentUrl');
}
},
@@ -63,7 +59,7 @@ var RedirectorOverlay = {
item.redirectUrl = gContextMenu.link.toString();
}
- window.openDialog("chrome://redirector/content/redirect.xul",
+ window.openDialog("chrome://redirector/content/ui/editRedirect.xul",
"redirect",
"chrome,dialog,modal,centerscreen", item);
@@ -82,12 +78,12 @@ var RedirectorOverlay = {
openSettings : function() {
var windowName = "redirectorSettings";
- var windowsMediator = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
+ var windowsMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
var win = windowsMediator.getMostRecentWindow(windowName);
if (win) {
win.focus();
} else {
- window.openDialog("chrome://redirector/content/redirectList.xul",
+ window.openDialog("chrome://redirector/content/ui/redirectList.xul",
windowName,
"chrome,dialog,resizable=no,centerscreen", this);
}
@@ -101,18 +97,17 @@ var RedirectorOverlay = {
RedirectorOverlay.toggleEnabled();
} else if (event.button == RIGHT) {
this.openSettings();
- //$('redirector-status-popup').showPopup();
}
},
setStatusBarImg : function() {
- var statusImg = $('redirector-statusbar-img');
+ var statusImg = document.getElementById('redirector-statusbar-img');
if (Redirector.enabled) {
- statusImg.src = 'chrome://redirector/content/statusactive.PNG'
+ statusImg.src = 'chrome://redirector/content/images/statusactive.PNG'
statusImg.setAttribute('tooltiptext', this.strings.getString('enabledTooltip'));
} else {
- statusImg.src = 'chrome://redirector/content/statusinactive.PNG'
+ statusImg.src = 'chrome://redirector/content/images/statusinactive.PNG'
statusImg.setAttribute('tooltiptext', this.strings.getString('disabledTooltip'));
}
},
@@ -120,7 +115,7 @@ var RedirectorOverlay = {
prefObserver : {
getService : function() {
- return Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranchInternal);
+ return Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranchInternal);
},
register: function() {
diff --git a/chrome/content/redirect.js b/chrome/content/code/editRedirect.xul.js
index f51e7f2..6e981d2 100644
--- a/chrome/content/redirect.js
+++ b/chrome/content/code/editRedirect.xul.js
@@ -8,7 +8,7 @@ function $(id) {
return document.getElementById(id);
}
-var Redirect = {
+var EditRedirect = {
onLoad : function() {
var item = window.arguments[0];
@@ -17,7 +17,7 @@ var Redirect = {
$('txtPattern').value = item.pattern;
$('txtRedirectUrl').value = item.redirectUrl || '';
$('txtExcludePattern').value = item.excludePattern || '';
- $('chkUnescapeMatches').setAttribute('selected', !!item.unescapeMatches);
+ $('chkUnescapeMatches').setAttribute('checked', !!item.unescapeMatches);
$('txtPattern').focus();
this.strings = document.getElementById("redirector-strings");
@@ -37,10 +37,10 @@ var Redirect = {
} else {
item.patternType = kRedirectorWildcard;
}
- item.exampleUrl =$('txtExampleUrl').value;
+ item.exampleUrl = $('txtExampleUrl').value;
item.redirectUrl = $('txtRedirectUrl').value;
item.excludePattern = $('txtExcludePattern').value;
- item.unescapeMatches = $('chkUnescapeMatches').selected;
+ item.unescapeMatches = $('chkUnescapeMatches').hasAttribute('checked') && $('chkUnescapeMatches').getAttribute('checked');
item.saved = true;
return true;
diff --git a/chrome/content/redirectList.js b/chrome/content/code/redirectList.xul.js
index b3a3200..65957b4 100644
--- a/chrome/content/redirectList.js
+++ b/chrome/content/code/redirectList.xul.js
@@ -60,7 +60,7 @@ var RedirectList = {
return;
}
}
- window.openDialog("chrome://redirector/content/help.html", windowName, "chrome,dialog,resizable=yes,location=0,toolbar=0,status=0,width=800px,height=600px,centerscreen", this);
+ window.openDialog("chrome://redirector/content/ui/help.html", windowName, "chrome,dialog,resizable=yes,location=0,toolbar=0,status=0,width=800px,height=600px,centerscreen", this);
},
close : function() {
@@ -100,9 +100,9 @@ var RedirectList = {
addRedirect : function() {
- var item = { pattern : '', exampleUrl : '', redirectUrl : '', patternType : 'W'};
+ var item = { pattern : '', exampleUrl : '', redirectUrl : '', patternType : 'W', unescapeMatches : false};
- window.openDialog("chrome://redirector/content/redirect.xul",
+ window.openDialog("chrome://redirector/content/ui/editRedirect.xul",
"redirect",
"chrome,dialog,modal,centerscreen", item);
@@ -123,7 +123,7 @@ var RedirectList = {
var item = listItem.item;
- window.openDialog("chrome://redirector/content/redirect.xul",
+ window.openDialog("chrome://redirector/content/ui/editRedirect.xul",
"redirect",
"chrome,dialog,modal,centerscreen", item);
@@ -153,6 +153,41 @@ var RedirectList = {
$('btnEdit').disabled = (index == -1);
$('btnDelete').disabled = (index == -1);
+ },
+
+ importExport : function(mode, captionKey, func) {
+ //Mostly borrowed from Adblock Plus
+ var picker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
+ picker.init(window, Redirector.getString(captionKey), mode);
+ picker.defaultExtension = ".rdx";
+ var dir = Redirector.getDefaultDir();
+ if (dir) {
+ picker.displayDirectory = dir;
+ }
+ picker.appendFilter(Redirector.getString('redirectorFiles'), '*.rdx');
+
+ if (picker.show() != picker.returnCancel)
+ {
+ try
+ {
+ func(picker.file);
+ }
+ catch (e)
+ {
+ alert(e);
+ }
+ }
+ },
+
+ export : function() {
+ this.importExport(Ci.nsIFilePicker.modeSave, 'exportCaption', function(file) {
+ Redirector.exportRedirects(file);
+ });
+ },
+
+ import : function() {
+ this.importExport(Ci.nsIFilePicker.modeOpen, 'importCaption', function(file) {
+ Redirector.importRedirects(file);
+ });
}
-
};
diff --git a/chrome/content/redirector.prototype.js b/chrome/content/code/redirector.prototype.js
index d064764..24a41ba 100644
--- a/chrome/content/redirector.prototype.js
+++ b/chrome/content/code/redirector.prototype.js
@@ -56,13 +56,21 @@ Redirector.prototype = {
redirectUrl : arr[2],
patternType : arr[3],
excludePattern : arr[4],
- unescapeMatches : !!arr[5] //This might be undefined for those upgrading from 1.7.1 but that's ok
+ unescapeMatches : arr[5] == 'true' //This might be undefined for those upgrading from 1.7.1 but that's ok
});
}
}
},
+ getDefaultDir : function() {
+ return this.prefBranch.getCharPref('defaultDir');
+ },
+
+ setDefaultDir : function(dir) {
+ this.prefBranch.setCharPref('defaultDir', dir.spec);
+ },
+
loadStrings : function() {
var src = 'chrome://redirector/locale/redirector.properties';
var localeService = Cc["@mozilla.org/intl/nslocaleservice;1"].getService(Ci.nsILocaleService);
@@ -122,7 +130,7 @@ Redirector.prototype = {
reload : function() {
Cc["@mozilla.org/moz/jssubscript-loader;1"]
.getService(Ci.mozIJSSubScriptLoader)
- .loadSubScript('chrome://redirector/content/redirector.prototype.js');
+ .loadSubScript('chrome://redirector/content/code/redirector.prototype.js');
for (var key in Redirector.prototype) {
this[key] = Redirector.prototype[key];
@@ -141,13 +149,18 @@ Redirector.prototype = {
},
save : function() {
+ this.prefBranch.setCharPref('redirects', this.redirectsAsStrings().join(':::'));
+ },
+
+ redirectsAsStrings : function() {
var r
, tempList = [];
for each (r in this.list) {
+ this.debug(r.unescapeMatches);
tempList.push([r.exampleUrl, r.pattern, r.redirectUrl, r.patternType, r.excludePattern, r.unescapeMatches].join(',,,'));
}
- this.prefBranch.setCharPref('redirects', tempList.join(':::'));
+ return tempList;
},
getBoolPref : function(name) {
@@ -182,6 +195,54 @@ Redirector.prototype = {
},
+ exportRedirects : function(file) {
+ var fileStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
+ const PR_WRONLY = 0x02;
+ const PR_CREATE_FILE = 0x08;
+ const PR_TRUNCATE = 0x20;
+
+ fileStream.init(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0644, 0);
+ //file.parent.QueryInterface(Ci.nsILocalFile)
+ var stream = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
+ stream.init(fileStream, "UTF-8", 16384, Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
+ stream.writeString(this.redirectsAsStrings().join('\n'));
+ stream.close();
+ },
+
+ importRedirects : function(file) {
+ var fileStream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
+ fileStream.init(file, 0x01, 0444, 0); //TODO: Find the actual constants for these magic numbers
+
+ var stream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(Ci.nsIConverterInputStream);
+ stream.init(fileStream, "UTF-8", 16384, Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
+ stream = stream.QueryInterface(Ci.nsIUnicharLineInputStream);
+
+ var importCount = 0, existsCount = 0;
+ var lines = [];
+ var line = {value: null};
+ while (stream.readLine(line)) {
+ var parts = line.replace('\n', '').split(',,,');
+ if (parts.length < 6) {
+ var redirect = {
+ exampleUrl : parts[0],
+ pattern : parts[1],
+ redirectUrl : parts[2],
+ patternType : parts[3],
+ excludePattern : parts[4],
+ unescapeMatches : parts[5] == 'true' ? true : false
+ };
+
+
+ }
+ }
+ stream.close();
+ this.save();
+ },
+
+ getString : function(name) {
+ return this.strings.GetStringFromName(name);
+ },
+
msgBox : function(title, text) {
Cc["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Ci.nsIPromptService)
diff --git a/chrome/content/redirector.png b/chrome/content/images/redirector.png
index f8de12c..f8de12c 100644
--- a/chrome/content/redirector.png
+++ b/chrome/content/images/redirector.png
Binary files differ
diff --git a/chrome/content/statusactive.PNG b/chrome/content/images/statusactive.PNG
index 06ce766..06ce766 100644
--- a/chrome/content/statusactive.PNG
+++ b/chrome/content/images/statusactive.PNG
Binary files differ
diff --git a/chrome/content/statusinactive.PNG b/chrome/content/images/statusinactive.PNG
index 8b83562..8b83562 100644
--- a/chrome/content/statusinactive.PNG
+++ b/chrome/content/images/statusinactive.PNG
Binary files differ
diff --git a/chrome/content/overlay.xul b/chrome/content/ui/browserOverlay.xul
index 9c4619e..9a02332 100644
--- a/chrome/content/overlay.xul
+++ b/chrome/content/ui/browserOverlay.xul
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id$ -->
-<!DOCTYPE overlay SYSTEM "chrome://redirector/locale/redirector.dtd">
+<!DOCTYPE overlay SYSTEM "chrome://redirector/locale/browserOverlay.xul.dtd">
<overlay id="redirector-overlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
- <script src="overlay.js"/>
+ <script src="../code/browserOverlay.xul.js"/>
<stringbundleset id="stringbundleset">
<stringbundle id="redirector-strings" src="chrome://redirector/locale/redirector.properties"/>
@@ -28,7 +28,7 @@
<menuitem label="&RedirectorHelp.label;" accesskey="&RedirectorHelp.accesskey;" oncommand="Redirector.openHelp();" />
</menupopup>
-->
- <image id="redirector-statusbar-img" src="chrome://redirector/content/statusactive.PNG"
+ <image id="redirector-statusbar-img" src="chrome://redirector/content/images/statusactive.PNG"
tooltiptext="Redirector is enabled;"
style="width:16px; height:16px;"
onclick="RedirectorOverlay.statusBarClick(event);" />
diff --git a/chrome/content/redirect.xul b/chrome/content/ui/editRedirect.xul
index d3b0907..afca5b6 100644
--- a/chrome/content/redirect.xul
+++ b/chrome/content/ui/editRedirect.xul
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id$ -->
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
-<!DOCTYPE dialog SYSTEM "chrome://redirector/locale/redirect.dtd">
+<!DOCTYPE dialog SYSTEM "chrome://redirector/locale/editRedirect.xul.dtd">
<dialog title="&redirectWindow.title;"
orient="vertical"
autostretch="always"
- onload="Redirect.onLoad();"
+ onload="EditRedirect.onLoad();"
buttons="accept,cancel"
- ondialogaccept="return Redirect.onAccept();"
+ ondialogaccept="return EditRedirect.onAccept();"
xmlns:nc="http://home.netscape.com/NC-rdf#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
- <script type="application/x-javascript" src="redirect.js"/>
+ <script type="application/x-javascript" src="../code/editRedirect.xul.js"/>
<stringbundleset id="stringbundleset">
<stringbundle id="redirector-strings" src="chrome://redirector/locale/redirector.properties"/>
</stringbundleset>
@@ -25,7 +25,7 @@
<row align="center">
<text value="&txtPattern.label;" style="margin-top:6px;"/>
<textbox id="txtPattern" taborder="1"/>
- <button id="btnTestPattern" label="&btnTestPattern.label;" onclick="Redirect.testPattern();" taborder="2"/>
+ <button id="btnTestPattern" label="&btnTestPattern.label;" onclick="EditRedirect.testPattern();" taborder="2"/>
</row>
<row align="center">
<text value="&txtExcludePattern.label;" style="margin-top:6px;"/>
diff --git a/chrome/content/help.html b/chrome/content/ui/help.html
index 0ce6769..0ce6769 100644
--- a/chrome/content/help.html
+++ b/chrome/content/ui/help.html
diff --git a/chrome/content/redirectList.xul b/chrome/content/ui/redirectList.xul
index 77bbf9b..29d5ceb 100644
--- a/chrome/content/redirectList.xul
+++ b/chrome/content/ui/redirectList.xul
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id -->
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
-<!DOCTYPE dialog SYSTEM "chrome://redirector/locale/redirectList.dtd">
+<!DOCTYPE dialog SYSTEM "chrome://redirector/locale/redirectList.xul.dtd">
<window title="&window.title;"
orient="vertical"
onload="RedirectList.onLoad();"
@@ -12,7 +12,7 @@
xmlns:nc="http://home.netscape.com/NC-rdf#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
- <script type="application/x-javascript" src="redirectList.js"/>
+ <script type="application/x-javascript" src="../code/redirectList.xul.js"/>
<vbox>
<richlistbox seltype="single" id="lstRedirects" style="margin-bottom:5px; border:solid 1px grey;" height="330px" ondblclick="RedirectList.editRedirect();" onselect="RedirectList.selectionChange();">
@@ -41,10 +41,10 @@
<button id="btnAdd" onclick="RedirectList.addRedirect();" label="&btnAdd.label;" disabled="false" />
<button id="btnEdit" onclick="RedirectList.editRedirect();" label="&btnEdit.label;" disabled="true" />
<button id="btnDelete" onclick="RedirectList.deleteRedirect();" label="&btnDelete.label;" disabled="true" />
- <button id="btnClose" onclick="RedirectList.close();" label="&btnClose.label;"/>
- <button id="btnHelp" onclick="RedirectList.openHelp();" label="&btnHelp.label;"/>
<button id="btnImport" onclick="RedirectList.import();" label="&btnImport.label;"/>
<button id="btnExport" onclick="RedirectList.export();" label="&btnExport.label;"/>
+ <button id="btnHelp" onclick="RedirectList.openHelp();" label="&btnHelp.label;"/>
+ <button id="btnClose" onclick="RedirectList.close();" label="&btnClose.label;"/>
<!-- TODO: include in v2.0
<button id="btnUp" onclick="RedirectList.moveUp();" label="UP" disabled="false" />
<button id="btnDown" onclick="RedirectList.moveDown();" label="Down" />
diff --git a/chrome/content/unittests.html b/chrome/content/unittest/run.html
index 0989562..2c4f968 100644
--- a/chrome/content/unittests.html
+++ b/chrome/content/unittest/run.html
@@ -5,11 +5,12 @@
<style type="text/css">
body { font-family: Verdana, Arial; color:black; background-color:white; font-size:0.8em; width:800px; margin:auto; text-align:center;}
a { color:blue; }
- h1 { text-align:center; margin:20px 0px; }
+ h1 { text-align:center; margin:10px 0px; }
table { margin:auto; border:solid 1px black; width:700px; border-collapse:collapse;}
td { border:solid 1px black; padding:3px; }
td.result { width:20px; height:20px; padding:0;}
td.result div { width:70%; height:70%; margin:auto; }
+ button { margin:20px auto; }
</style>
<script type="text/javascript">
@@ -50,7 +51,7 @@
tables[i].parentNode.removeChild(tables[i]);
}
- subscriptLoader.loadSubScript('chrome://redirector/content/unittests.js');
+ subscriptLoader.loadSubScript('chrome://redirector/content/unittest/testcases.js');
redirector.reload();
for (var name in tests) {
diff --git a/chrome/content/unittests.js b/chrome/content/unittest/testcases.js
index ea6e26b..ea6e26b 100644
--- a/chrome/content/unittests.js
+++ b/chrome/content/unittest/testcases.js
diff --git a/chrome/locale/en-US/redirector.dtd b/chrome/locale/en-US/browserOverlay.xul.dtd
index 3aaa0fc..3aaa0fc 100644
--- a/chrome/locale/en-US/redirector.dtd
+++ b/chrome/locale/en-US/browserOverlay.xul.dtd
diff --git a/chrome/locale/en-US/redirect.dtd b/chrome/locale/en-US/editRedirect.xul.dtd
index 40098b8..40098b8 100644
--- a/chrome/locale/en-US/redirect.dtd
+++ b/chrome/locale/en-US/editRedirect.xul.dtd
diff --git a/chrome/locale/en-US/redirectList.dtd b/chrome/locale/en-US/redirectList.xul.dtd
index e09b038..e09b038 100644
--- a/chrome/locale/en-US/redirectList.dtd
+++ b/chrome/locale/en-US/redirectList.xul.dtd
diff --git a/chrome/locale/en-US/redirector.properties b/chrome/locale/en-US/redirector.properties
index f884575..0e10390 100644
--- a/chrome/locale/en-US/redirector.properties
+++ b/chrome/locale/en-US/redirector.properties
@@ -11,4 +11,7 @@ testPatternSuccess=The pattern %S matches example URL %S, and would redirect you
testPatternFailure=The pattern %S does not match example URL %S
testPatternExclude=Example URL %S matches the exclude pattern %S and so would not be redirected
regexPatternError=The pattern '%S' is not a legal regular expression pattern. Details: %S
-xpathDeprecated=XPath patterns are no longer supported as of version 1.5.1, please remove those redirects. \ No newline at end of file
+xpathDeprecated=XPath patterns are no longer supported as of version 1.5.1, please remove those redirects.
+redirectorFiles=Redirector files (*.rdx)
+exportCaption=Export redirects...
+importCaption=Import redirects... \ No newline at end of file