1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
const useDefault = "Use default";
const defaultId = "defaultId";
const saveSettings = async () => {
const params = new URLSearchParams(window.location.search);
const folderId = params.get("id");
const identityId = document.getElementById("identityId").value;
const to = document.getElementById("to").value.trim();
const replyTo = document.getElementById("replyTo").value.trim();
const addToCcOnReply = document.getElementById("addToCcOnReply").checked;
const replyToOnReplyForward = document.getElementById(
"replyToOnReplyForward"
).checked;
const overrideReturnAddress = document.getElementById(
"overrideReturnAddress"
).checked;
let [settings] = Object.values(await browser.storage.local.get(folderId));
if (!settings) {
settings = {};
}
const setOrClearSetting = (pref, value, valueToClear) => {
if (value == valueToClear) {
delete settings[pref];
} else {
settings[pref] = value;
}
};
setOrClearSetting("identityId", identityId, defaultId);
setOrClearSetting("to", to, "");
setOrClearSetting("replyTo", replyTo, "");
setOrClearSetting("addToCcOnReply", addToCcOnReply, false);
setOrClearSetting("replyToOnReplyForward", replyToOnReplyForward, false);
setOrClearSetting("overrideReturnAddress", overrideReturnAddress, false);
if (Object.entries(settings).length) {
await browser.storage.local.set({ [folderId]: settings });
} else {
await browser.storage.local.remove(folderId);
}
const thisWindow = await messenger.windows.getCurrent();
browser.storage.local.set({
windowSize: { height: thisWindow.height, width: thisWindow.width },
});
window.close();
};
document.addEventListener("DOMContentLoaded", async () => {
const params = new URLSearchParams(window.location.search);
const folderId = params.get("id");
document.title = "Folder Account - Settings for " + folderId;
const saveButton = document.getElementById("save-button");
const cancelButton = document.getElementById("cancel-button");
if ((await browser.runtime.getPlatformInfo()).os == "win") {
saveButton.parentElement.insertBefore(saveButton, cancelButton);
}
saveButton.addEventListener("click", saveSettings);
cancelButton.addEventListener("click", () => {
window.close();
});
const [settings] = Object.values(await browser.storage.local.get(folderId));
const [sortIdentities] = Object.values(
await browser.storage.local.get("sortIdentities")
);
const menuList = document.getElementById("identityId");
const option = document.createElement("option");
option.text = useDefault;
option.value = defaultId;
menuList.add(option);
const accounts = await messenger.accounts.list(false);
for (const account of accounts) {
if (!account.identities.length) {
continue;
}
let menuListEntries = [];
for (const id of account.identities) {
let entry = "";
if (id.name.length > 0) {
entry += id.name + " <" + id.email + ">";
} else {
entry += id.email;
}
if (id.label.length > 0) {
entry += " (" + id.label + ")";
}
entry += "\u2003[" + account.name + "]";
menuListEntries[id.id] = entry;
}
let entriesArray = Object.entries(menuListEntries);
if (sortIdentities)
entriesArray = entriesArray.sort(([, a], [, b]) => a > b);
const separator = document.createElement("hr");
menuList.appendChild(separator);
for (const [id, text] of entriesArray) {
const option = document.createElement("option");
option.text = text;
option.value = id;
option.selected = settings?.identityId == id;
menuList.add(option);
}
}
if (!settings) {
return;
}
document.getElementById("to").setAttribute("value", settings.to ?? "");
document
.getElementById("replyTo")
.setAttribute("value", settings.replyTo ?? "");
document.getElementById("addToCcOnReply").checked = settings.addToCcOnReply;
document.getElementById("replyToOnReplyForward").checked =
settings.replyToOnReplyForward;
document.getElementById("overrideReturnAddress").checked =
settings.overrideReturnAddress;
});
document.addEventListener("keydown", (event) => {
if (event.key == "Enter") {
saveSettings();
}
if (event.key == "Escape") {
window.close();
}
});
|