summaryrefslogtreecommitdiffstats
path: root/src/js/contentscripts/collapser.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 16:55:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 16:55:34 +0000
commit75417f5e3d32645859d94cec82255dc130ec4a2e (patch)
tree5fd46925c6b4a881c9208772ed8e5cc0588bc164 /src/js/contentscripts/collapser.js
parentInitial commit. (diff)
downloadprivacybadger-upstream/2020.10.7.tar.xz
privacybadger-upstream/2020.10.7.zip
Adding upstream version 2020.10.7.upstream/2020.10.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/js/contentscripts/collapser.js')
-rw-r--r--src/js/contentscripts/collapser.js56
1 files changed, 56 insertions, 0 deletions
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 <https://www.eff.org/privacybadger>
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+(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);
+ }
+});
+
+}());