2019-07-10 02:29:38 -04:00
|
|
|
//var windowIds = []
|
2022-10-24 19:57:51 -04:00
|
|
|
var titlepref = chrome.i18n.getMessage("titlePreface");
|
2019-07-10 01:25:02 -04:00
|
|
|
|
2019-11-10 20:28:31 -05:00
|
|
|
function onError(error) {
|
2022-10-07 19:32:52 -04:00
|
|
|
console.log(`Error : ${error}`);
|
2019-11-10 20:28:31 -05:00
|
|
|
}
|
|
|
|
|
2019-07-10 01:25:02 -04:00
|
|
|
function eventHandler(event) {
|
2022-10-07 19:32:52 -04:00
|
|
|
function onCreated(windowInfo) {
|
|
|
|
console.log(`Created window : ${windowInfo.id}`);
|
|
|
|
browser.tabs.create({
|
|
|
|
windowId: windowInfo.id,
|
2022-10-24 19:57:51 -04:00
|
|
|
url: "about:blank",
|
|
|
|
cookieStoreId: event.target.dataset.identity,
|
2022-10-07 19:32:52 -04:00
|
|
|
});
|
|
|
|
}
|
2022-10-24 19:57:51 -04:00
|
|
|
if (event.target.dataset.action == "new-i2p browser tab") {
|
2022-10-07 19:32:52 -04:00
|
|
|
var creating = browser.tabs.create({
|
2022-10-24 19:57:51 -04:00
|
|
|
cookieStoreId: event.target.dataset.identity,
|
2022-10-07 19:32:52 -04:00
|
|
|
});
|
|
|
|
creating.then(onCreated, onError);
|
|
|
|
}
|
2022-10-24 19:57:51 -04:00
|
|
|
if (event.target.dataset.action == "close-all i2p browser tabs") {
|
2022-10-07 19:32:52 -04:00
|
|
|
browser.tabs
|
|
|
|
.query({
|
2022-10-24 19:57:51 -04:00
|
|
|
cookieStoreId: event.target.dataset.identity,
|
2022-10-07 19:32:52 -04:00
|
|
|
})
|
|
|
|
.then((tabs) => {
|
|
|
|
browser.tabs.remove(tabs.map((rem) => rem.id));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
2019-07-10 01:25:02 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function createOptions(node, identity) {
|
2022-10-07 19:32:52 -04:00
|
|
|
for (let option of ["New I2P Browser Tab", "Close All I2P Browser Tabs"]) {
|
|
|
|
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-07-10 01:25:02 -04:00
|
|
|
}
|
|
|
|
|
2019-10-06 15:18:10 -04:00
|
|
|
var div = document.getElementById("identity-list");
|
2019-07-10 01:25:02 -04:00
|
|
|
|
|
|
|
if (browser.contextualIdentities === undefined) {
|
2022-10-07 19:32:52 -04:00
|
|
|
div.innerText =
|
|
|
|
"browser.contextualIdentities not available. Check that the privacy.userContext.enabled pref is set to true, and reload the add-on.";
|
2019-07-10 01:25:02 -04:00
|
|
|
} else {
|
2022-10-07 19:32:52 -04:00
|
|
|
browser.contextualIdentities
|
|
|
|
.query({
|
|
|
|
name: titlepref,
|
|
|
|
})
|
|
|
|
.then((identities) => {
|
|
|
|
if (!identities.length) {
|
|
|
|
div.innerText = "No identities returned from the API.";
|
|
|
|
return;
|
|
|
|
}
|
2019-07-10 01:25:02 -04:00
|
|
|
|
2022-10-07 19:32:52 -04:00
|
|
|
for (let identity of identities) {
|
|
|
|
let row = document.createElement("div");
|
|
|
|
let span = document.createElement("div");
|
|
|
|
span.className = "identity";
|
|
|
|
span.innerText = identity.name;
|
|
|
|
console.log(identity);
|
|
|
|
row.appendChild(span);
|
|
|
|
createOptions(row, identity);
|
|
|
|
div.appendChild(row);
|
|
|
|
}
|
|
|
|
});
|
2022-10-03 19:58:07 -04:00
|
|
|
}
|