keyboard shortcuts working
This commit is contained in:
parent
8ef5cbd81b
commit
707cec56c5
6 changed files with 109 additions and 11 deletions
|
@ -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});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
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;
|
||||
},
|
||||
|
||||
/*
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,54 @@
|
|||
"default": "Ctrl+Shift+2"
|
||||
},
|
||||
"description": "Container Shortcut 2"
|
||||
},
|
||||
"open_container_2": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+Shift+3"
|
||||
},
|
||||
"description": "Container Shortcut 3"
|
||||
},
|
||||
"open_container_3": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+Shift+4"
|
||||
},
|
||||
"description": "Container Shortcut 4"
|
||||
},
|
||||
"open_container_4": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+Shift+5"
|
||||
},
|
||||
"description": "Container Shortcut 5"
|
||||
},
|
||||
"open_container_5": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+Shift+6"
|
||||
},
|
||||
"description": "Container Shortcut 6"
|
||||
},
|
||||
"open_container_6": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+Shift+7"
|
||||
},
|
||||
"description": "Container Shortcut 7"
|
||||
},
|
||||
"open_container_7": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+Shift+8"
|
||||
},
|
||||
"description": "Container Shortcut 8"
|
||||
},
|
||||
"open_container_8": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+Shift+9"
|
||||
},
|
||||
"description": "Container Shortcut 9"
|
||||
},
|
||||
"open_container_9": {
|
||||
"suggested_key": {
|
||||
"default": "Ctrl+Shift+0"
|
||||
},
|
||||
"description": "Container Shortcut 10"
|
||||
}
|
||||
},
|
||||
"browser_action": {
|
||||
|
|
|
@ -18,15 +18,55 @@
|
|||
</label>
|
||||
<p>This setting allows you to sync your containers and site assignments across devices.</p>
|
||||
<p><label>
|
||||
Container to open with Keyboard Shortcut 0
|
||||
Container to open with Keyboard Shortcut 1
|
||||
<select id="open_container_0">
|
||||
</select>
|
||||
</label></p>
|
||||
<p><label>
|
||||
Container to open with Keyboard Shortcut 1
|
||||
Container to open with Keyboard Shortcut 2
|
||||
<select id="open_container_1">
|
||||
</select>
|
||||
</label></p>
|
||||
<p><label>
|
||||
Container to open with Keyboard Shortcut 3
|
||||
<select id="open_container_2">
|
||||
</select>
|
||||
</label></p>
|
||||
<p><label>
|
||||
Container to open with Keyboard Shortcut 4
|
||||
<select id="open_container_3">
|
||||
</select>
|
||||
</label></p>
|
||||
<p><label>
|
||||
Container to open with Keyboard Shortcut 5
|
||||
<select id="open_container_4">
|
||||
</select>
|
||||
</label></p>
|
||||
<p><label>
|
||||
Container to open with Keyboard Shortcut 6
|
||||
<select id="open_container_5">
|
||||
</select>
|
||||
</label></p>
|
||||
<p><label>
|
||||
Container to open with Keyboard Shortcut 7
|
||||
<select id="open_container_6">
|
||||
</select>
|
||||
</label></p>
|
||||
<p><label>
|
||||
Container to open with Keyboard Shortcut 8
|
||||
<select id="open_container_7">
|
||||
</select>
|
||||
</label></p>
|
||||
<p><label>
|
||||
Container to open with Keyboard Shortcut 9
|
||||
<select id="open_container_8">
|
||||
</select>
|
||||
</label></p>
|
||||
<p><label>
|
||||
Container to open with Keyboard Shortcut 10
|
||||
<select id="open_container_9">
|
||||
</select>
|
||||
</label></p>
|
||||
<button>Reset Onboarding Panels </button>
|
||||
</form>
|
||||
<script src="js/options.js"></script>
|
||||
|
|
Loading…
Add table
Reference in a new issue