From 8d13bdc6cac0e20c43c6f909fc0208774b9c5c84 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 21:47:39 +0200 Subject: Adding upstream version 2020.10.7. Signed-off-by: Daniel Baumann --- src/js/contentscripts/collapser.js | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/js/contentscripts/collapser.js (limited to 'src/js/contentscripts/collapser.js') diff --git a/src/js/contentscripts/collapser.js b/src/js/contentscripts/collapser.js new file mode 100644 index 0000000..968905c --- /dev/null +++ b/src/js/contentscripts/collapser.js @@ -0,0 +1,56 @@ +/* + * This file is part of Privacy Badger + * Copyright (C) 2020 Electronic Frontier Foundation + * + * Privacy Badger is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * Privacy Badger 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 Privacy Badger. If not, see . + */ + +(function () { + +// don't inject into non-HTML documents (such as XML documents) +// but do inject into XHTML documents +if (document instanceof HTMLDocument === false && ( + document instanceof XMLDocument === false || + document.createElement('div') instanceof HTMLDivElement === false +)) { + return; +} + +function hideFrame(url) { + let sel = "iframe[src='" + CSS.escape(url) + "']"; + let el = document.querySelector(sel); + if (el) { // el could have gotten replaced since the lookup + el.style.setProperty("display", "none", "important"); + } +} + +chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) { + if (request.hideFrame) { + hideFrame(request.url); + sendResponse(true); + } +}); + +// check the page for any frames that were blocked before we got here +chrome.runtime.sendMessage({ + type: "getBlockedFrameUrls" +}, function (frameUrls) { + if (!frameUrls) { + return; + } + for (let url of frameUrls) { + hideFrame(url); + } +}); + +}()); -- cgit v1.2.3