Fix wapo.com

This commit is contained in:
Adam 2021-07-04 11:25:12 -07:00
parent 78b75141f3
commit d5b191dc8f

View File

@ -22,7 +22,7 @@ if (matchDomain('elmercurio.com')) {
} else if (matchDomain('repubblica.it')) { } else if (matchDomain('repubblica.it')) {
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
if (document.querySelector('#paywall')) { if (document.querySelector('#paywall')) {
var url = window.location.href.split('?')[0]; const url = window.location.href.split('?')[0];
window.location.href = url + 'amp'; window.location.href = url + 'amp';
} else if (window.location.href.includes('/pwa/')) { } else if (window.location.href.includes('/pwa/')) {
setTimeout(function () { setTimeout(function () {
@ -98,6 +98,13 @@ if (matchDomain('elmercurio.com')) {
document.querySelector('.gdpr-consent-container .consent-page:not(.hide) .continue-btn.button.accept-consent').click(); document.querySelector('.gdpr-consent-container .consent-page:not(.hide) .continue-btn.button.accept-consent').click();
} }
}, 300); // Delay (in milliseconds) }, 300); // Delay (in milliseconds)
} else {
function defaultPaywall (element) {
removeDOMElement(element);
const url = window.location.href;
if (!url.includes('outputType=amp')) { window.location.href = url.split('?')[0] + '?outputType=amp'; }
}
waitDOMElement('div[id^="paywall-"]', 'DIV', defaultPaywall, false);
} }
} else if (matchDomain('wsj.com') && !matchDomain('cn.wsj.com')) { } else if (matchDomain('wsj.com') && !matchDomain('cn.wsj.com')) {
if (window.location.href.includes('/articles/')) { if (window.location.href.includes('/articles/')) {
@ -220,7 +227,7 @@ if (matchDomain('elmercurio.com')) {
decoyArticle.classList.add('decoy-article'); decoyArticle.classList.add('decoy-article');
decoyArticle.hidden = true; decoyArticle.hidden = true;
realArticle.parentElement.insertBefore(decoyArticle, realArticle); realArticle.parentElement.insertBefore(decoyArticle, realArticle);
for (var child = realArticle.firstChild; child !== null; child = child.nextSibling) { for (let child = realArticle.firstChild; child !== null; child = child.nextSibling) {
if (child.style) { if (child.style) {
child.style.display = 'block'; child.style.display = 'block';
} }
@ -688,6 +695,24 @@ function matchDomain (domains) {
return domains.some(domain => hostname === domain || hostname.endsWith('.' + domain)); return domains.some(domain => hostname === domain || hostname.endsWith('.' + domain));
} }
function waitDOMElement (selector, tagName = '', callback, multiple = false) {
new window.MutationObserver(function (mutations) {
for (const mutation of mutations) {
for (const node of mutation.addedNodes) {
if (!tagName || (node.tagName === tagName)) {
if (node.matches(selector)) {
callback(node);
if (!multiple) { this.disconnect(); }
}
}
}
}
}).observe(document, {
subtree: true,
childList: true
});
}
function removeDOMElement (...elements) { function removeDOMElement (...elements) {
for (const element of elements) { for (const element of elements) {
if (element) { element.remove(); } if (element) { element.remove(); }