Debian Codegraph @

src/js/contentscripts/dnt.js

raw
1 /*
2 * This file is part of Privacy Badger <https://privacybadger.org/>
3 * Copyright (C) 2018 Electronic Frontier Foundation
4 *
5 * Privacy Badger is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Privacy Badger is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Privacy Badger. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 (function () {
19
20 // don't inject into non-HTML documents (such as XML documents)
21 // but do inject into XHTML documents
22 if (document instanceof HTMLDocument === false && (
23 document instanceof XMLDocument === false ||
24 document.createElement('div') instanceof HTMLDivElement === false
25 )) {
26 return;
27 }
28
29 function getPageScript() {
30
31 // code below is not a content script: no chrome.* APIs /////////////////////
32
33 // return a string
34 return "(" + function () {
35
36 if (window.navigator.doNotTrack != "1") {
37 Object.defineProperty(window.Navigator.prototype, "doNotTrack", {
38 get: function doNotTrack() {
39 return "1";
40 },
41 configurable: true,
42 enumerable: true
43 });
44 }
45
46 if (!window.navigator.globalPrivacyControl) {
47 try {
48 Object.defineProperty(window.Navigator.prototype, "globalPrivacyControl", {
49 get: function globalPrivacyControl() {
50 return true;
51 },
52 configurable: true,
53 enumerable: true
54 });
55 } catch (e) {
56 console.error("Privacy Badger failed to set navigator.globalPrivacyControl, probably because another extension set it in an incompatible way first.");
57 }
58 }
59
60 } + "());";
61
62 // code above is not a content script: no chrome.* APIs /////////////////////
63
64 }
65
66 // END FUNCTION DEFINITIONS ///////////////////////////////////////////////////
67
68 // TODO race condition; fix waiting on https://crbug.com/478183
69 chrome.runtime.sendMessage({
70 type: "checkDNT"
71 }, function (enabled) {
72 if (enabled) {
73 window.injectScript(getPageScript());
74 }
75 });
76
77 }());