Files
I2P_in_Private_Browsing_Mod…/context.js

76 lines
2.1 KiB
JavaScript
Raw Normal View History

2019-07-10 02:29:38 -04:00
//var windowIds = []
2021-12-28 20:36:17 -05:00
var titlepref = chrome.i18n.getMessage('titlePreface');
function onError(error) {
2020-01-14 14:49:48 -05:00
console.log(`Error : ${error}`);
}
function eventHandler(event) {
2019-11-24 04:13:12 -05:00
function onCreated(windowInfo) {
2020-01-14 14:49:48 -05:00
console.log(`Created window : ${windowInfo.id}`);
2019-11-24 04:13:12 -05:00
browser.tabs.create({
windowId: windowInfo.id,
2021-12-28 20:36:17 -05:00
url: 'about:blank',
cookieStoreId: event.target.dataset.identity
2019-11-24 04:13:12 -05:00
});
}
2021-12-28 20:36:17 -05:00
if (event.target.dataset.action == 'create') {
var creating = browser.tabs.create({
2021-12-28 20:36:17 -05:00
cookieStoreId: event.target.dataset.identity
2019-10-06 15:18:10 -04:00
});
creating.then(onCreated, onError);
}
2021-12-28 20:36:17 -05:00
if (event.target.dataset.action == 'close-all') {
2019-12-24 16:51:38 -05:00
browser.tabs
.query({
2021-12-28 20:36:17 -05:00
cookieStoreId: event.target.dataset.identity
2019-12-24 16:51:38 -05:00
})
2020-11-10 21:48:08 -05:00
.then((tabs) => {
browser.tabs.remove(tabs.map((rem) => rem.id));
2019-10-06 15:18:10 -04:00
});
}
event.preventDefault();
}
function createOptions(node, identity) {
2019-12-24 16:51:38 -05:00
for (let option of ["Create", "Close All"]) {
let alink = document.createElement("a");
alink.href = "#";
alink.innerText = option;
alink.dataset.action = option.toLowerCase().replace(" ", "-");
alink.dataset.identity = identity.cookieStoreId;
alink.addEventListener("click", eventHandler);
node.appendChild(alink);
2019-10-06 15:18:10 -04:00
}
}
2019-10-06 15:18:10 -04:00
var div = document.getElementById("identity-list");
if (browser.contextualIdentities === undefined) {
2019-10-06 15:18:10 -04:00
div.innerText =
"browser.contextualIdentities not available. Check that the privacy.userContext.enabled pref is set to true, and reload the add-on.";
} else {
2019-12-24 16:51:38 -05:00
browser.contextualIdentities
.query({
2020-11-10 21:48:08 -05:00
name: titlepref,
2019-12-24 16:51:38 -05:00
})
2020-11-10 21:48:08 -05:00
.then((identities) => {
2019-10-06 15:18:10 -04:00
if (!identities.length) {
div.innerText = "No identities returned from the API.";
return;
}
2019-10-06 15:18:10 -04:00
for (let identity of identities) {
let row = document.createElement("div");
2020-10-30 23:50:23 -04:00
let span = document.createElement("div");
2019-10-06 15:18:10 -04:00
span.className = "identity";
span.innerText = identity.name;
span.style = `color: ${identity.color}`;
console.log(identity);
row.appendChild(span);
createOptions(row, identity);
div.appendChild(row);
}
});
}