diff --git a/VERSIONS.md b/VERSIONS.md index 9fd3f23..0ebe393 100644 --- a/VERSIONS.md +++ b/VERSIONS.md @@ -1,3 +1,6 @@ +### Version 1.0.6 (26 Aug 2016) +* Fixed loophole where blocking a page could be cancelled using Escape (issue 10) + ### Version 1.0.5 (07 Aug 2016) * Minor code improvements (per AMO reviewer recommendation). diff --git a/chrome/content/browser.js b/chrome/content/browser.js index ec8e287..80fb12d 100644 --- a/chrome/content/browser.js +++ b/chrome/content/browser.js @@ -425,6 +425,24 @@ LeechBlock.checkWindow = function (parsedURL, win, isRepeat) { win.location.replace(blockURL); } + // Prevent bypassing the block by pressing Escape to cancel the redirect to blockURL (issue #10) + + // Remove old listener first + LeechBlock.preventEscapeListener && gBrowser.removeEventListener("keydown", LeechBlock.preventEscapeListener); + + gBrowser.addEventListener("keydown", + LeechBlock.preventEscapeListener = // Assign for use with removeEventListener + evt => { // Using an arrow function so the variable doc is available to it (thanks to autobinding) + if (evt.key === 'Escape' && + gBrowser.getBrowserForTab(gBrowser.selectedTab).contentDocument === doc) { // Is this still the tab we're trying to redirect to the block page? + evt.preventDefault(); // Yes? Then block the default action of Escape, which is to cancel navigation + } else { + gBrowser.removeEventListener("keydown", LeechBlock.preventEscapeListener); //No? Then remove the eventListener + LeechBlock.preventEscapeListener = undefined; + } + } + ); + return; // nothing more to do } diff --git a/install.rdf b/install.rdf index cb6c6f2..40a39d8 100644 --- a/install.rdf +++ b/install.rdf @@ -4,7 +4,7 @@ xmlns:em="http://www.mozilla.org/2004/em-rdf#"> {a95d8332-e4b4-6e7f-98ac-20b733364387} - 1.0.5 + 1.0.6 2 true LeechBlock