Add option to disable the page action
This commit is contained in:
parent
6bf0f78cfc
commit
6bcbd801b2
5 changed files with 46 additions and 2 deletions
|
@ -51,6 +51,11 @@ window.assignManager = {
|
||||||
return !!syncEnabled;
|
return !!syncEnabled;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async getPageActionEnabled() {
|
||||||
|
const { pageActionEnabled } = await browser.storage.local.get({ pageActionEnabled: true });
|
||||||
|
return !!pageActionEnabled;
|
||||||
|
},
|
||||||
|
|
||||||
async getReplaceTabEnabled() {
|
async getReplaceTabEnabled() {
|
||||||
const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled");
|
const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled");
|
||||||
return !!replaceTabEnabled;
|
return !!replaceTabEnabled;
|
||||||
|
@ -417,6 +422,19 @@ window.assignManager = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async resetPageAction() {
|
||||||
|
const pageActionEnabled = await this.storageArea.getPageActionEnabled();
|
||||||
|
const tabs = await browser.tabs.query({});
|
||||||
|
const res = tabs.map((tab) => {
|
||||||
|
if (pageActionEnabled) {
|
||||||
|
return browser.pageAction.show(tab.id);
|
||||||
|
} else {
|
||||||
|
return browser.pageAction.hide(tab.id);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
await Promise.all(res);
|
||||||
|
},
|
||||||
|
|
||||||
contextualIdentityCreated(changeInfo) {
|
contextualIdentityCreated(changeInfo) {
|
||||||
browser.contextMenus.create({
|
browser.contextMenus.create({
|
||||||
parentId: assignManager.OPEN_IN_CONTAINER,
|
parentId: assignManager.OPEN_IN_CONTAINER,
|
||||||
|
|
|
@ -23,6 +23,9 @@ const messageHandler = {
|
||||||
case "resetBookmarksContext":
|
case "resetBookmarksContext":
|
||||||
response = assignManager.resetBookmarksMenuItem();
|
response = assignManager.resetBookmarksMenuItem();
|
||||||
break;
|
break;
|
||||||
|
case "resetPageAction":
|
||||||
|
response = assignManager.resetPageAction();
|
||||||
|
break;
|
||||||
case "deleteContainer":
|
case "deleteContainer":
|
||||||
response = backgroundLogic.deleteContainer(m.message.userContextId);
|
response = backgroundLogic.deleteContainer(m.message.userContextId);
|
||||||
break;
|
break;
|
||||||
|
@ -180,6 +183,17 @@ const messageHandler = {
|
||||||
});
|
});
|
||||||
}, {urls: ["<all_urls>"], types: ["main_frame"]});
|
}, {urls: ["<all_urls>"], types: ["main_frame"]});
|
||||||
|
|
||||||
|
browser.tabs.onUpdated.addListener((tabId) => {
|
||||||
|
// check if the page action is enabled right away to avoid flashing
|
||||||
|
browser.storage.local.get({ pageActionEnabled: true }).then(({ pageActionEnabled }) => {
|
||||||
|
if (pageActionEnabled) {
|
||||||
|
browser.pageAction.show(tabId);
|
||||||
|
}
|
||||||
|
}).catch(e => {
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
}, { properties: ["status"] });
|
||||||
|
|
||||||
browser.tabs.onCreated.addListener((tab) => {
|
browser.tabs.onCreated.addListener((tab) => {
|
||||||
// lets remember the last tab created so we can close it if it looks like a redirect
|
// lets remember the last tab created so we can close it if it looks like a redirect
|
||||||
this.lastCreatedTab = tab;
|
this.lastCreatedTab = tab;
|
||||||
|
|
|
@ -25,15 +25,23 @@ async function enableDisableReplaceTab() {
|
||||||
await browser.storage.local.set({replaceTabEnabled: !!checkbox.checked});
|
await browser.storage.local.set({replaceTabEnabled: !!checkbox.checked});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function enableDisablePageAction() {
|
||||||
|
const checkbox = document.querySelector("#pageActionCheck");
|
||||||
|
await browser.storage.local.set({pageActionEnabled: !!checkbox.checked});
|
||||||
|
await browser.runtime.sendMessage({ method: "resetPageAction" });
|
||||||
|
}
|
||||||
|
|
||||||
async function setupOptions() {
|
async function setupOptions() {
|
||||||
const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]});
|
const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]});
|
||||||
const { syncEnabled } = await browser.storage.local.get("syncEnabled");
|
const { syncEnabled } = await browser.storage.local.get("syncEnabled");
|
||||||
const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled");
|
const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled");
|
||||||
|
const { pageActionEnabled } = await browser.storage.local.get({ pageActionEnabled: true });
|
||||||
if (hasPermission) {
|
if (hasPermission) {
|
||||||
document.querySelector("#bookmarksPermissions").checked = true;
|
document.querySelector("#bookmarksPermissions").checked = true;
|
||||||
}
|
}
|
||||||
document.querySelector("#syncCheck").checked = !!syncEnabled;
|
document.querySelector("#syncCheck").checked = !!syncEnabled;
|
||||||
document.querySelector("#replaceTabCheck").checked = !!replaceTabEnabled;
|
document.querySelector("#replaceTabCheck").checked = !!replaceTabEnabled;
|
||||||
|
document.querySelector("#pageActionCheck").checked = !!pageActionEnabled;
|
||||||
setupContainerShortcutSelects();
|
setupContainerShortcutSelects();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,6 +90,7 @@ document.addEventListener("DOMContentLoaded", setupOptions);
|
||||||
document.querySelector("#bookmarksPermissions").addEventListener( "change", requestPermissions);
|
document.querySelector("#bookmarksPermissions").addEventListener( "change", requestPermissions);
|
||||||
document.querySelector("#syncCheck").addEventListener( "change", enableDisableSync);
|
document.querySelector("#syncCheck").addEventListener( "change", enableDisableSync);
|
||||||
document.querySelector("#replaceTabCheck").addEventListener( "change", enableDisableReplaceTab);
|
document.querySelector("#replaceTabCheck").addEventListener( "change", enableDisableReplaceTab);
|
||||||
|
document.querySelector("#pageActionCheck").addEventListener( "change", enableDisablePageAction);
|
||||||
document.querySelector("button").addEventListener("click", resetOnboarding);
|
document.querySelector("button").addEventListener("click", resetOnboarding);
|
||||||
|
|
||||||
for (let i=0; i < NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
|
for (let i=0; i < NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
|
||||||
|
|
|
@ -119,8 +119,7 @@
|
||||||
"default_icon": "img/container-openin-16.svg",
|
"default_icon": "img/container-openin-16.svg",
|
||||||
"default_title": "Always open this in a Container",
|
"default_title": "Always open this in a Container",
|
||||||
"default_popup": "pageActionPopup.html",
|
"default_popup": "pageActionPopup.html",
|
||||||
"pinned": false,
|
"pinned": false
|
||||||
"show_matches": ["*://*/*"]
|
|
||||||
},
|
},
|
||||||
"background": {
|
"background": {
|
||||||
"page": "js/background/index.html"
|
"page": "js/background/index.html"
|
||||||
|
|
|
@ -27,6 +27,10 @@
|
||||||
</label>
|
</label>
|
||||||
<p><em>Replace the current tab if a page which is assigned to another container is opened (instead of keeping the current tab open).
|
<p><em>Replace the current tab if a page which is assigned to another container is opened (instead of keeping the current tab open).
|
||||||
Opening tabs with middle mouse button is not affected.</em></p>
|
Opening tabs with middle mouse button is not affected.</em></p>
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="pageActionCheck">
|
||||||
|
Show the "Always open this in a container" button in the URL bar
|
||||||
|
</label>
|
||||||
<h3>Keyboard Shortcuts:</h3>
|
<h3>Keyboard Shortcuts:</h3>
|
||||||
<p><em>Edit which container is opened when using the numbered shortcuts.</em></p>
|
<p><em>Edit which container is opened when using the numbered shortcuts.</em></p>
|
||||||
<p><label>
|
<p><label>
|
||||||
|
|
Loading…
Add table
Reference in a new issue