bitwarden-estensione-browser/src/content/shortcuts.ts

45 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-05-09 20:13:20 +02:00
import * as Mousetrap from 'mousetrap';
document.addEventListener('DOMContentLoaded', (event) => {
const isSafari = (typeof safari !== 'undefined') && navigator.userAgent.indexOf(' Safari/') !== -1 &&
navigator.userAgent.indexOf('Chrome') === -1;
const isEdge = !isSafari && navigator.userAgent.indexOf(' Edge/') !== -1;
const isVivaldi = !isSafari && navigator.userAgent.indexOf(' Vivaldi/') !== -1;
if (!isSafari && !isEdge && !isVivaldi) {
return;
}
Mousetrap.prototype.stopCallback = () => {
return false;
};
const autofillCommand = isSafari || isEdge ? 'mod+\\' : 'mod+shift+l';
Mousetrap.bind(autofillCommand, () => {
sendMessage('autofill_login');
});
if (isSafari) {
Mousetrap.bind('mod+shift+y', () => {
sendMessage('open_popup');
});
2018-09-27 14:27:33 +02:00
} else if (!isEdge) {
2018-05-09 20:13:20 +02:00
Mousetrap.bind('mod+shift+9', () => {
sendMessage('generate_password');
});
}
function sendMessage(shortcut: string) {
const msg = {
command: 'keyboardShortcutTriggered',
shortcut: shortcut,
};
if (isSafari) {
safari.self.tab.dispatchMessage('bitwarden', msg);
} else {
chrome.runtime.sendMessage(msg);
}
}
});