aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--help.html1
-rw-r--r--js/background.js53
-rw-r--r--js/redirect.js5
3 files changed, 31 insertions, 28 deletions
diff --git a/help.html b/help.html
index 835e76b..a9cb717 100644
--- a/help.html
+++ b/help.html
@@ -48,6 +48,7 @@
load <span class="url">http://def.com</span> instead. This can be useful for instance to always redirect articles to printer friendly
versions, redirect http:// to https:// for sites that support both, bypass advertising pages that appear before
being able to view certain pages and more.</p>
+ <p>A new feature in v3.0 is that the result of a redirect will never be redirected again, even if it matches another include pattern. This is to prevent endless loops, for example if you have a pattern that redirects from a -> b and another that redirects from b -> a. This also removes the annoying message that the include pattern matches the result and therefore you can't create the redirect. That doesn't matter anymore because the result will never be redirected, even if it matches the include pattern again, so this should make it simpler for people to create redirects.</p>
<a name="basicusage"></a>
<h4>Basic usage</h4>
diff --git a/js/background.js b/js/background.js
index f57bbdf..c86a4e2 100644
--- a/js/background.js
+++ b/js/background.js
@@ -19,6 +19,13 @@ var tabIdToIcon = {
};
+//Cache of urls that have just been redirected to. They will not be redirected again, to
+//stop recursive redirects, and endless redirect chains.
+//Key is url, value is timestamp of redirect.
+var ignoreNextRequest = {
+
+};
+
function log(msg) {
if (log.enabled) {
console.log('REDIRECTOR: ' + msg);
@@ -48,8 +55,6 @@ function setIcon(image19, image38, tabId) {
//This is the actual function that gets called for each request and must
//decide whether or not we want to redirect.
function checkRedirects(details) {
-
- log('Checking: ' + details.type + ': ' + details.url);
//We only allow GET request to be redirected, don't want to accidentally redirect
//sensitive POST parameters
@@ -57,10 +62,19 @@ function checkRedirects(details) {
return null;
}
+ log('Checking: ' + details.type + ': ' + details.url);
+
var list = partitionedRedirects[details.type];
if (!list) {
log('No list for type: ' + details.type);
- return;
+ return null;
+ }
+
+ var timestamp = ignoreNextRequest[details.url];
+ if (timestamp) {
+ log('Ignoring ' + details.url + ', was just redirected ' + (new Date().getTime()-timestamp) + 'ms ago');
+ delete ignoreNextRequest[details.url];
+ return null;
}
for (var i = 0; i < list.length; i++) {
@@ -69,26 +83,19 @@ function checkRedirects(details) {
if (result.isMatch) {
- //Have to check if the result also matches, which would cause a loop...
- //Based on tests in chrome it actually looks like we don't get passed the redirect url back into our listener so
- //this should be unneccessary. But lets verify on Firefox and Opera first, before removing this code (and the recursive warning in the
- //edit box)
- var recursiveResult = r.getMatch(result.redirectTo);
- if (recursiveResult.isMatch) {
- log('Ignoring pattern ' + r.includePattern + ' for url ' + details.url + ', because it would also match the result: ' + result.redirectTo);
- } else {
- log('Redirecting ' + details.url + ' ===> ' + result.redirectTo + ', type: ' + details.type + ', pattern: ' + r.includePattern);
-
- /* Unfortunately the setBrowserIcon for a specific tab function is way too unreliable, fails all the time with tab not found,
- even though the tab is there. So, for now I'm cancelling this feature, which would have been pretty great ... :/
- if (details.type == 'main_frame') {
- log('Setting icon on tab ' + details.tabId + ' to green');
-
- setIcon("images/icon19redirected.png", "images/icon38redirected.png", details.tabId);
- tabIdToIcon[details.tabId] = true;
- }*/
- return { redirectUrl: result.redirectTo };
- }
+ log('Redirecting ' + details.url + ' ===> ' + result.redirectTo + ', type: ' + details.type + ', pattern: ' + r.includePattern);
+
+ /* Unfortunately the setBrowserIcon for a specific tab function is way too unreliable, fails all the time with tab not found,
+ even though the tab is there. So, for now I'm cancelling this feature, which would have been pretty great ... :/
+ if (details.type == 'main_frame') {
+ log('Setting icon on tab ' + details.tabId + ' to green');
+
+ setIcon("images/icon19redirected.png", "images/icon38redirected.png", details.tabId);
+ tabIdToIcon[details.tabId] = true;
+ }*/
+ ignoreNextRequest[result.redirectTo] = new Date().getTime();
+
+ return { redirectUrl: result.redirectTo };
}
}
diff --git a/js/redirect.js b/js/redirect.js
index 7433027..f0b429d 100644
--- a/js/redirect.js
+++ b/js/redirect.js
@@ -155,11 +155,6 @@ Redirect.prototype = {
}
this.exampleResult = match.redirectTo;
-
- if (this.getMatch(this.exampleResult, true).isMatch) {
- this.exampleResult = '';
- this.error = 'Result matches the redirect again, causing endless loop.'
- }
},
isRegex: function() {