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:home",
|
||||||
"about:blank"
|
"about:blank"
|
||||||
]),
|
]),
|
||||||
NUMBER_OF_KEYBOARD_SHORTCUTS: 2,
|
NUMBER_OF_KEYBOARD_SHORTCUTS: 10,
|
||||||
unhideQueue: [],
|
unhideQueue: [],
|
||||||
init() {
|
init() {
|
||||||
browser.commands.onCommand.addListener(function (command) {
|
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 key = "open_container_" + i;
|
||||||
const cookieStoreId = identityState.keyboardShortcut[key];
|
const cookieStoreId = identityState.keyboardShortcut[key];
|
||||||
if (command === key) {
|
if (command === key) {
|
||||||
|
if (cookieStoreId === "none") return;
|
||||||
browser.tabs.create({cookieStoreId});
|
browser.tabs.create({cookieStoreId});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,11 +49,21 @@ window.identityState = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async loadKeyboardShortcuts () {
|
async loadKeyboardShortcuts () {
|
||||||
|
const identities = await browser.contextualIdentities.query({});
|
||||||
for (let i=0; i < backgroundLogic.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
|
for (let i=0; i < backgroundLogic.NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
|
||||||
const key = "open_container_" + i;
|
const key = "open_container_" + i;
|
||||||
const storageObject = await this.area.get(key);
|
const storageObject = await this.area.get(key);
|
||||||
|
if (storageObject[key]){
|
||||||
identityState.keyboardShortcut[key] = 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) {
|
switch (m.method) {
|
||||||
case "getShortcuts":
|
case "getShortcuts":
|
||||||
console.log("getShortcuts", identityState.keyboardShortcut);
|
response = identityState.storageArea.loadKeyboardShortcuts();
|
||||||
response = identityState.keyboardShortcut;
|
|
||||||
break;
|
break;
|
||||||
case "setShortcut":
|
case "setShortcut":
|
||||||
identityState.storageArea.setKeyboardShortcut(m.shortcut, m.cookieStoreId);
|
identityState.storageArea.setKeyboardShortcut(m.shortcut, m.cookieStoreId);
|
||||||
|
@ -105,7 +104,6 @@ const messageHandler = {
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
console.log(m.method, "response", response);
|
|
||||||
return response;
|
return response;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const NUMBER_OF_KEYBOARD_SHORTCUTS = 2;
|
const NUMBER_OF_KEYBOARD_SHORTCUTS = 10;
|
||||||
|
|
||||||
async function requestPermissions() {
|
async function requestPermissions() {
|
||||||
const checkbox = document.querySelector("#bookmarksPermissions");
|
const checkbox = document.querySelector("#bookmarksPermissions");
|
||||||
|
@ -40,11 +40,11 @@ async function setupOptions() {
|
||||||
|
|
||||||
async function setupContainerShortcutSelects () {
|
async function setupContainerShortcutSelects () {
|
||||||
const keyboardShortcut = await browser.runtime.sendMessage({method: "getShortcuts"});
|
const keyboardShortcut = await browser.runtime.sendMessage({method: "getShortcuts"});
|
||||||
// console.log(keyboardShortcut);
|
|
||||||
const identities = await browser.contextualIdentities.query({});
|
const identities = await browser.contextualIdentities.query({});
|
||||||
const fragment = document.createDocumentFragment();
|
const fragment = document.createDocumentFragment();
|
||||||
const noneOption = document.createElement("option");
|
const noneOption = document.createElement("option");
|
||||||
noneOption.value = "none";
|
noneOption.value = "none";
|
||||||
|
noneOption.id = "none";
|
||||||
noneOption.textContent = "None";
|
noneOption.textContent = "None";
|
||||||
fragment.append(noneOption);
|
fragment.append(noneOption);
|
||||||
|
|
||||||
|
@ -61,7 +61,8 @@ async function setupContainerShortcutSelects () {
|
||||||
const shortcutSelect = document.getElementById(shortcutKey);
|
const shortcutSelect = document.getElementById(shortcutKey);
|
||||||
shortcutSelect.appendChild(fragment.cloneNode(true));
|
shortcutSelect.appendChild(fragment.cloneNode(true));
|
||||||
if (keyboardShortcut && keyboardShortcut[shortcutKey]) {
|
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"
|
"default": "Ctrl+Shift+2"
|
||||||
},
|
},
|
||||||
"description": "Container Shortcut 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": {
|
"browser_action": {
|
||||||
|
|
|
@ -18,15 +18,55 @@
|
||||||
</label>
|
</label>
|
||||||
<p>This setting allows you to sync your containers and site assignments across devices.</p>
|
<p>This setting allows you to sync your containers and site assignments across devices.</p>
|
||||||
<p><label>
|
<p><label>
|
||||||
Container to open with Keyboard Shortcut 0
|
Container to open with Keyboard Shortcut 1
|
||||||
<select id="open_container_0">
|
<select id="open_container_0">
|
||||||
</select>
|
</select>
|
||||||
</label></p>
|
</label></p>
|
||||||
<p><label>
|
<p><label>
|
||||||
Container to open with Keyboard Shortcut 1
|
Container to open with Keyboard Shortcut 2
|
||||||
<select id="open_container_1">
|
<select id="open_container_1">
|
||||||
</select>
|
</select>
|
||||||
</label></p>
|
</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>
|
<button>Reset Onboarding Panels </button>
|
||||||
</form>
|
</form>
|
||||||
<script src="js/options.js"></script>
|
<script src="js/options.js"></script>
|
||||||
|
|
Loading…
Add table
Reference in a new issue