aboutsummaryrefslogtreecommitdiff
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/code/browserOverlay.xul.js5
-rw-r--r--chrome/code/editRedirect.xul.js2
-rw-r--r--chrome/code/redirector.js59
-rw-r--r--chrome/code/redirectorprefs.js4
-rw-r--r--chrome/code/settings.xul.js4
-rw-r--r--chrome/ui/settings.xul1
6 files changed, 41 insertions, 34 deletions
diff --git a/chrome/code/browserOverlay.xul.js b/chrome/code/browserOverlay.xul.js
index 0d2f46e..d4df3b9 100644
--- a/chrome/code/browserOverlay.xul.js
+++ b/chrome/code/browserOverlay.xul.js
@@ -17,6 +17,11 @@ var RedirectorOverlay = {
this.prefs = new RedirectorPrefs();
this.changedPrefs(this.prefs);
this.prefs.addListener(this);
+ document.addEventListener('keypress', function(event) {
+ if ((event.charCode == 114) && event.altKey) { //alt+r
+ RedirectorOverlay.toggleEnabled();
+ }
+ }, true);
} catch(e) {
if (this.strings) {
alert(this.strings.getString("initError") + "\n\n" + e);
diff --git a/chrome/code/editRedirect.xul.js b/chrome/code/editRedirect.xul.js
index 0c8f34b..87f6533 100644
--- a/chrome/code/editRedirect.xul.js
+++ b/chrome/code/editRedirect.xul.js
@@ -1,4 +1,4 @@
-//// $Id$
+Components.utils.import("chrome://redirector/content/code/redirect.js");
var EditRedirect = {
txtExampleUrl : null,
diff --git a/chrome/code/redirector.js b/chrome/code/redirector.js
index df2a25b..19b0f0c 100644
--- a/chrome/code/redirector.js
+++ b/chrome/code/redirector.js
@@ -12,7 +12,7 @@ Components.utils.import("chrome://redirector/content/code/redirect.js");
Components.utils.import("chrome://redirector/content/code/redirectorprefs.js");
function rdump(msg) {
- dump(msg + '\n');
+ //dump(msg + '\n');
}
Redirector = {
@@ -36,12 +36,7 @@ Redirector = {
},
addRedirect : function(redirect) {
- //This runaround is necessary because the redirect
- //that was created somewhere up in the GUI doesn't
- //have the Redirect function in scope.
- var rx = new Redirect();
- rx.copyValues(redirect);
- this._list.push(rx);
+ this._list.push(redirect);
this.save();
},
@@ -65,7 +60,7 @@ Redirector = {
fileStream.init(file, PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, 0644, 0);
var stream = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
stream.init(fileStream, "UTF-8", 16384, Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
- var rjson = { globalExcludePattern : '', createdBy : 'Redirector v' + this._prefs.version, redirects :[]};
+ var rjson = { createdBy : 'Redirector v' + this._prefs.version, createdAt : new Date(), redirects :[]};
for each (var re in this._list) {
rjson.redirects.push(re.toObject());
}
@@ -124,30 +119,40 @@ Redirector = {
handleUpgrades : function(){
var currentVersion = '2.6';
+ this._list = [];
+ if (this._prefs.version == currentVersion) {
+ return;
+ }
//Here update checks are handled
- if (this._prefs.version != currentVersion) {
- var data = this._prefs.redirects;
- var arr;
- this._list = [];
- if (data != '') {
- for each (redirectString in data.split(':::')) {
- if (!redirectString || !redirectString.split) {
- continue;
- rdump('Invalid old redirect: ' + redirectString);
- }
- var parts = redirectString.split(',,,');
- if (parts.length < 5) {
- throw Error("Invalid serialized redirect, too few fields: " + redirectString);
- }
- var redirect = new Redirect();
- redirect._init.apply(parts);
- this._list.push(redirect);
+
+ try {
+ var branch = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefService).getBranch("extensions.redirector.");
+ var data = branch.getCharPref("redirects");
+ } catch(e) {
+ this._prefs.version = currentVersion;
+ return;
+ }
+ var arr;
+ this._list = [];
+ if (data != '') {
+ for each (redirectString in data.split(':::')) {
+ if (!redirectString || !redirectString.split) {
+ continue;
+ rdump('Invalid old redirect: ' + redirectString);
+ }
+ var parts = redirectString.split(',,,');
+ if (parts.length < 5) {
+ throw Error("Invalid serialized redirect, too few fields: " + redirectString);
}
- this.save();
- this._list = []; //Let the real loading start this properly
+ var redirect = new Redirect();
+ redirect._init.apply(redirect, parts);
+ this._list.push(redirect);
}
+ this.save();
+ this._list = []; //Let the real loading start this properly
}
+ branch.deleteBranch('redirects');
this._prefs.version = currentVersion;
},
diff --git a/chrome/code/redirectorprefs.js b/chrome/code/redirectorprefs.js
index 101a3f0..3920539 100644
--- a/chrome/code/redirectorprefs.js
+++ b/chrome/code/redirectorprefs.js
@@ -39,9 +39,6 @@ RedirectorPrefs.prototype = {
get defaultDir() { return this._defaultDir; },
set defaultDir(value) { this._prefBranch.setCharPref('defaultDir', value); },
- get redirects() { return this._redirects; },
- set redirects(value) { this._prefBranch.setCharPref('redirects', value); },
-
init : function() {
this._prefBranch = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("extensions.redirector.");
this.reload();
@@ -61,7 +58,6 @@ RedirectorPrefs.prototype = {
this._showContextMenu = this._prefBranch.getBoolPref('showContextMenu');
this._debugEnabled = this._prefBranch.getBoolPref('debugEnabled');
this._defaultDir = this._prefBranch.getCharPref('defaultDir');
- this._redirects = this._prefBranch.getCharPref('redirects');
},
get service() {
diff --git a/chrome/code/settings.xul.js b/chrome/code/settings.xul.js
index c7f780a..bee7817 100644
--- a/chrome/code/settings.xul.js
+++ b/chrome/code/settings.xul.js
@@ -217,12 +217,12 @@ var Settings = {
//Mostly borrowed from Adblock Plus
var picker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
picker.init(window, this.strings.getString(captionKey), mode);
- picker.defaultExtension = ".rdx";
+ picker.defaultExtension = ".rjson";
var dir = this.prefs.defaultDir;
if (dir) {
picker.displayDirectory = new nsLocalFile(dir);
}
- picker.appendFilter(this.strings.getString('redirectorFiles'), '*.rdx');
+ picker.appendFilter(this.strings.getString('redirectorFiles'), '*.rjson');
if (picker.show() == picker.returnCancel) {
return null;
diff --git a/chrome/ui/settings.xul b/chrome/ui/settings.xul
index ccb9569..14d9de5 100644
--- a/chrome/ui/settings.xul
+++ b/chrome/ui/settings.xul
@@ -63,6 +63,7 @@
<button id="btnDelete" oncommand="Settings.deleteRedirect();" accesskey="&btnDelete.accesskey;" label="&btnDelete.label;" tooltiptext="&btnDelete.tooltip;" disabled="true" />
<button id="btnUp" oncommand="Settings.moveUp();" tooltiptext="&btnUp.tooltip;" disabled="true" />
<button id="btnDown" oncommand="Settings.moveDown();" tooltiptext="&btnDown.tooltip;" disabled="true" />
+ <button id="btnClose" oncommand="close();" tooltiptext="&btnClose.tooltip;" label="&btnClose.label;" accesskey="&btnClose.accesskey;" />
</hbox>
</vbox>
</tabpanel>