Files
SysTray-X/webext/js/options_accounts.js

75 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-01-08 23:36:19 +01:00
var SysTrayX = {};
SysTrayX.Accounts = {
initialized: false,
2020-01-09 21:03:06 +01:00
2020-01-08 23:36:19 +01:00
init: function() {
if (this.initialized) {
console.log("Accounts already initialized");
return;
}
console.log("Enabling Accounts");
this.getAccounts().then(this.getAccountsCb);
this.initialized = true;
},
/*
* Use the messages API to get the unread messages (Promise)
* Be aware that the data is only avaiable inside the callback
*/
getAccounts: async function() {
return await browser.accounts.list();
},
2020-01-09 21:03:06 +01:00
2020-01-08 23:36:19 +01:00
/*
* Callback for getAccounts
*/
getAccountsCb: function(mailAccount) {
let accounts = new Object();
let i;
2020-01-09 21:03:06 +01:00
for (i = 0; i < mailAccount.length; i++) {
console.debug("SysTrayX accounts id: " + mailAccount[i].id);
console.debug("SysTrayX accounts name: " + mailAccount[i].name);
console.debug("SysTrayX accounts type: " + mailAccount[i].type);
2020-01-08 23:36:19 +01:00
accounts[mailAccount[i].type] = [];
2020-01-09 21:03:06 +01:00
accounts[mailAccount[i].type].push({
id: mailAccount[i].id,
name: mailAccount[i].name
});
}
console.debug("SysTrayX Storage: " + accounts.imap[0].name);
2020-01-08 23:36:19 +01:00
2020-01-09 21:03:06 +01:00
for (let prop in accounts) {
console.debug(prop + ": " + accounts[prop][0].name);
2020-01-08 23:36:19 +01:00
}
2020-01-09 21:03:06 +01:00
2020-01-08 23:36:19 +01:00
let p = document.getElementsByClassName("account");
p[0].innerHTML = accounts.imap[0].name;
// Get base
let treeBase = document.getElementsByClassName("accountstree");
2020-01-09 21:03:06 +01:00
for (let prop in accounts) {
console.debug("Tree: " + prop + ": " + accounts[prop][0].name);
let typeLi = document.createElement("li");
2020-01-08 23:36:19 +01:00
2020-01-09 21:03:06 +01:00
let typeSpan = document.createElement("span");
typeSpan.setAttribute("class", "caret");
2020-01-08 23:36:19 +01:00
let typeText = document.createTextNode(prop);
typeSpan.appendChild(typeText);
2020-01-09 21:03:06 +01:00
typeLi.appendChild(typeSpan);
2020-01-08 23:36:19 +01:00
2020-01-09 21:03:06 +01:00
treeBase[0].appendChild(typeLi);
}
}
2020-01-08 23:36:19 +01:00
};
SysTrayX.Accounts.init();