Fix Upstream - NHST (json)

This commit is contained in:
magnolia1234 2024-03-03 15:09:20 +01:00
parent be4a7fde2f
commit e84bcd2814
3 changed files with 82 additions and 2 deletions

View File

@ -14,6 +14,7 @@ Fix Medscape (js)
Fix Project Syndicate (no article)
Fix Telegraaf.nl (timing)
Fix Times of India (epaper)
Fix Upstream - NHST (json)
Maintenance updated sites (removed)
Update custom sites (block_host_perm_add)

View File

@ -2743,7 +2743,7 @@ else if (matchDomain('telegraaf.nl')) {
})
}
article.after(div_main);
}
}
let banners = document.querySelectorAll('.ArticleBodyBlocks__inlineArticleSpotXBanner, .WebpushOptin');
removeDOMElement(...banners);
}
@ -5736,6 +5736,79 @@ else if (matchDomain(no_nhst_media_domains)) {
let blurred = document.querySelector('body > div[style]');
if (blurred)
blurred.removeAttribute('style');
} else if (matchDomain('upstreamonline.com')) {
window.setTimeout(function () {
let paywall = document.querySelector('div.dn-paywall > div#sub-paywall-container');
if (paywall && dompurify_loaded) {
removeDOMElement(paywall.parentNode);
let article = document.querySelector('div#dn-content');
let json_script = document.querySelector('script#__NUXT_DATA__');
if (json_script) {
try {
let pars = JSON.parse(json_script.text);
let article_id_index = pars.indexOf('global-article') + 1;
if (article_id_index) {
let article_id = pars[article_id_index];
if (article_id && !window.location.pathname.endsWith(article_id)) {
refreshCurrentTab();
return;
}
}
article.innerHTML = '';
article.classList.remove('shadow');
let img_first = true;
let parser = new DOMParser();
for (let par of pars) {
let elem;
if (par.type) {
let type = pars[par.type];
if (['text', 'subhead'].includes(type)) {
if (par.html || par.value) {
let index = par.html || par.value;
let json_text = pars[index];
let content_new = parser.parseFromString('<p class="dn-text">' + DOMPurify.sanitize(json_text) + '</p>', 'text/html');
elem = content_new.querySelector('p');
if (par.value)
elem.style = 'font-weight: bold;';
}
} else if (type === 'picture') {
if (img_first)
img_first = false;
else {
elem = document.createElement('figure');
elem.className = 'dn-image';
let img = document.createElement('img');
img.src = pars[par.src];
elem.appendChild(img);
if (par.caption) {
let caption = document.createElement('p');
caption.innerText = pars[par.caption];
if (par.credit)
caption.innerText += ' (' + pars[par.credit] + ')';
elem.appendChild(caption);
}
}
} else if (type === 'news' && par.title && par.url) {
elem = document.createElement('a');
elem.href = pars[par.url];
elem.innerText = 'Related: ' + pars[par.title];
elem.style = 'font-weight: bold;';
} else if (!['ad', 'author', 'break', 'Location', 'news', 'Organisation', 'promobox', 'Person', 'Region', 'Regions', 'related', 'Sectors'].includes(type)) {
for (let item in par) {
console.log(item);
console.log(pars[par[item]]);
}
}
if (elem)
article.appendChild(elem);
}
}
} catch (err) {
console.log(err);
}
}
}
}, 1000);
} else {
let fade = document.querySelector('div[style*="background-image: linear-gradient"]');
if (fade) {

View File

@ -1786,7 +1786,13 @@ var defaultSites = {
"upstreamonline.com"
],
allow_cookies: 1,
block_regex: /subscription-static-global\.nhst\.tech\//
block_regex: /subscription-static-global\.nhst\.tech\//,
exception: [{
domain: "upstreamonline.com",
allow_cookies: 1,
cs_dompurify: 1
}
]
},
"Nikkei Asian Review (do not block Piano.io-script externally)": {
domain: "asia.nikkei.com",