mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-18 17:02:27 +02: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.
|
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
|
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
|
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() {
|
(function() {
|
||||||
if ( vAPI.commands === undefined ) { return; }
|
if ( µBlock.canUseShortcuts === false ) { return; }
|
||||||
|
|
||||||
vAPI.commands.onCommand.addListener(function(command) {
|
vAPI.commands.onCommand.addListener(function(command) {
|
||||||
var µb = µBlock;
|
var µb = µBlock;
|
||||||
|
@ -917,28 +917,28 @@ var modifyRuleset = function(details) {
|
|||||||
// Shortcuts pane
|
// Shortcuts pane
|
||||||
|
|
||||||
let getShortcuts = function(callback) {
|
let getShortcuts = function(callback) {
|
||||||
if ( vAPI.commands !== undefined ) {
|
if ( µb.canUseShortcuts === false ) {
|
||||||
vAPI.commands.getAll(commands => {
|
return callback([]);
|
||||||
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([]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
let setShortcut = function(details) {
|
||||||
if ( typeof vAPI.commands.update !== 'function' ) { return; }
|
if ( µb.canUpdateShortcuts === false ) { return; }
|
||||||
if ( details.shortcut === undefined ) {
|
if ( details.shortcut === undefined ) {
|
||||||
vAPI.commands.reset(details.name);
|
vAPI.commands.reset(details.name);
|
||||||
µb.commandShortcuts.delete(details.name);
|
µb.commandShortcuts.delete(details.name);
|
||||||
@ -981,7 +981,7 @@ var onMessage = function(request, sender, callback) {
|
|||||||
|
|
||||||
switch ( request.what ) {
|
switch ( request.what ) {
|
||||||
case 'canUpdateShortcuts':
|
case 'canUpdateShortcuts':
|
||||||
response = typeof vAPI.commands.update === 'function';
|
response = µb.canUpdateShortcuts;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'getRules':
|
case 'getRules':
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
|
|
||||||
uBlock Origin - a browser extension to block requests.
|
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
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -106,12 +106,7 @@ var onPSLReady = function() {
|
|||||||
var onCommandShortcutsReady = function(commandShortcuts) {
|
var onCommandShortcutsReady = function(commandShortcuts) {
|
||||||
if ( Array.isArray(commandShortcuts) === false ) { return; }
|
if ( Array.isArray(commandShortcuts) === false ) { return; }
|
||||||
µb.commandShortcuts = new Map(commandShortcuts);
|
µb.commandShortcuts = new Map(commandShortcuts);
|
||||||
if (
|
if ( µb.canUpdateShortcuts === false ) { return; }
|
||||||
vAPI.commands === undefined ||
|
|
||||||
typeof vAPI.commands.update !== 'function'
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for ( let entry of commandShortcuts ) {
|
for ( let entry of commandShortcuts ) {
|
||||||
vAPI.commands.update({ name: entry[0], shortcut: entry[1] });
|
vAPI.commands.update({ name: entry[0], shortcut: entry[1] });
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user