added bookmarks as optional_permission and added checkbox in preferences menu.
This commit is contained in:
parent
7e4950b184
commit
e7824f367b
6 changed files with 102 additions and 14 deletions
|
@ -5,7 +5,6 @@ const assignManager = {
|
||||||
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-bookmark-in-container-tab",
|
OPEN_IN_CONTAINER: "open-bookmark-in-container-tab",
|
||||||
|
|
||||||
storageArea: {
|
storageArea: {
|
||||||
area: browser.storage.local,
|
area: browser.storage.local,
|
||||||
exemptedTabs: {},
|
exemptedTabs: {},
|
||||||
|
@ -222,11 +221,7 @@ const assignManager = {
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
browser.contextMenus.onClicked.addListener((info, tab) => {
|
browser.contextMenus.onClicked.addListener((info, tab) => {
|
||||||
if (info.bookmarkId) {
|
info.bookmarkId ? this._onClickedBookmark(info) : this._onClickedHandler(info, tab);
|
||||||
this._onClickedBookmark(info);
|
|
||||||
} else {
|
|
||||||
this._onClickedHandler(info, tab);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// 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
|
||||||
|
@ -246,6 +241,24 @@ const assignManager = {
|
||||||
delete this.canceledRequests[options.tabId];
|
delete this.canceledRequests[options.tabId];
|
||||||
}
|
}
|
||||||
},{urls: ["<all_urls>"], types: ["main_frame"]});
|
},{urls: ["<all_urls>"], types: ["main_frame"]});
|
||||||
|
this.getPermissions();
|
||||||
|
},
|
||||||
|
|
||||||
|
getPermissions() {
|
||||||
|
browser.permissions.getAll().
|
||||||
|
then((permissions) => {
|
||||||
|
if (permissions.permissions.includes("bookmarks")) {
|
||||||
|
this.makeBookmarksMenu();
|
||||||
|
} else {
|
||||||
|
browser.contextMenus.remove(this.OPEN_IN_CONTAINER);
|
||||||
|
}
|
||||||
|
}).
|
||||||
|
catch((err) => {
|
||||||
|
return err.message;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
makeBookmarksMenu() {
|
||||||
this.initBookmarksMenu();
|
this.initBookmarksMenu();
|
||||||
browser.contextualIdentities.onCreated.addListener(this.contextualIdentCreated);
|
browser.contextualIdentities.onCreated.addListener(this.contextualIdentCreated);
|
||||||
browser.contextualIdentities.onUpdated.addListener(this.contextualIdentUpdated);
|
browser.contextualIdentities.onUpdated.addListener(this.contextualIdentUpdated);
|
||||||
|
@ -304,11 +317,19 @@ const assignManager = {
|
||||||
},
|
},
|
||||||
|
|
||||||
async _onClickedBookmark(info) {
|
async _onClickedBookmark(info) {
|
||||||
let bookmarks = await browser.bookmarks.get(info.bookmarkId);
|
|
||||||
if (bookmarks[0].type === "folder") {
|
async function _getBookmarksFromInfo(info) {
|
||||||
bookmarks = await browser.bookmarks.getChildren(bookmarks[0].id);
|
const bookmarkTreeNode = await browser.bookmarks.get(info.bookmarkId);
|
||||||
|
const firstBookmark = bookmarkTreeNode[0];
|
||||||
|
if (firstBookmark.type === "folder") {
|
||||||
|
return await browser.bookmarks.getChildren(firstBookmark.id);
|
||||||
|
} else {
|
||||||
|
return bookmarkTreeNode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (let bookmark of bookmarks) { // eslint-disable-line prefer-const
|
|
||||||
|
const bookmarks = await _getBookmarksFromInfo(info);
|
||||||
|
for (const bookmark of bookmarks) {
|
||||||
browser.tabs.create({
|
browser.tabs.create({
|
||||||
cookieStoreId: info.menuItemId,
|
cookieStoreId: info.menuItemId,
|
||||||
url: bookmark.url
|
url: bookmark.url
|
||||||
|
@ -493,7 +514,7 @@ const assignManager = {
|
||||||
});
|
});
|
||||||
|
|
||||||
const identities = await browser.contextualIdentities.query({});
|
const identities = await browser.contextualIdentities.query({});
|
||||||
for (let identity of identities) { // eslint-disable-line prefer-const
|
for (const identity of identities) {
|
||||||
browser.contextMenus.create({
|
browser.contextMenus.create({
|
||||||
parentId: this.OPEN_IN_CONTAINER,
|
parentId: this.OPEN_IN_CONTAINER,
|
||||||
id: identity.cookieStoreId,
|
id: identity.cookieStoreId,
|
||||||
|
|
|
@ -326,4 +326,4 @@ const backgroundLogic = {
|
||||||
cookieStoreId(userContextId) {
|
cookieStoreId(userContextId) {
|
||||||
return `firefox-container-${userContextId}`;
|
return `firefox-container-${userContextId}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
|
@ -10,6 +10,9 @@ const messageHandler = {
|
||||||
let response;
|
let response;
|
||||||
|
|
||||||
switch (m.method) {
|
switch (m.method) {
|
||||||
|
case "resetBookmarksContext":
|
||||||
|
response = assignManager.getPermissions();
|
||||||
|
break;
|
||||||
case "deleteContainer":
|
case "deleteContainer":
|
||||||
response = backgroundLogic.deleteContainer(m.message.userContextId);
|
response = backgroundLogic.deleteContainer(m.message.userContextId);
|
||||||
break;
|
break;
|
||||||
|
|
41
src/js/options.js
Normal file
41
src/js/options.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
|
||||||
|
function requestPermissions() {
|
||||||
|
const checkbox = document.querySelector("#bookmarksPermissions");
|
||||||
|
if (checkbox.checked) {
|
||||||
|
browser.permissions.request({permissions: ["bookmarks"]}).
|
||||||
|
then((response) => {
|
||||||
|
if (response) {
|
||||||
|
browser.runtime.sendMessage({ method: "resetBookmarksContext" });
|
||||||
|
} else {
|
||||||
|
checkbox.checked = false;
|
||||||
|
}
|
||||||
|
}).
|
||||||
|
catch((err) => {
|
||||||
|
return err.message;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
browser.permissions.remove({permissions: ["bookmarks"]}).
|
||||||
|
then(() => {
|
||||||
|
browser.runtime.sendMessage({ method: "resetBookmarksContext" });
|
||||||
|
}).
|
||||||
|
catch((err) => {
|
||||||
|
return err.message;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function restoreOptions() {
|
||||||
|
browser.permissions.getAll()
|
||||||
|
.then((permissions) => {
|
||||||
|
if (permissions.permissions.includes("bookmarks")) {
|
||||||
|
document.querySelector("#bookmarksPermissions").checked = true;
|
||||||
|
}
|
||||||
|
}).
|
||||||
|
catch((err) => {
|
||||||
|
return err.message;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", restoreOptions);
|
||||||
|
document.querySelector("#bookmarksPermissions").addEventListener( "change", requestPermissions);
|
|
@ -30,7 +30,10 @@
|
||||||
"storage",
|
"storage",
|
||||||
"tabs",
|
"tabs",
|
||||||
"webRequestBlocking",
|
"webRequestBlocking",
|
||||||
"webRequest",
|
"webRequest"
|
||||||
|
],
|
||||||
|
|
||||||
|
"optional_permissions": [
|
||||||
"bookmarks"
|
"bookmarks"
|
||||||
],
|
],
|
||||||
|
|
||||||
|
@ -71,5 +74,9 @@
|
||||||
|
|
||||||
"web_accessible_resources": [
|
"web_accessible_resources": [
|
||||||
"/img/container-site-d-24.png"
|
"/img/container-site-d-24.png"
|
||||||
]
|
],
|
||||||
|
|
||||||
|
"options_ui": {
|
||||||
|
"page": "options.html"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
16
src/options.html
Normal file
16
src/options.html
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<form>
|
||||||
|
<input type="checkbox" id="bookmarksPermissions"/>
|
||||||
|
<label>Enable Bookmark Permissions</label>
|
||||||
|
<p>This setting allows you to open a bookmark or folder of bookmarks in a container.</p>
|
||||||
|
</form>
|
||||||
|
<script src="js/options.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Add table
Reference in a new issue