-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathoptions.js
41 lines (36 loc) · 1.62 KB
/
options.js
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
"use strict";
function requiresPermission() {
// As of Firefox 63, the "activeTab" unlocks access to the tab that was
// clicked ( https://bugzilla.mozilla.org/show_bug.cgi?id=1446956 ).
// Support for this functionality cannot easily be detected, so indirectly
// infer support for this feature via a different change in the same release:
// https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Releases/63#Menus
// If we ever stop supporting Firefox 62 and earlier (including ESR 60), then
// the "<all_urls>" optional permission can be removed from manifest.json,
// together with the uses of the browser.permissions API in this file.
return !browser.menus.getTargetElement;
}
var permissions = { origins: ["<all_urls>"] };
var prefPrependSnowflake = document.getElementById("prefPrependSnowflake");
prefPrependSnowflake.onchange = async () => {
if (prefPrependSnowflake.checked && requiresPermission()) {
prefPrependSnowflake.disabled = true;
prefPrependSnowflake.checked = await browser.permissions.request(permissions);
prefPrependSnowflake.disabled = false;
} else {
browser.permissions.remove(permissions);
}
browser.storage.local.set({
prependSnowflake: prefPrependSnowflake.checked,
});
};
document.getElementById("i18n-toggleSnowflakePref").textContent =
browser.i18n.getMessage("toggleSnowflakePref");
browser.storage.onChanged.addListener((changes) => {
if (changes.prependSnowflake) {
prefPrependSnowflake.checked = changes.prependSnowflake.newValue;
}
});
browser.storage.local.get("prependSnowflake", (items) => {
prefPrependSnowflake.checked = !!items.prependSnowflake;
});