in src/js/shared/data-opt-out-toggle.js [6:35]
async function enableDataOptOut() {
const dataCollectionPrefToggle = document.querySelector(".data-collection");
const stylePrefToggle = (userPref) => {
if (userPref === "data-enabled") {
dataCollectionPrefToggle.classList.remove("data-disabled");
dataCollectionPrefToggle.title = browser.i18n.getMessage("disableDataCollection");
dataCollectionPrefToggle.dataset.collectionPreference = "data-disabled";
return;
}
dataCollectionPrefToggle.classList.add("data-disabled");
dataCollectionPrefToggle.title = browser.i18n.getMessage("allowDataCollection");
dataCollectionPrefToggle.dataset.collectionPreference = "data-enabled";
};
const { dataCollection } = await browser.storage.local.get("dataCollection");
if (!dataCollection) {
browser.storage.local.set({ "dataCollection": "data-enabled" });
stylePrefToggle("data-enabled")
} else {
stylePrefToggle(dataCollection);
}
dataCollectionPrefToggle.addEventListener("click", async(e) => {
const collectionPreference = e.target.dataset.collectionPreference;
await browser.storage.local.set({ "dataCollection" : collectionPreference });
stylePrefToggle(collectionPreference);
});
}