diff options
Diffstat (limited to 'chrome/js')
-rw-r--r-- | chrome/js/redirect.js | 20 | ||||
-rw-r--r-- | chrome/js/redirector-ui.js | 2 | ||||
-rw-r--r-- | chrome/js/redirector.js | 2 |
3 files changed, 18 insertions, 6 deletions
diff --git a/chrome/js/redirect.js b/chrome/js/redirect.js index 8b0b1d2..4a05ef8 100644 --- a/chrome/js/redirect.js +++ b/chrome/js/redirect.js @@ -2,8 +2,8 @@ var EXPORTED_SYMBOLS = ['Redirect']; -function Redirect(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, disabled) { - this._init(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, disabled); +function Redirect(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, escapeMatches, disabled) { + this._init(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, escapeMatches, disabled); } //Static @@ -36,6 +36,7 @@ Redirect.prototype = { }, unescapeMatches : false, + escapeMatches : false, disabled : false, @@ -57,6 +58,7 @@ Redirect.prototype = { redirectUrl : this.redirectUrl, patternType : this.patternType, unescapeMatches : this.unescapeMatches, + escapeMatches : this.escapeMatches, disabled : !!this.disabled }; }, @@ -75,6 +77,7 @@ Redirect.prototype = { this.redirectUrl = other.redirectUrl; this.patternType = other.patternType; this.unescapeMatches = other.unescapeMatches; + this.escapeMatches = other.escapeMatches; this.disabled = other.disabled; }, @@ -85,6 +88,7 @@ Redirect.prototype = { && this.redirectUrl == redirect.redirectUrl && this.patternType == redirect.patternType && this.unescapeMatches == redirect.unescapeMatches + && this.escapeMatches == redirect.escapeMatches ; }, @@ -164,13 +168,14 @@ Redirect.prototype = { return new RegExp(this._preparePattern(pattern),"gi"); }, - _init : function(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, disabled) { + _init : function(exampleUrl, includePattern, redirectUrl, patternType, excludePattern, unescapeMatches, escapeMatches, disabled) { this.exampleUrl = exampleUrl || ''; this.includePattern = includePattern || ''; this.excludePattern = excludePattern || ''; this.redirectUrl = redirectUrl || ''; this.patternType = patternType || Redirect.WILDCARD; this.unescapeMatches = (unescapeMatches === 'true' || unescapeMatches === true); + this.escapeMatches = (escapeMatches === 'true' || escapeMatches === true); this.disabled = (disabled === 'true' || disabled === true); }, @@ -182,6 +187,7 @@ Redirect.prototype = { + '\n\tRedirect url : ' + this.redirectUrl + '\n\tPattern type : ' + this.patternType + '\n\tUnescape matches : ' + this.unescapeMatches + + '\n\tEscape matches : ' + this.escapeMatches + '\n\tDisabled : ' + this.disabled + '\n}\n'; }, @@ -196,7 +202,11 @@ Redirect.prototype = { } var resultUrl = this.redirectUrl; for (var i = 1; i < matches.length; i++) { - resultUrl = resultUrl.replace(new RegExp('\\$' + i, 'gi'), this.unescapeMatches ? unescape(matches[i]) : matches[i]); + resultUrl = resultUrl.replace(new RegExp('\\$' + i, 'gi'), + this.unescapeMatches ? unescape(matches[i]) : + this.escapeMatches ? encodeURIComponent(matches[i]) : + matches[i] + ); } this._rxInclude.lastIndex = 0; return resultUrl; @@ -210,4 +220,4 @@ Redirect.prototype = { this._rxExclude.lastIndex = 0; return shouldExclude; } -};
\ No newline at end of file +}; diff --git a/chrome/js/redirector-ui.js b/chrome/js/redirector-ui.js index 8deb20d..bd709cc 100644 --- a/chrome/js/redirector-ui.js +++ b/chrome/js/redirector-ui.js @@ -148,6 +148,7 @@ function bindRedirect(redirect) { $('#redirect-to').val(redirect.redirectUrl); $('#redirect-enabled').attr('checked', !redirect.disabled); $('#unescape-matches').attr('checked', redirect.unescapeMatches); + $('#escape-matches').attr('checked', redirect.escapeMatches); $('#regex-pattern').attr('checked', redirect.patternType == Redirect.REGEX); $('#wildcard-pattern').attr('checked', redirect.patternType == Redirect.WILDCARD); } @@ -180,6 +181,7 @@ function controlsToRedirect(redirect) { redirect.redirectUrl = $('#redirect-to').val(); redirect.disabled = !$('#redirect-enabled').attr('checked'); redirect.unescapeMatches = $('#unescape-matches').attr('checked'); + redirect.escapeMatches = $('#escape-matches').attr('checked'); return true; } diff --git a/chrome/js/redirector.js b/chrome/js/redirector.js index d2bcc51..5f4fa2a 100644 --- a/chrome/js/redirector.js +++ b/chrome/js/redirector.js @@ -345,4 +345,4 @@ Redirector = { } }; -Redirector.init();
\ No newline at end of file +Redirector.init(); |