mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-05 18:32:30 +01:00
code review for https://github.com/uBlockOrigin/uBlock-issues/issues/106
This commit is contained in:
parent
473872105c
commit
c57c760b1e
@ -1,7 +1,7 @@
|
||||
/*******************************************************************************
|
||||
|
||||
uBlock Origin - a browser extension to block requests.
|
||||
Copyright (C) 2017 Raymond Hill
|
||||
Copyright (C) 2017-present Raymond Hill
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -25,8 +25,15 @@
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
µBlock.canUseShortcuts = vAPI.commands instanceof Object;
|
||||
|
||||
µBlock.canUpdateShortcuts = µBlock.canUseShortcuts &&
|
||||
typeof vAPI.commands.update === 'function';
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
(function() {
|
||||
if ( vAPI.commands === undefined ) { return; }
|
||||
if ( µBlock.canUseShortcuts === false ) { return; }
|
||||
|
||||
vAPI.commands.onCommand.addListener(function(command) {
|
||||
var µb = µBlock;
|
||||
|
@ -917,28 +917,28 @@ var modifyRuleset = function(details) {
|
||||
// Shortcuts pane
|
||||
|
||||
let getShortcuts = function(callback) {
|
||||
if ( vAPI.commands !== undefined ) {
|
||||
vAPI.commands.getAll(commands => {
|
||||
let response = [];
|
||||
for ( let command of commands ) {
|
||||
let desc = command.description;
|
||||
let match = /^__MSG_(.+?)__$/.exec(desc);
|
||||
if ( match !== null ) {
|
||||
desc = vAPI.i18n(match[1]);
|
||||
}
|
||||
if ( desc === '' ) { continue; }
|
||||
command.description = desc;
|
||||
response.push(command);
|
||||
}
|
||||
callback(response);
|
||||
});
|
||||
} else {
|
||||
callback([]);
|
||||
if ( µb.canUseShortcuts === false ) {
|
||||
return callback([]);
|
||||
}
|
||||
|
||||
vAPI.commands.getAll(commands => {
|
||||
let response = [];
|
||||
for ( let command of commands ) {
|
||||
let desc = command.description;
|
||||
let match = /^__MSG_(.+?)__$/.exec(desc);
|
||||
if ( match !== null ) {
|
||||
desc = vAPI.i18n(match[1]);
|
||||
}
|
||||
if ( desc === '' ) { continue; }
|
||||
command.description = desc;
|
||||
response.push(command);
|
||||
}
|
||||
callback(response);
|
||||
});
|
||||
};
|
||||
|
||||
let setShortcut = function(details) {
|
||||
if ( typeof vAPI.commands.update !== 'function' ) { return; }
|
||||
if ( µb.canUpdateShortcuts === false ) { return; }
|
||||
if ( details.shortcut === undefined ) {
|
||||
vAPI.commands.reset(details.name);
|
||||
µb.commandShortcuts.delete(details.name);
|
||||
@ -981,7 +981,7 @@ var onMessage = function(request, sender, callback) {
|
||||
|
||||
switch ( request.what ) {
|
||||
case 'canUpdateShortcuts':
|
||||
response = typeof vAPI.commands.update === 'function';
|
||||
response = µb.canUpdateShortcuts;
|
||||
break;
|
||||
|
||||
case 'getRules':
|
||||
|
@ -1,7 +1,7 @@
|
||||
/*******************************************************************************
|
||||
|
||||
uBlock Origin - a browser extension to block requests.
|
||||
Copyright (C) 2014-2018 Raymond Hill
|
||||
Copyright (C) 2014-present Raymond Hill
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -106,12 +106,7 @@ var onPSLReady = function() {
|
||||
var onCommandShortcutsReady = function(commandShortcuts) {
|
||||
if ( Array.isArray(commandShortcuts) === false ) { return; }
|
||||
µb.commandShortcuts = new Map(commandShortcuts);
|
||||
if (
|
||||
vAPI.commands === undefined ||
|
||||
typeof vAPI.commands.update !== 'function'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if ( µb.canUpdateShortcuts === false ) { return; }
|
||||
for ( let entry of commandShortcuts ) {
|
||||
vAPI.commands.update({ name: entry[0], shortcut: entry[1] });
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user