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

51 lines
1.4 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 isVivaldi = !isSafari && navigator.userAgent.indexOf(' Vivaldi/') !== -1;
2020-09-15 17:04:32 +02:00
if (!isSafari && !isVivaldi) {
2018-05-09 20:13:20 +02:00
return;
}
if (isSafari && (window as any).__bitwardenFrameId == null) {
(window as any).__bitwardenFrameId = Math.floor(Math.random() * Math.floor(99999999));
}
2018-05-09 20:13:20 +02:00
Mousetrap.prototype.stopCallback = () => {
return false;
};
2020-06-12 18:50:56 +02:00
let autofillCommand = ['mod+shift+l'];
if (isSafari) {
autofillCommand = ['mod+\\', 'mod+8', 'mod+shift+p'];
2020-06-12 18:50:56 +02:00
}
2018-05-09 20:13:20 +02:00
Mousetrap.bind(autofillCommand, () => {
sendMessage('autofill_login');
});
if (isSafari) {
Mousetrap.bind('mod+shift+y', () => {
sendMessage('open_popup');
});
Mousetrap.bind('mod+shift+s', () => {
sendMessage('lock_vault');
});
2020-09-15 16:50:45 +02:00
} else {
2018-05-09 20:13:20 +02:00
Mousetrap.bind('mod+shift+9', () => {
sendMessage('generate_password');
});
}
function sendMessage(shortcut: string) {
const msg: any = {
2018-05-09 20:13:20 +02:00
command: 'keyboardShortcutTriggered',
shortcut: shortcut,
};
2020-12-11 16:13:50 +01:00
chrome.runtime.sendMessage(msg);
2018-05-09 20:13:20 +02:00
}
});