Fix The Daily Beast (images)

This commit is contained in:
magnolia1234 2021-08-19 09:03:09 +02:00
parent 0283e6a2db
commit 635bb04e9b
3 changed files with 52 additions and 28 deletions

View File

@ -5,7 +5,7 @@ Post-release
Add Ad Age & Automotive News (& fix group Crain Communications) Add Ad Age & Automotive News (& fix group Crain Communications)
Add MediaNews Group (local USA) Add MediaNews Group (local USA)
Fix group Mediahuis Nederland Regional Fix group Mediahuis Nederland Regional
Fix The Daily Beast (proper) Fix The Daily Beast (proper/images)
* v2.3.3.0 (2021-08-15) * v2.3.3.0 (2021-08-15)
Add Live Law (India) Add Live Law (India)

View File

@ -2521,35 +2521,59 @@ else if (matchDomain('thedailybeast.com')) {
removeDOMElement(paywall); removeDOMElement(paywall);
let json_script = document.querySelector('script[displayName="initialState"]'); let json_script = document.querySelector('script[displayName="initialState"]');
if (json_script) { if (json_script) {
let json_split = json_script.innerText.includes('"sections":') ? json_script.innerText.split('"sections":') : []; let json_str = json_script.text.substring(json_script.textContent.indexOf('{'));
let json_text; try {
if (json_split.length > 1) let json = JSON.parse(json_str);
json_text = json_split[json_split.length - 1].split('},"')[0]; if (json.body) {
if (json_text) { let pars = json.body.sections;
let pars = json_text.split('"').filter(function (value) { let cards = json.body.cards;
return (value.split('[').length < 3 && value.split(']').length < 3); if (pars) {
}); let mobile_doc = document.querySelector('div.Mobiledoc');
let mobile_doc = document.querySelector('div.Mobiledoc'); if (mobile_doc) {
if (mobile_doc) { let mobile_doc_text = mobile_doc.innerText.replace(/(\r|\n)/g, '');
let mobile_doc_text = mobile_doc.innerText.replace(/(\r|\n)/g, ''); for (let elem of pars) {
let par, par_elem; let par_elem = '';
for (let elem of pars) { if (elem[0] === 1) {
if (elem === 'p') { if (elem[1] === 'p') {
if (par && !mobile_doc_text.includes(par)) { let par = '';
par_elem = document.createElement('p'); for (let part of elem[2])
par_elem.innerText = par; par += part[3];
mobile_doc.appendChild(par_elem); if (par && !mobile_doc_text.includes(par)) {
par_elem = document.createElement('p');
par_elem.innerText = par;
}
}
} else if (elem[0] === 10) {
if (cards && cards[elem[1]]) {
let card = cards[elem[1]];
if (card[0] === 'pt-image') {
par_elem = document.createElement('p');
let par_fig = document.createElement('figure');
let par_img = document.createElement('img');
par_img.src = card[1].url;
par_fig.appendChild(par_img);
par_elem.appendChild(par_fig);
let par_cap = document.createElement('figcaption');
par_cap.innerText = card[1].title + ' ' + card[1].credit;
par_elem.appendChild(par_cap);
} else if (card[0] === 'pt-fancy-links-card') {
par_elem = document.createElement('p');
let par_link = document.createElement('a');
par_link.href = card[1].links;
par_link.innerText = card[1].linksData[0].long_headline;
par_elem.appendChild(par_link);
}
}
}
if (par_elem)
mobile_doc.appendChild(par_elem);
} }
par = ''; }
} else
par += elem;
}
if (par && !mobile_doc_text.includes(par)) {
par_elem = document.createElement('p');
par_elem.innerText = par;
mobile_doc.appendChild(par_elem);
} }
} }
csDoneOnce = true;
} catch (err) {
console.log(err);
} }
} }
} }

View File

@ -553,5 +553,5 @@
"*://*.wallkit.net/*", "*://*.wallkit.net/*",
"*://*.wsj.net/*" "*://*.wsj.net/*"
], ],
"version": "2.3.3.4" "version": "2.3.3.5"
} }