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
1 changed files with 17 additions and 11 deletions

View File

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