-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbackground.js
66 lines (53 loc) · 2.32 KB
/
background.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
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
/*
Firefox addon "Toggle Referrer"
Copyright (C) 2019 Manuel Reimer <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Fired if the toolbar button is clicked.
// Toggles the referrer setting.
async function ToolbarButtonClicked() {
const value = (await browser.privacy.websites.referrersEnabled.get({})).value;
await browser.privacy.websites.referrersEnabled.set({value: !value});
await UpdateBadge();
}
// Sets browserAction badge text based on referrer status.
async function UpdateBadge() {
const value = (await browser.privacy.websites.referrersEnabled.get({})).value;
const badgetext = value ? "!" : "";
const title = "Referrer (" +
browser.i18n.getMessage(value ? "title_enabled" : "title_disabled") +
")";
if (browser.browserAction.setBadgeText !== undefined) // Not Android
browser.browserAction.setBadgeText({text: badgetext});
browser.browserAction.setTitle({title: title});
UpdateSpoofStatus();
}
// Handles auto disable of referrer
async function DoAutoDisable() {
// If the user enabled referrer res
const prefs = await browser.storage.local.get();
const autodisable = prefs.autodisable || false;
if (autodisable) {
await browser.privacy.websites.referrersEnabled.set({value: false});
await UpdateBadge();
}
}
// Get sure our badge background is red.
if (browser.browserAction.setBadgeBackgroundColor !== undefined) // Not Android
browser.browserAction.setBadgeBackgroundColor({color: "#FF0000"});
// Register event listeners
browser.browserAction.onClicked.addListener(ToolbarButtonClicked);
// Update badge for the first time
UpdateBadge();
// Diable Referrer if the user enabled auto disabling
DoAutoDisable();
IconUpdater.Init("icons/togglereferrer.svg");