1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 12:57:57 +02:00
This commit is contained in:
gorhill 2017-06-22 14:34:18 -04:00
parent 88fcf53d34
commit ca45ade4c5
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -3399,9 +3399,9 @@ vAPI.contextMenu = (function() {
vAPI.commands = (function() {
var commands = [
{ id: 'launch-element-zapper', shortcut: 'alt-z' },
{ id: 'launch-element-picker', shortcut: 'alt-x' },
{ id: 'launch-logger', shortcut: 'alt-l' }
{ id: 'launch-element-zapper' },
{ id: 'launch-element-picker' },
{ id: 'launch-logger' }
];
var clientListener;
@ -3431,19 +3431,25 @@ vAPI.commands = (function() {
myKeyset = doc.createElement('keyset');
myKeyset.setAttribute('id', 'uBlock0Keyset');
var myKey, shortcut, parts, modifier, key;
var myKey, shortcut, parts, modifiers, key;
for ( var command of commands ) {
shortcut = vAPI.localStorage.getItem('shortcuts.' + command.id);
if ( shortcut === null ) { shortcut = command.shortcut; }
parts = /(([a-z]+)-)?(\w)/.exec(shortcut);
if ( shortcut === null ) {
vAPI.localStorage.setItem('shortcuts.' + command.id, '');
}
if ( typeof shortcut !== 'string' ) { continue; }
parts = /^((?:[a-z]+-){1,})?(\w)$/.exec(shortcut);
if ( parts === null ) { continue; }
modifier = parts[2] || '';
key = parts[3] || '';
if ( key === '' ) { continue; }
modifiers = parts[1];
if ( typeof modifiers === 'string' ) {
modifiers = parts[1].slice(0, -1).split('-').join(' ');
}
key = parts[2];
if ( typeof key !== 'string' ) { continue; }
myKey = doc.createElement('key');
myKey.setAttribute('id', 'uBlock0Key-' + command.id);
if ( modifier !== '' ) {
myKey.setAttribute('modifiers', parts[2]);
if ( modifiers !== '' ) {
myKey.setAttribute('modifiers', modifiers);
}
myKey.setAttribute('key', key);
// https://stackoverflow.com/a/16786770