Add an option to not show hidden tabs when opening a new tab in a hidden container

This commit is contained in:
Anders Stedtlund 2018-02-06 08:59:59 +01:00
parent 22ec01d565
commit 0cd51bd9dc
4 changed files with 58 additions and 2 deletions

View file

@ -119,8 +119,8 @@ const messageHandler = {
// increment the counter of container tabs opened
this.incrementCountOfContainerTabsOpened();
}
this.unhideContainer(tab.cookieStoreId);
// Optionally open hidden tabs.
this.optionallyUnhideContainer(tab.cookieStoreId);
}
setTimeout(() => {
this.lastCreatedTab = null;
@ -146,6 +146,15 @@ const messageHandler = {
}
},
async optionallyUnhideContainer(cookieStoreId) {
const key = "showAllTabs";
// Use true if not set in the storage yet. Will show all hidden tabs as default.
const showAllTabs = await browser.storage.local.get({[key]: true});
if (showAllTabs.showAllTabs) {
this.unhideContainer(cookieStoreId);
}
},
async unhideContainer(cookieStoreId) {
if (!this.unhideQueue.includes(cookieStoreId)) {
this.unhideQueue.push(cookieStoreId);

View file

@ -62,6 +62,10 @@
}
],
"options_ui": {
"page": "options/options.html"
},
"web_accessible_resources": [
"/img/container-site-d-24.png"
]

19
src/options/options.html Normal file
View file

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<form>
<label>Show hidden tabs when a new tab is opened in a hidden container <input type="checkbox" id="showAllTabs" ></label>
<button type="submit">Save</button>
</form>
<script src="options.js"></script>
</body>
</html>

24
src/options/options.js Normal file
View file

@ -0,0 +1,24 @@
function saveOptions(e) {
e.preventDefault();
browser.storage.local.set({
showAllTabs : document.querySelector("#showAllTabs").checked
});
}
function restoreOptions() {
function setShowAllTabs(result) {
document.querySelector("#showAllTabs").checked = result.showAllTabs;
}
function onError(error) {
console.log(`Error: ${error}`);
}
var key = "showAllTabs";
var showAllTabs = browser.storage.local.get({[key]: true});
showAllTabs.then(setShowAllTabs, onError);
}
document.addEventListener("DOMContentLoaded", restoreOptions);
document.querySelector("form").addEventListener("submit", saveOptions);