Fix bloomberg.com (#1060)

This commit is contained in:
Calvin Wu 2020-12-05 20:38:21 -05:00 committed by GitHub
parent 4d50bc78e6
commit ddc315b0ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -174,14 +174,7 @@ if (matchDomain('elmercurio.com')) {
const paywall = document.getElementsByClassName('paywall')[0]; const paywall = document.getElementsByClassName('paywall')[0];
removeDOMElement(paywall); removeDOMElement(paywall);
} else if (matchDomain('bloomberg.com')) { } else if (matchDomain('bloomberg.com')) {
document.addEventListener('DOMContentLoaded', () => { blockElement('#graphics-paywall-overlay', true);
const fence = document.querySelector('.fence-body');
if (fence) {
fence.classList.remove('fence-body');
}
const paywall = document.getElementById('paywall-banner');
removeDOMElement(paywall);
});
} else if (matchDomain('bloombergquint.com')) { } else if (matchDomain('bloombergquint.com')) {
const articlesLeftModal = document.getElementsByClassName('paywall-meter-module__story-paywall-container__1UgCE')[0]; const articlesLeftModal = document.getElementsByClassName('paywall-meter-module__story-paywall-container__1UgCE')[0];
const paywall = document.getElementById('paywallDmp'); const paywall = document.getElementById('paywallDmp');
@ -513,19 +506,21 @@ function pageContains (selector, text) {
}); });
} }
// Prevent element from being added to the DOM // Prevent element from being added the first time to the DOM
function blockElement (selector) { function blockElement (selector, blockAlways = false) {
new window.MutationObserver(function (mutations) { new window.MutationObserver(function (mutations) {
for (const mutation of mutations) { for (const mutation of mutations) {
for (const node of mutation.addedNodes) { for (const node of mutation.addedNodes) {
if (node instanceof window.HTMLElement) { if (node instanceof window.HTMLElement) {
if (node.matches(selector)) { if (node.matches(selector)) {
removeDOMElement(node); removeDOMElement(node);
if (!blockAlways) {
this.disconnect(); // Stop watching for element being added after one removal this.disconnect(); // Stop watching for element being added after one removal
} }
} }
} }
} }
}
}).observe(document, { subtree: true, childList: true }); }).observe(document, { subtree: true, childList: true });
} }