From 9b57efe67dd9f16ab30886182b6591b589c29bbf Mon Sep 17 00:00:00 2001
From: Einar Egilsson
Date: Fri, 26 Aug 2011 16:55:21 +0200
Subject: Added close button + alt+r shortcut to toggle enabled
---
chrome.manifest | 1 -
chrome/code/browserOverlay.xul.js | 5 ++
chrome/code/editRedirect.xul.js | 2 +-
chrome/code/redirector.js | 59 ++++++++++++-----------
chrome/code/redirectorprefs.js | 4 --
chrome/code/settings.xul.js | 4 +-
chrome/ui/settings.xul | 1 +
defaults/preferences/redirector.preferences.js | 2 -
locale/en-US/redirector.properties | 2 +-
locale/en-US/settings.xul.dtd | 5 ++
locale/zh-CN/browserOverlay.xul.dtd | 9 ----
locale/zh-CN/editRedirect.xul.dtd | 14 ------
locale/zh-CN/redirector.properties | 33 -------------
locale/zh-CN/settings.xul.dtd | 65 --------------------------
14 files changed, 47 insertions(+), 159 deletions(-)
delete mode 100644 locale/zh-CN/browserOverlay.xul.dtd
delete mode 100644 locale/zh-CN/editRedirect.xul.dtd
delete mode 100644 locale/zh-CN/redirector.properties
delete mode 100644 locale/zh-CN/settings.xul.dtd
diff --git a/chrome.manifest b/chrome.manifest
index 3ca72f2..e758bd7 100644
--- a/chrome.manifest
+++ b/chrome.manifest
@@ -1,7 +1,6 @@
content redirector file:chrome/
locale redirector en-US file:locale/en-US/
-locale redirector zh-CN file:locale/zh-CN/
skin redirector classic/1.0 file:chrome/ui/skin/
overlay chrome://browser/content/browser.xul chrome://redirector/content/ui/browserOverlay.xul
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 @@
+
diff --git a/defaults/preferences/redirector.preferences.js b/defaults/preferences/redirector.preferences.js
index 1bac6b0..da9e642 100644
--- a/defaults/preferences/redirector.preferences.js
+++ b/defaults/preferences/redirector.preferences.js
@@ -1,10 +1,8 @@
-//// $Id$
pref("extensions.redirector.debugEnabled", false);
pref("extensions.redirector.enabled", true);
pref("extensions.redirector.showContextMenu", true);
pref("extensions.redirector.showStatusBarIcon", true);
-pref("extensions.redirector.redirects", '');
pref("extensions.redirector.version", 'undefined');
pref("extensions.redirector.defaultDir", '');
diff --git a/locale/en-US/redirector.properties b/locale/en-US/redirector.properties
index 128d08e..e0a05a5 100644
--- a/locale/en-US/redirector.properties
+++ b/locale/en-US/redirector.properties
@@ -12,7 +12,7 @@ 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.
-redirectorFiles=Redirector files (*.rdx)
+redirectorFiles=Redirector files (*.rjson)
exportCaption=Export redirects...
importCaption=Import redirects...
deleteConfirmationText=Are you sure you want to permanently delete this redirect?
diff --git a/locale/en-US/settings.xul.dtd b/locale/en-US/settings.xul.dtd
index ff55b68..90d3f6f 100644
--- a/locale/en-US/settings.xul.dtd
+++ b/locale/en-US/settings.xul.dtd
@@ -32,6 +32,10 @@
+
+
+
+
@@ -63,3 +67,4 @@
+
diff --git a/locale/zh-CN/browserOverlay.xul.dtd b/locale/zh-CN/browserOverlay.xul.dtd
deleted file mode 100644
index b0567f8..0000000
--- a/locale/zh-CN/browserOverlay.xul.dtd
+++ /dev/null
@@ -1,9 +0,0 @@
-
-
-
-
-
-
-
-
-
diff --git a/locale/zh-CN/editRedirect.xul.dtd b/locale/zh-CN/editRedirect.xul.dtd
deleted file mode 100644
index f0ab422..0000000
--- a/locale/zh-CN/editRedirect.xul.dtd
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/locale/zh-CN/redirector.properties b/locale/zh-CN/redirector.properties
deleted file mode 100644
index 866ec1a..0000000
--- a/locale/zh-CN/redirector.properties
+++ /dev/null
@@ -1,33 +0,0 @@
-# $Id: redirector.properties 288 2009-10-26 08:13:15Z einar@einaregilsson.com $
-initError=Failed to initialize Redirector.
-extensions.redirector@einaregilsson.com.description=根据您设置的规则自动跳转网页。
-extensionName=Redirector
-addCurrentUrl=Add current url to Redirector
-addLinkUrl=为链接创建 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 url: %S
-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.
-redirectorFiles=Redirector files (*.rdx)
-exportCaption=Export redirects...
-importCaption=Import redirects...
-deleteConfirmationText=Are you sure you want to permanently delete this redirect?
-deleteConfirmationTitle=Delete redirect?
-importedMessage=%S redirects were imported
-importedMessageSingular=%S redirect was imported
-existedMessage=%S redirects were identical to existing redirects and were therefore not imported.
-existedMessageSingular=%S redirect was identical to an existing redirect and was therefore not imported.
-allExistedMessage=All %S redirects in the file were identical to existing redirects, no redirects were imported.
-allExistedMessageSingular=The single redirect in the file was identical to an existing redirect and was therefore not imported.
-importedNone=There were no usable redirects in the given file, no redirects were imported.
-importResult=Import results
-invalidRedirectTitle=Redirector Add-on: Invalid Redirect detected
-invalidRedirectText=The pattern "%S" redirected the url %S to %S which also matches the pattern. This will cause an endless loop and so the redirect has been disabled to prevent this from happening. You should edit this redirect to fix it.
-warningExampleUrlDoesntMatchPatternTitle=Warning: Example url does not match redirect
-warningExampleUrlDoesntMatchPattern=The example url does not match the redirect specified. Are you sure you want to save this redirect?
-errorExampleUrlMatchesRecursiveTitle=Error: Recursive match detected
-errorExampleUrlMatchesRecursive=The example url %S matches the redirect and would redirect you to %S, which also matches the redirect. This is not allowed as it can cause an endless loop of requests.
\ No newline at end of file
diff --git a/locale/zh-CN/settings.xul.dtd b/locale/zh-CN/settings.xul.dtd
deleted file mode 100644
index 0facb3a..0000000
--- a/locale/zh-CN/settings.xul.dtd
+++ /dev/null
@@ -1,65 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
--
cgit v1.2.3-70-g09d2