Skip to content
This repository was archived by the owner on Apr 9, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### Version 1.0.6 (26 Aug 2016)
* Fixed loophole where blocking a page could be cancelled using <kbd>Escape</kbd> (issue 10)

### Version 1.0.5 (07 Aug 2016)
* Minor code improvements (per AMO reviewer recommendation).

Expand Down
18 changes: 18 additions & 0 deletions chrome/content/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion install.rdf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
<Description about="urn:mozilla:install-manifest">
<em:id>{a95d8332-e4b4-6e7f-98ac-20b733364387}</em:id>
<em:version>1.0.5</em:version>
<em:version>1.0.6</em:version>
<em:type>2</em:type>
<em:unpack>true</em:unpack>
<em:name>LeechBlock</em:name>
Expand Down