keyboard shortcuts working

This commit is contained in:
Kendall Werts
2020-02-27 16:55:11 -06:00
parent 8ef5cbd81b
commit 707cec56c5
6 changed files with 109 additions and 11 deletions
+3 -2
View File
@@ -6,14 +6,15 @@ const backgroundLogic = {
"about:home",
"about:blank"
]),
NUMBER_OF_KEYBOARD_SHORTCUTS: 2,
NUMBER_OF_KEYBOARD_SHORTCUTS: 10,
unhideQueue: [],
init() {
browser.commands.onCommand.addListener(function (command) {
for (let i=0; i < this.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
for (let i=0; i < backgroundLogic.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
const key = "open_container_" + i;
const cookieStoreId = identityState.keyboardShortcut[key];
if (command === key) {
if (cookieStoreId === "none") return;
browser.tabs.create({cookieStoreId});
}
}
+11 -1
View File
@@ -49,11 +49,21 @@ window.identityState = {
},
async loadKeyboardShortcuts () {
const identities = await browser.contextualIdentities.query({});
for (let i=0; i < backgroundLogic.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
const key = "open_container_" + i;
const storageObject = await this.area.get(key);
identityState.keyboardShortcut[key] = storageObject[key];
if (storageObject[key]){
identityState.keyboardShortcut[key] = storageObject[key];
continue;
}
if (identities[i]) {
identityState.keyboardShortcut[key] = identities[i].cookieStoreId;
continue;
}
identityState.keyboardShortcut[key] = "none";
}
return identityState.keyboardShortcut;
},
/*
+1 -3
View File
@@ -12,8 +12,7 @@ const messageHandler = {
switch (m.method) {
case "getShortcuts":
console.log("getShortcuts", identityState.keyboardShortcut);
response = identityState.keyboardShortcut;
response = identityState.storageArea.loadKeyboardShortcuts();
break;
case "setShortcut":
identityState.storageArea.setKeyboardShortcut(m.shortcut, m.cookieStoreId);
@@ -105,7 +104,6 @@ const messageHandler = {
});
break;
}
console.log(m.method, "response", response);
return response;
});
+4 -3
View File
@@ -1,4 +1,4 @@
const NUMBER_OF_KEYBOARD_SHORTCUTS = 2;
const NUMBER_OF_KEYBOARD_SHORTCUTS = 10;
async function requestPermissions() {
const checkbox = document.querySelector("#bookmarksPermissions");
@@ -40,11 +40,11 @@ async function setupOptions() {
async function setupContainerShortcutSelects () {
const keyboardShortcut = await browser.runtime.sendMessage({method: "getShortcuts"});
// console.log(keyboardShortcut);
const identities = await browser.contextualIdentities.query({});
const fragment = document.createDocumentFragment();
const noneOption = document.createElement("option");
noneOption.value = "none";
noneOption.id = "none";
noneOption.textContent = "None";
fragment.append(noneOption);
@@ -61,7 +61,8 @@ async function setupContainerShortcutSelects () {
const shortcutSelect = document.getElementById(shortcutKey);
shortcutSelect.appendChild(fragment.cloneNode(true));
if (keyboardShortcut && keyboardShortcut[shortcutKey]) {
shortcutSelect.getElementById(keyboardShortcut[shortcutKey]).selected = true;
const cookieStoreId = keyboardShortcut[shortcutKey];
shortcutSelect.querySelector("#" + cookieStoreId).selected = true;
}
}
}