2018-05-09 20:13:20 +02:00
|
|
|
import * as Mousetrap from "mousetrap";
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2021-02-10 16:40:15 +01:00
|
|
|
document.addEventListener("DOMContentLoaded", (event) => {
|
2018-05-09 20:13:20 +02:00
|
|
|
const isSafari =
|
|
|
|
typeof safari !== "undefined" &&
|
|
|
|
navigator.userAgent.indexOf(" Safari/") !== -1 &&
|
|
|
|
navigator.userAgent.indexOf("Chrome") === -1;
|
|
|
|
const isVivaldi = !isSafari && navigator.userAgent.indexOf(" Vivaldi/") !== -1;
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2020-09-15 17:04:32 +02:00
|
|
|
if (!isSafari && !isVivaldi) {
|
2018-05-09 20:13:20 +02:00
|
|
|
return;
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
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));
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
|
|
|
|
2018-05-09 20:13:20 +02:00
|
|
|
Mousetrap.prototype.stopCallback = () => {
|
|
|
|
return false;
|
2021-12-21 15:43:35 +01:00
|
|
|
};
|
|
|
|
|
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"];
|
2018-05-09 20:13:20 +02:00
|
|
|
}
|
|
|
|
Mousetrap.bind(autofillCommand, () => {
|
|
|
|
sendMessage("autofill_login");
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
|
|
|
|
2018-05-09 20:13:20 +02:00
|
|
|
if (isSafari) {
|
|
|
|
Mousetrap.bind("mod+shift+y", () => {
|
|
|
|
sendMessage("open_popup");
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
2018-05-09 20:13:20 +02:00
|
|
|
|
2018-09-27 17:07:17 +02:00
|
|
|
Mousetrap.bind("mod+shift+s", () => {
|
|
|
|
sendMessage("lock_vault");
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
|
|
|
} else {
|
2018-09-27 17:07:17 +02:00
|
|
|
Mousetrap.bind("mod+shift+9", () => {
|
|
|
|
sendMessage("generate_password");
|
2021-12-21 15:43:35 +01:00
|
|
|
});
|
2018-09-27 17:07:17 +02:00
|
|
|
}
|
|
|
|
|
2018-05-09 20:13:20 +02:00
|
|
|
function sendMessage(shortcut: string) {
|
|
|
|
const msg: any = {
|
|
|
|
command: "keyboardShortcutTriggered",
|
|
|
|
shortcut: shortcut,
|
|
|
|
};
|
|
|
|
|
|
|
|
chrome.runtime.sendMessage(msg);
|
|
|
|
}
|
|
|
|
});
|