From f5a17653c51c54209f54a81c65707f30980fd7f6 Mon Sep 17 00:00:00 2001
From: nobody42 <5514211-nobody42@users.noreply.gitlab.com>
Date: Sat, 2 May 2020 13:56:49 +0200
Subject: [PATCH] Error in encoding fixed (#66)
---
core/constants.js | 3 +-
core/manipulate-dom.js | 97 ++++++++++++++++++++++++++++++++
core/state-manager.js | 53 -----------------
pages/background/background.html | 1 +
pages/updates/updates.html | 1 +
5 files changed, 101 insertions(+), 54 deletions(-)
create mode 100644 core/manipulate-dom.js
diff --git a/core/constants.js b/core/constants.js
index 1d07e9ac..756a5950 100644
--- a/core/constants.js
+++ b/core/constants.js
@@ -90,5 +90,6 @@ const Whitelist = {
};
const BrowserType = {
- 'CHROMIUM': chrome.runtime.getURL("/").startsWith("chrome-extension")
+ 'CHROMIUM': chrome.runtime.getURL("/").startsWith("chrome-extension"),
+ 'FIREFOX': chrome.runtime.getURL("/").startsWith("moz-extension")
}
diff --git a/core/manipulate-dom.js b/core/manipulate-dom.js
new file mode 100644
index 00000000..c41e5018
--- /dev/null
+++ b/core/manipulate-dom.js
@@ -0,0 +1,97 @@
+/**
+ * Remove integrity checks from embedded CSS and JavaScript files
+ * Belongs to LocalCDN.
+ *
+ * @author nobody42
+ * @since 2020-02-27
+ *
+ * @license MPL 2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+'use strict';
+
+
+/**
+ * Manipulate DOM
+ */
+
+var manipulateDOM = {};
+
+
+/**
+ * Private Methods
+ */
+
+manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) {
+
+ // by Jaap (https://gitlab.com/Jaaap)
+ // https://gitlab.com/nobody42/localcdn/-/issues/66
+ let header = details.responseHeaders.find(h => h.name.toLowerCase() === 'content-type');
+
+ if (header && BrowserType.FIREFOX) {
+
+ let mimeType, charset, initiatorDomain, isWhitelisted;
+
+ mimeType = header.value.replace(/;.*/, '').toLowerCase();
+ charset = /charset\s*=/.test(header.value) ? header.value.replace(/^.*?charset\s*=\s*/, '') : 'UTF-8';
+ initiatorDomain = helpers.extractDomainFromUrl(details.url, true) || Address.EXAMPLE;
+ isWhitelisted = stateManager._domainIsWhitelisted(initiatorDomain);
+
+ if (!isWhitelisted && mimeType === 'text/html') {
+
+ header.value = 'text/html; charset=UTF-8';
+ let decoder = new TextDecoder(charset);
+ let encoder = new TextEncoder();
+ let filter = browser.webRequest.filterResponseData(details.requestId);
+
+ //Note that this will not work if the '
+