| 1 |
/* |
| 2 |
* This file is part of Privacy Badger <https://privacybadger.org/> |
| 3 |
* Copyright (C) 2020 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 hideFrame(url) { |
| 30 |
let sel = "iframe[src='" + CSS.escape(url) + "']"; |
| 31 |
let el = document.querySelector(sel); |
| 32 |
if (el) { // el could have gotten replaced since the lookup |
| 33 |
el.style.setProperty("display", "none", "important"); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { |
| 38 |
if (request.hideFrame) { |
| 39 |
hideFrame(request.url); |
| 40 |
sendResponse(true); |
| 41 |
} |
| 42 |
}); |
| 43 |
|
| 44 |
// check the page for any frames that were blocked before we got here |
| 45 |
chrome.runtime.sendMessage({ |
| 46 |
type: "getBlockedFrameUrls" |
| 47 |
}, function (frameUrls) { |
| 48 |
if (!frameUrls) { |
| 49 |
return; |
| 50 |
} |
| 51 |
for (let url of frameUrls) { |
| 52 |
hideFrame(url); |
| 53 |
} |
| 54 |
}); |
| 55 |
|
| 56 |
}()); |