added bookmark context menu ref: issue #323
This commit is contained in:
parent
27d51f89c7
commit
18bc8eb5aa
2 changed files with 36 additions and 2 deletions
|
@ -4,6 +4,7 @@ const assignManager = {
|
||||||
MENU_SEPARATOR_ID: "separator",
|
MENU_SEPARATOR_ID: "separator",
|
||||||
MENU_HIDE_ID: "hide-container",
|
MENU_HIDE_ID: "hide-container",
|
||||||
MENU_MOVE_ID: "move-to-new-window-container",
|
MENU_MOVE_ID: "move-to-new-window-container",
|
||||||
|
OPEN_IN_CONTAINER: "open-link-in-container-tab",
|
||||||
|
|
||||||
storageArea: {
|
storageArea: {
|
||||||
area: browser.storage.local,
|
area: browser.storage.local,
|
||||||
|
@ -221,7 +222,11 @@ const assignManager = {
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
browser.contextMenus.onClicked.addListener((info, tab) => {
|
browser.contextMenus.onClicked.addListener((info, tab) => {
|
||||||
this._onClickedHandler(info, tab);
|
if (tab) {
|
||||||
|
this._onClickedHandler(info, tab);
|
||||||
|
} else {
|
||||||
|
this._onClickedBookmark(info);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Before a request is handled by the browser we decide if we should route through a different container
|
// Before a request is handled by the browser we decide if we should route through a different container
|
||||||
|
@ -242,6 +247,8 @@ const assignManager = {
|
||||||
}
|
}
|
||||||
},{urls: ["<all_urls>"], types: ["main_frame"]});
|
},{urls: ["<all_urls>"], types: ["main_frame"]});
|
||||||
|
|
||||||
|
this.initBookmarksMenu();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
async _onClickedHandler(info, tab) {
|
async _onClickedHandler(info, tab) {
|
||||||
|
@ -275,6 +282,14 @@ const assignManager = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async _onClickedBookmark(info) {
|
||||||
|
const bookmark = await browser.bookmarks.get(info.bookmarkId);
|
||||||
|
browser.tabs.create({
|
||||||
|
cookieStoreId: info.menuItemId,
|
||||||
|
url: bookmark[0].url
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
deleteContainer(userContextId) {
|
deleteContainer(userContextId) {
|
||||||
this.storageArea.deleteContainer(userContextId);
|
this.storageArea.deleteContainer(userContextId);
|
||||||
|
@ -442,6 +457,24 @@ const assignManager = {
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
async initBookmarksMenu() {
|
||||||
|
browser.contextMenus.create({
|
||||||
|
id: this.OPEN_IN_CONTAINER,
|
||||||
|
title: "Open Link in Container Tab",
|
||||||
|
contexts: ["bookmark"],
|
||||||
|
});
|
||||||
|
|
||||||
|
const identities = await browser.contextualIdentities.query({});
|
||||||
|
for (let identity of identities) { // eslint-disable-line prefer-const
|
||||||
|
browser.contextMenus.create({
|
||||||
|
parentId: this.OPEN_IN_CONTAINER,
|
||||||
|
id: identity.cookieStoreId,
|
||||||
|
title: identity.name,
|
||||||
|
icons: { "16": `img/usercontext.svg#${identity.icon}` }
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,8 @@
|
||||||
"storage",
|
"storage",
|
||||||
"tabs",
|
"tabs",
|
||||||
"webRequestBlocking",
|
"webRequestBlocking",
|
||||||
"webRequest"
|
"webRequest",
|
||||||
|
"bookmarks"
|
||||||
],
|
],
|
||||||
|
|
||||||
"commands": {
|
"commands": {
|
||||||
|
|
Loading…
Add table
Reference in a new issue