From 18bc8eb5aa6b9483cadfa36e656bed48335f1ed1 Mon Sep 17 00:00:00 2001 From: Kendall Werts Date: Thu, 17 Oct 2019 14:11:59 -0500 Subject: [PATCH] added bookmark context menu ref: issue #323 --- src/js/background/assignManager.js | 35 +++++++++++++++++++++++++++++- src/manifest.json | 3 ++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/js/background/assignManager.js b/src/js/background/assignManager.js index dc9e991..940c906 100644 --- a/src/js/background/assignManager.js +++ b/src/js/background/assignManager.js @@ -4,6 +4,7 @@ const assignManager = { MENU_SEPARATOR_ID: "separator", MENU_HIDE_ID: "hide-container", MENU_MOVE_ID: "move-to-new-window-container", + OPEN_IN_CONTAINER: "open-link-in-container-tab", storageArea: { area: browser.storage.local, @@ -221,7 +222,11 @@ const assignManager = { init() { 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 @@ -242,6 +247,8 @@ const assignManager = { } },{urls: [""], types: ["main_frame"]}); + this.initBookmarksMenu(); + }, 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) { this.storageArea.deleteContainer(userContextId); @@ -442,6 +457,24 @@ const assignManager = { 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}` } + }); + } } }; diff --git a/src/manifest.json b/src/manifest.json index bab033b..54946e0 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -30,7 +30,8 @@ "storage", "tabs", "webRequestBlocking", - "webRequest" + "webRequest", + "bookmarks" ], "commands": {