Adding in hide/show API for containers

This commit is contained in:
Jonathan Kingston 2016-12-22 17:10:23 +00:00
parent 38a4eb68ec
commit 1215e4e7f0
5 changed files with 1429 additions and 8 deletions

1
.gitignore vendored
View file

@ -2,3 +2,4 @@
node_modules
README.html
*.xpi
*.swp

File diff suppressed because it is too large Load diff

View file

@ -25,8 +25,34 @@
"parameters": [
{
"type": "string",
"name": "cookieStoreId",
"description": "The ID of the contextual identity cookie store. "
"name": "cookiestoreid",
"description": "the id of the contextual identity cookie store. "
}
]
},
{
"name": "hide",
"type": "function",
"description": "hides all of a contextual identity.",
"async": true,
"parameters": [
{
"type": "string",
"name": "cookiestoreid",
"description": "the id of the contextual identity cookie store. "
}
]
},
{
"name": "show",
"type": "function",
"description": "unhides all of a contextual identity.",
"async": true,
"parameters": [
{
"type": "string",
"name": "cookiestoreid",
"description": "the id of the contextual identity cookie store. "
}
]
},

View file

@ -1,24 +1,58 @@
const identityState = {
};
browser.contextualIdentities.query({}).then(identites=> {
let customContainerStyles = '';
const identitiesListElement = document.querySelector('.identities-list');
identites.forEach(identity=> {
identites.forEach(identity => {
const identityRow = `
<tr>
<tr data-identity-id="${identity.cookieStoreId}" >
<td><div class="userContext-icon"
data-identity-icon="${identity.icon}"
data-identity-color="${identity.color}"
></div></td>
<td>${identity.name}</td>
<td class="hideorshow" >H/S</td>
<td>&gt;</td>
</tr>`;
identitiesListElement.innerHTML += identityRow;
});
const rows = identitiesListElement.querySelectorAll('tr');
rows.forEach(row => {
row.addEventListener('click', (e) => {
if (e.target.matches('.hideorshow')) {
const containerId = e.target.parentElement.dataset.identityId;
if (!(containerId in identityState)) {
identityState[containerId] = true;
}
if (identityState[containerId]) {
hideContainer(containerId);
identityState[containerId] = false;
} else {
showContainer(containerId);
identityState[containerId] = true;
}
}
});
});
});
document.querySelector('#edit-containers-link').addEventListener('click', ()=> {
browser.runtime.sendMessage('open-containers-preferences').then(()=> {
window.close();
});
});
function hideContainer(containerId) {
browser.contextualIdentities.hide(containerId);
}
function showContainer(containerId) {
browser.contextualIdentities.show(containerId);
}

View file

@ -20,6 +20,7 @@
"homepage_url": "https://testpilot.firefox.com/",
"permissions": [
"cookies",
"experiments.contextualidentities",
"contextualidentities"
],