Path: blob/master/sites/bitcoin/clobberlocalstorage.js
777 views
/*1* This file is part of Privacy Badger <https://www.eff.org/privacybadger>2* Copyright (C) 2014 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*/1617/**18* Runs in page content context. Injects a script that deletes cookies.19* Communicates to webrequest.js to get orders if to delete cookies.20*/2122/**23* Insert script into page24*25* @param {String} text The script to insert into the page26*/2728function insertClsScript(text) {29var parent = document.documentElement,30script = document.createElement('script');3132script.text = text;33script.async = false;3435parent.insertBefore(script, parent.firstChild);36parent.removeChild(script);37}3839// END FUNCTION DEFINITIONS ///////////////////////////////////////////////////4041(function () {4243// don't inject into non-HTML documents (such as XML documents)44// but do inject into XHTML documents45if (document instanceof HTMLDocument === false && (46document instanceof XMLDocument === false ||47document.createElement('div') instanceof HTMLDivElement === false48)) {49return;50}5152// TODO race condition; fix waiting on https://crbug.com/47818353chrome.runtime.sendMessage({checkLocation:document.location.href}, function(blocked) {54if (blocked) {55var code =56'('+ function() {57try {58window.localStorage.getItem = function() {59return null;60};61window.localStorage.setItem = function(/*newValue*/) {62//doNothing63};64} catch (ex) {65// ignore exceptions thrown when "Block third-party cookies" is enabled in Chrome66}67} +')()';6869insertClsScript(code);70}71return true;72});7374}());75767778