Fix Telegraaf.nl (images)

This commit is contained in:
magnolia1234 2023-06-29 15:41:00 +02:00
parent b2c44d8200
commit a7b7eed217
2 changed files with 89 additions and 26 deletions

View file

@ -8,6 +8,7 @@ Add Zeit.de (link to archive.is)
Remove LePoint.fr (fix obsolete)
Fix Beobachter.ch & Handelszeitung.ch
Fix Foreign Policy (Insider)
Fix Telegraaf.nl (images)
* v3.2.2.0 (2023-06-25)
Add Follow the Money (Ftm.eu)

View file

@ -176,7 +176,6 @@ if (bg2csData.add_ext_link) {
article.firstChild.before(ext_12ftLink(url));
break;
}
}
}
}, 1000);
@ -2411,7 +2410,75 @@ else if (matchDomain('telegraaf.nl')) {
}, 500);
}
let paywall = document.querySelector('div.MeteringNotification__backdrop, data-hydrate[data-name="SubscriptionCard"]');
if (paywall) {
let article_body = document.querySelector('section.TextArticlePage__imageWrapper, section > div.DetailArticleImage');
if (paywall && article_body) {
let div_main = document.createElement('div');
div_main.style = 'margin: 20px 0px;';
let div_elem = document.createElement('div');
let par_style = 'font-weight: normal; font-size: 16px; line-height: 1.5;';
let scripts = document.querySelectorAll('script:not([src], [type])');
let apollo_script;
for (let script of scripts) {
if (script.text.includes('window.__APOLLO_STATE__=')) {
apollo_script = script;
break;
}
}
if (apollo_script) {
removeDOMElement(paywall);
try {
let apollo_json = JSON.parse(apollo_script.text.replace(/(^window.__APOLLO_STATE__=|;$)/g, ''));
let start = false;
for (let key in apollo_json) {
let elem = apollo_json[key];
if (!start) {
if (key.includes('.introBlocks.'))
start = true;
} else {
let typename = elem.__typename;
if (key.startsWith('Article:') || ['ArticleAuthorBiography'].includes(typename))
break;
else {
let par = document.createElement('p');
if (typename === 'HtmlBlock') {
let item = document.createElement('p');
item.innerText = elem.contentHTML.replace(/((<|\\u003c)([^>]+)(>|\\u003e))/gi, '');
item.style = par_style;
par.appendChild(item);
} else if (typename === 'SubheadBlock') {
let item = document.createElement('p');
item.innerText = elem.text.replace(/((<|\\u003c)([^>]+)(>|\\u003e))/gi, '');
item.style = par_style;
par.appendChild(item);
} else if (typename === 'Image') {
let figure = document.createElement('figure');
let img = document.createElement('img');
img.src = elem.url.startsWith('https:') ? elem.url : 'https:' + elem.url;
img.width = !mobile ? 640 : 320;
figure.appendChild(img);
if (elem.description) {
let caption = document.createElement('figcaption');
caption.innerText = elem.description + (elem.copyright ? ' | ' + elem.copyright : '');
figure.appendChild(caption);
}
par.appendChild(figure);
} else if (typename === 'Article') {
let item = document.createElement('a');
item.href = elem.url.startsWith('https:') ? elem.url : 'https:' + elem.url;
item.innerText = elem.title;
par.appendChild(item);
} else if (!['ImageBlock', 'InlineRelatedArticlesBlock', 'Video', 'Webshop'].includes(typename))
console.log(elem);
if (par.childNodes) {
div_main.appendChild(par); ;
}
}
}
}
} catch (err) {
console.log(err);
}
} else {
let json_script = getArticleJsonScript();
if (json_script) {
removeDOMElement(paywall);
@ -2423,21 +2490,14 @@ else if (matchDomain('telegraaf.nl')) {
let intro = document.querySelector('span[id^="articleIntro"], p.Article__intro > span');
if (intro)
json_text = json_text.replace(intro.innerText + '\n\n', '');
let article_body = document.querySelector('section.TextArticlePage__imageWrapper, section > div.DetailArticleImage');
if (article_body) {
let div_main = document.createElement('div');
div_main.style = 'margin: 20px 0px;';
let div_elem = document.createElement('div');
let text_array = json_text.split('\\n');
text_array.forEach(p_text => {
let p_div = document.createElement('p');
p_div.innerText = p_text;
p_div.style = 'font-weight: normal; font-size: 16px; line-height: 1.5;';
p_div.style = par_style;
div_elem.appendChild(p_div);
});
div_main.appendChild(div_elem);
article_body.after(div_main);
}
}
}
} catch (err) {
@ -2445,8 +2505,10 @@ else if (matchDomain('telegraaf.nl')) {
}
}
}
article_body.after(div_main);
}
let banners = document.querySelectorAll('.ArticleBodyBlocks__inlineArticleSpotXBanner, .WebpushOptin');
removeDOMElement(paywall, ...banners);
removeDOMElement(...banners);
}
else if (matchDomain('vn.nl')) {