Improved: HTML filter (#257)
This commit is contained in:
parent
fba55c215b
commit
e597707eae
|
@ -73,10 +73,11 @@ manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) {
|
|||
encoder = new TextEncoder();
|
||||
isFirstData = true;
|
||||
filter = browser.webRequest.filterResponseData(details.requestId);
|
||||
let data = [];
|
||||
|
||||
header.value = 'text/html; charset=UTF-8';
|
||||
|
||||
//Note that this will not work if the '<script crossorigin="anonymous" src="dfgsfgd.com">' string is divided into two chunks, but we want to flush this data asap.
|
||||
// Note that should work if the '<script crossorigin="anonymous" src="dfgsfgd.com">' string is divided into two chunks.
|
||||
filter.ondata = evt => {
|
||||
if (isFirstData) {
|
||||
if (!charset) {
|
||||
|
@ -87,20 +88,26 @@ manipulateDOM._removeCrossOriginAndIntegrityAttr = function (details) {
|
|||
}
|
||||
decoder = new TextDecoder(charset);
|
||||
}
|
||||
isFirstData = false;
|
||||
|
||||
data.push(evt.data);
|
||||
}
|
||||
|
||||
filter.onstop = evt => {
|
||||
let str = '';
|
||||
for (let buffer of data) {
|
||||
str += decoder.decode(buffer, {stream: true});
|
||||
}
|
||||
str += decoder.decode(); // end-of-stream
|
||||
|
||||
//remove crossorigin and integrity attributes
|
||||
let str = decoder.decode(evt.data, {stream: true}).replace(/<(link|script)[^>]+>/ig, m => {
|
||||
str = str.replace(/<(link|script)[^>]+>/ig, m => {
|
||||
if (cdnDomainsRE.test(m)) {
|
||||
return m.replace(/\s+(integrity|crossorigin)(="[^"]*"|='[^']*'|=[^"'`=>\s]+|)/ig, '');
|
||||
}
|
||||
return m;
|
||||
});
|
||||
filter.write(encoder.encode(str));
|
||||
isFirstData = false;
|
||||
}
|
||||
|
||||
filter.onstop = evt => {
|
||||
let str = decoder.decode(); //end-of-stream
|
||||
filter.write(encoder.encode(str));
|
||||
filter.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
<li>Updated: ember.js v3.24.0 -> v3.24.1 (<a href="https://codeberg.org/nobody/LocalCDN/issues/251">#251</a>)</li>
|
||||
<li>Updated: instantsearch.js v4.12.0 -> v4.13.1 (<a href="https://codeberg.org/nobody/LocalCDN/issues/252">#252</a>)</li>
|
||||
<li>Added: Missing resources for Highlight.js (<a href="https://codeberg.org/nobody/LocalCDN/issues/253">#253</a>)</li>
|
||||
<li>Improved: HTML filter (<a href="https://codeberg.org/nobody/LocalCDN/issues/257">#257</a>)</li>
|
||||
</ul>
|
||||
<div id="generator-section">
|
||||
<div class="topic-label">
|
||||
|
|
Loading…
Reference in New Issue