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;
|
||||
},
|
||||
|
||||
async getPageActionEnabled() {
|
||||
const { pageActionEnabled } = await browser.storage.local.get({ pageActionEnabled: true });
|
||||
return !!pageActionEnabled;
|
||||
},
|
||||
|
||||
async getReplaceTabEnabled() {
|
||||
const { replaceTabEnabled } = await browser.storage.local.get("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) {
|
||||
browser.contextMenus.create({
|
||||
parentId: assignManager.OPEN_IN_CONTAINER,
|
||||
|
|
|
@ -23,6 +23,9 @@ const messageHandler = {
|
|||
case "resetBookmarksContext":
|
||||
response = assignManager.resetBookmarksMenuItem();
|
||||
break;
|
||||
case "resetPageAction":
|
||||
response = assignManager.resetPageAction();
|
||||
break;
|
||||
case "deleteContainer":
|
||||
response = backgroundLogic.deleteContainer(m.message.userContextId);
|
||||
break;
|
||||
|
@ -180,6 +183,17 @@ const messageHandler = {
|
|||
});
|
||||
}, {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) => {
|
||||
// lets remember the last tab created so we can close it if it looks like a redirect
|
||||
this.lastCreatedTab = tab;
|
||||
|
|
|
@ -25,15 +25,23 @@ async function enableDisableReplaceTab() {
|
|||
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() {
|
||||
const hasPermission = await browser.permissions.contains({permissions: ["bookmarks"]});
|
||||
const { syncEnabled } = await browser.storage.local.get("syncEnabled");
|
||||
const { replaceTabEnabled } = await browser.storage.local.get("replaceTabEnabled");
|
||||
const { pageActionEnabled } = await browser.storage.local.get({ pageActionEnabled: true });
|
||||
if (hasPermission) {
|
||||
document.querySelector("#bookmarksPermissions").checked = true;
|
||||
}
|
||||
document.querySelector("#syncCheck").checked = !!syncEnabled;
|
||||
document.querySelector("#replaceTabCheck").checked = !!replaceTabEnabled;
|
||||
document.querySelector("#pageActionCheck").checked = !!pageActionEnabled;
|
||||
setupContainerShortcutSelects();
|
||||
}
|
||||
|
||||
|
@ -82,6 +90,7 @@ document.addEventListener("DOMContentLoaded", setupOptions);
|
|||
document.querySelector("#bookmarksPermissions").addEventListener( "change", requestPermissions);
|
||||
document.querySelector("#syncCheck").addEventListener( "change", enableDisableSync);
|
||||
document.querySelector("#replaceTabCheck").addEventListener( "change", enableDisableReplaceTab);
|
||||
document.querySelector("#pageActionCheck").addEventListener( "change", enableDisablePageAction);
|
||||
document.querySelector("button").addEventListener("click", resetOnboarding);
|
||||
|
||||
for (let i=0; i < NUMBER_OF_KEYBOARD_SHORTCUTS; i++) {
|
||||
|
|
|
@ -119,8 +119,7 @@
|
|||
"default_icon": "img/container-openin-16.svg",
|
||||
"default_title": "Always open this in a Container",
|
||||
"default_popup": "pageActionPopup.html",
|
||||
"pinned": false,
|
||||
"show_matches": ["*://*/*"]
|
||||
"pinned": false
|
||||
},
|
||||
"background": {
|
||||
"page": "js/background/index.html"
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
</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).
|
||||
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>
|
||||
<p><em>Edit which container is opened when using the numbered shortcuts.</em></p>
|
||||
<p><label>
|
||||
|
|
Loading…
Add table
Reference in a new issue