Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override the bookmark shortcut (Ctrl+D) function in Chrome

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.

like image 616
shagon Avatar asked Nov 17 '12 09:11

shagon


2 Answers

Alternative Solution: Type chrome:extensions into your browser's address bar. This will pull up the Chrome Extensions page.

Click on Keyboard Shortcuts in the top left menu ("Menu/Burger Button")

Assign Ctrl-D to a plugin that does not alter your Bookmarks.

This will solve the problem that an bookmark is created directly when you accidentally press Ctrl-D, instead the other Addon will pop up in that case.

like image 117
Jens Kisters Avatar answered Oct 01 '22 01:10

Jens Kisters


It's not necessary to use chrome.commands -- you can use a content script to trap the keydown event, call preventDefault and stopPropagation on it, and handle it however you want. Example snippet that should work as part of a content script:

document.addEventListener('keydown', function(event) {
  if (event.ctrlKey && String.fromCharCode(event.keyCode) === 'D') {
    console.log("you pressed ctrl-D");
    event.preventDefault();
    event.stopPropagation();
  }
}, true);

The only things you can't override this way are window-handling commands, like ctrl-N and ctrl-<tab>.

like image 31
int3 Avatar answered Oct 01 '22 02:10

int3