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