/*1* This file is part of Privacy Badger <https://www.eff.org/privacybadger>2* Copyright (C) 2018 Electronic Frontier Foundation3*4* Privacy Badger is free software: you can redistribute it and/or modify5* it under the terms of the GNU General Public License version 3 as6* published by the Free Software Foundation.7*8* Privacy Badger is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11* GNU General Public License for more details.12*13* You should have received a copy of the GNU General Public License14* along with Privacy Badger. If not, see <http://www.gnu.org/licenses/>.15*/1617function getPageScript() {1819// code below is not a content script: no chrome.* APIs /////////////////////2021// return a string22return "(" + function (NAVIGATOR, OBJECT) {2324OBJECT.defineProperty(OBJECT.getPrototypeOf(NAVIGATOR), "doNotTrack", {25get: () => {26return "1";27}28});2930// save locally to keep from getting overwritten by site code31} + "(window.navigator, Object));";3233// code above is not a content script: no chrome.* APIs /////////////////////3435}3637/**38* Executes a script in the page DOM context39*/40function insertPageScript(text) {41var parent = document.documentElement,42script = document.createElement('script');4344script.text = text;45script.async = false;4647parent.insertBefore(script, parent.firstChild);48parent.removeChild(script);49}5051// END FUNCTION DEFINITIONS ///////////////////////////////////////////////////5253(function () {5455// don't inject into non-HTML documents (such as XML documents)56// but do inject into XHTML documents57if (document instanceof HTMLDocument === false && (58document instanceof XMLDocument === false ||59document.createElement('div') instanceof HTMLDivElement === false60)) {61return;62}6364// TODO race condition; fix waiting on https://crbug.com/47818365chrome.runtime.sendMessage({66checkEnabled: true67}, function (enabled) {68if (enabled) {69insertPageScript(getPageScript());70}71});7273}());747576