1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-03 01:29:39 +02:00

Double-tap ctrl key to toggle god mode in popup panel

After many feedback:
- https://github.com/gorhill/uBlock/commit/aec2f81884c5#commitcomment-39385794

This is convenient enough and this still fulfill
the idea of not being able to create mindlessly
allow_ rules.
This commit is contained in:
Raymond Hill 2020-05-23 19:48:28 -04:00
parent a018937792
commit 196746386c
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -1112,23 +1112,31 @@ const toggleHostnameSwitch = async function(ev) {
/*******************************************************************************
Ctrl-Space bar: toggle god mode
Double tap ctrl key: toggle god mode
*/
const keyboardHandler = function(ev) {
let consumed = false;
if ( ev.ctrlKey && ev.key === ' ' ) {
document.body.classList.toggle('godMode');
consumed = true;
}
if ( consumed ) {
ev.stopPropagation();
ev.preventDefault();
}
};
{
let eventCount = 0;
let eventTime = 0;
document.addEventListener('keydown', ev => {
if ( ev.key !== 'Control' ) {
eventCount = 0;
return;
}
const now = Date.now();
if ( (now - eventTime) >= 500 ) {
eventCount = 0;
}
eventCount += 1;
eventTime = now;
if ( eventCount < 2 ) { return; }
eventCount = 0;
document.body.classList.toggle('godMode');
});
}
document.addEventListener('keydown', keyboardHandler);
/******************************************************************************/