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;
|
|
|
|
}
|
|
|
|
|
2018-09-27 17:07:17 +02:00
|
|
|
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) {
|
2020-08-12 23:08:34 +02:00
|
|
|
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');
|
|
|
|
});
|
2020-11-06 16:51:35 +01:00
|
|
|
|
|
|
|
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) {
|
2018-09-27 17:07:17 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
});
|