在Chrome中覆盖书签快捷键(Ctrl + D)功能 [英] Override the bookmark shortcut (Ctrl+D) function in Chrome
问题描述
是否可以覆盖 Ctrl + D ?我想,例如 console.log
或其他东西,而不是将这些链接添加到书签中。
使用和 Dev 频道,以及金丝雀建立 更多信息 。它可能适用于所有从Chrome 24开始的用户。
如果您想在Chrome 23或更低版本中测试API,请将实验权限添加到清单文件中,并使用 chrome.experimental.commands
而不是 chrome.commands
。同时访问 chrome:// flags /
并启用Experimental Extension APIs,或者使用 - 启用实验扩展程序apis
标志。
manifest.json
{
name:重映射快捷方式,
版本:1,
manifest_version:2,
background:{
scripts:[background.js]
},
权限:[
标签
] ,
commands:{
test-shortcut:{
suggested_key:{
default:Ctrl + D,
mac :Command + D,
linux:Ctrl + D
},
description:无论你想要什么
}
}
}
background.js
// Chrome 24+。在Chrome中使用chrome.experimental.commands 23-
chrome.commands.onCommand.addListener(function(command){
if(command ==='test-shortcut'){
//做任何你想做的事情,例如在标签中的console.log:
chrome.tabs.query({active:true},function(tabs){
var tabId = tabs [0] .id;
var code ='console.log(Intercepted Ctrl + D!);';
chrome.tabs.executeScript(tabId,{code:code});
});
}
});
文档
-
chrome.commands
-
chrome.tabs
(方法query
和executeScript
)
Is it possible to override the Ctrl+D? I want to, for example console.log
or something, and not add the links to the bookmarks.
Shortcuts can be overridden using the chrome.commands
API. An extension can suggest a default shortcut (eg. Ctrl+D) in the manifest file, but users are free to override this at chrome://extensions/
, as seen below:
Usage
This API is still under development and only available at the Beta and Dev channels, and the Canary builds More info. It will probably available to everyone starting at Chrome 24.
If you want to test the API in Chrome 23 or lower, add the "experimental" permission to the manifest file, and use chrome.experimental.commands
instead of chrome.commands
. Also visit chrome://flags/
and enable "Experimental Extension APIs", or start Chrome with the --enable-experimental-extension-apis
flag.
manifest.json
{
"name": "Remap shortcut",
"version": "1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"permissions": [
"tabs"
],
"commands": {
"test-shortcut": {
"suggested_key": {
"default": "Ctrl+D",
"mac": "Command+D",
"linux": "Ctrl+D"
},
"description": "Whatever you want"
}
}
}
background.js
// Chrome 24+. Use chrome.experimental.commands in Chrome 23-
chrome.commands.onCommand.addListener(function(command) {
if (command === 'test-shortcut') {
// Do whatever you want, for instance console.log in the tab:
chrome.tabs.query({active:true}, function(tabs) {
var tabId = tabs[0].id;
var code = 'console.log("Intercepted Ctrl+D!");';
chrome.tabs.executeScript(tabId, {code: code});
});
}
});
Documentation
chrome.commands
chrome.tabs
(methodsquery
andexecuteScript
)
这篇关于在Chrome中覆盖书签快捷键(Ctrl + D)功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!