切换 (hide/show) 我的 chrome 扩展程序的键盘快捷方式
Keyboard shortcut to Toggle (hide/show) my chrome extension
我正在开发扩展程序,我希望我的 chrome 扩展程序通过 say (mac: "CMD+SHIFT+9" 或默认值: "Ctrl+Shift+9");
虽然我在清单文件中定义了命令:
{
.........
"commands": {
"toggle-window": {
"suggested_key": {
"default": "Ctrl+Shift+9",
"mac": "Command+Shift+9"
},
"description": "Toggle feature foo",
"global": true
},
........
}
现在,我 backgroundScript.js 可以做什么?
我的 backgroundScript.js 是:
chrome.commands.onCommand.addListener(function(command) {
if(command === "toggle-window") {
console.log('Command:', command);
/* Logic to show/hide will go here..*/
}
});
我该怎么做?谢谢!
实施了此 "show/hide" 功能的示例扩展演示:
https://chrome.google.com/webstore/detail/meldium-browser-extension/fdocegmnehjgfhfjelhmaobjccoiklle
经过长时间的研究,我终于解决了它..首先,感谢@CViejo,他给了我一个问题的提示:
"Just use "_execute_browser_action" instead of "toggle-window" in your manifest file, chrome will handle this functionality for you.
我像这样更新了我的 manifest.js 文件,正如@CViejo 所说:
{
.........
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Shift+9",
"mac": "Command+Shift+9"
}
}
........
}
然后,我重新加载了我的扩展程序,但它仍然没有用.. 然后我只是在扩展程序页面的底部找到 键盘快捷键 框,我在网上阅读了它, 它基本上可以帮助我们 "to verify that suggested keys are actually set there on Keyboard shortcuts box that are defined in manifest file"。我检查了 键盘快捷键 框,但未设置密钥,即使该密钥可用并在清单中定义也是如此。
然后从堆栈溢出中,我发现了这个(这是一个重大错误):
As you can see in the source code here:
https://code.google.com/p/chromium/codesearch#chromium/src/chrome/browser/extensions/api/commands/command_service.cc&l=303&sq=package:chromium&rcl=1409677023
The key binding update is only run when OnExtensionWillBeInstalled
callback is triggered.
So you need to uninstall and reinstall your local extension to see the
default keyboard command appear in :
chrome://extensions/configureCommands
我刚刚卸载并重新安装了我的解压扩展,并检查了默认键盘命令是否出现在 chrome://extensions/configureCommands
它开始在我的扩展中工作...
非常感谢@CViejo 和@Stephane Brillant...
希望这也能帮助到其他人......
我正在开发扩展程序,我希望我的 chrome 扩展程序通过 say (mac: "CMD+SHIFT+9" 或默认值: "Ctrl+Shift+9"); 虽然我在清单文件中定义了命令:
{
.........
"commands": {
"toggle-window": {
"suggested_key": {
"default": "Ctrl+Shift+9",
"mac": "Command+Shift+9"
},
"description": "Toggle feature foo",
"global": true
},
........
}
现在,我 backgroundScript.js 可以做什么?
我的 backgroundScript.js 是:
chrome.commands.onCommand.addListener(function(command) {
if(command === "toggle-window") {
console.log('Command:', command);
/* Logic to show/hide will go here..*/
}
});
我该怎么做?谢谢!
实施了此 "show/hide" 功能的示例扩展演示:
https://chrome.google.com/webstore/detail/meldium-browser-extension/fdocegmnehjgfhfjelhmaobjccoiklle
经过长时间的研究,我终于解决了它..首先,感谢@CViejo,他给了我一个问题的提示:
"Just use "_execute_browser_action" instead of "toggle-window" in your manifest file, chrome will handle this functionality for you.
我像这样更新了我的 manifest.js 文件,正如@CViejo 所说:
{
.........
"commands": {
"_execute_browser_action": {
"suggested_key": {
"default": "Ctrl+Shift+9",
"mac": "Command+Shift+9"
}
}
........
}
然后,我重新加载了我的扩展程序,但它仍然没有用.. 然后我只是在扩展程序页面的底部找到 键盘快捷键 框,我在网上阅读了它, 它基本上可以帮助我们 "to verify that suggested keys are actually set there on Keyboard shortcuts box that are defined in manifest file"。我检查了 键盘快捷键 框,但未设置密钥,即使该密钥可用并在清单中定义也是如此。
然后从堆栈溢出中,我发现了这个(这是一个重大错误):
As you can see in the source code here: https://code.google.com/p/chromium/codesearch#chromium/src/chrome/browser/extensions/api/commands/command_service.cc&l=303&sq=package:chromium&rcl=1409677023
The key binding update is only run when OnExtensionWillBeInstalled callback is triggered.
So you need to uninstall and reinstall your local extension to see the default keyboard command appear in : chrome://extensions/configureCommands
我刚刚卸载并重新安装了我的解压扩展,并检查了默认键盘命令是否出现在 chrome://extensions/configureCommands
它开始在我的扩展中工作...
非常感谢@CViejo 和@Stephane Brillant...
希望这也能帮助到其他人......