From e06e3117ec415c19565bfd0e2a696279026cda31 Mon Sep 17 00:00:00 2001 From: magnolia1234 <7676006-magnolia1234@users.noreply.gitlab.com> Date: Mon, 25 Apr 2022 18:09:43 +0200 Subject: [PATCH] Fix Lequipe.fr (json) --- changelog.txt | 1 + contentScript.js | 77 ++++++++++++++++++------------------------------ manifest.json | 2 +- 3 files changed, 30 insertions(+), 50 deletions(-) diff --git a/changelog.txt b/changelog.txt index 497f1f71..f366f4e3 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ Changelog Bypass Paywalls Clean - Firefox Post-release +Fix Lequipe.fr (json) * v2.6.6.0 (2022-04-24) Add Automobilwoche diff --git a/contentScript.js b/contentScript.js index e29d3e80..75bd21c2 100644 --- a/contentScript.js +++ b/contentScript.js @@ -1390,65 +1390,44 @@ else if (matchDomain('lequipe.fr')) { let json = json_script.textContent.split('articleObject:')[1].split(',articleType')[0]; let url_nuxt = json_script.textContent.split('comment_count_url:"')[1].split('",')[0].replace(/\\u002F/g, '/'); if (url_nuxt && !url_nuxt.includes(window.location.pathname)) - ext_api.runtime.sendMessage({request: 'refreshCurrentTab'}); - let par_type = json.split('paragraphs:[')[1].split(',{__type:')[1].split(',')[0]; - if (par_type) { + window.setTimeout(function () { + ext_api.runtime.sendMessage({request: 'refreshCurrentTab'}); + }, 500); + json = json.replace(/keywords:\[([\w\,\$]+)\]/g, "keywords:\"\"").replace(/([{,])([a-zA-Z_]+\d?):/g, "$1\"$2\":").replace(/\":(\[)?([\w\$\.]+)([\]},])/g, "\":$1\"$2\"$3").replace(/},([\w]+),{/g, "},\"$1\",{"); + json = JSON.parse(json); + if (json.items) { + let pars = json.items.filter(x => x.objet && x.objet.paragraphs)[0].objet.paragraphs; article.innerHTML = ''; - let json_split = json.split('__type:' + par_type); - json_split.shift(); let article_dom; let article_text = ''; let parser = new DOMParser(); - let par_main_title = ''; - for (let par_main of json_split) { - if (par_main.includes(',content:')) { - let pars; - if (par_main.split(',content:"').filter(x => !x.startsWith('\\')).length > 2) { - if (par_main.startsWith(',title:')) { - par_main_title = par_main.split(',title:')[1].split(',')[0].replace(/(^\"|\"$)/g, ''); - article_text += '

' + par_main_title + '

'; - } - par_type = json.split('content:')[1].split('"},{__type:')[1].split(',')[0]; - pars = par_main.split('__type:' + par_type); - } else { - pars = [par_main]; + for (let par of pars) { + if (par.title || par.content) { + if (par.title && par.title.length > 2) + article_text += '

' + par.title + '

'; + if (par.content) { + let par_content = par.content.replace('class=', '').replace(/\\u003C/g, '<').replace(/\\u003E/g, '>').replace(/\\u002F/g, '/').replace(/\\"/g, '"').replace(/(^\"|\"$)/g, '').replace(/\\t/g, ''); + article_text += '

' + par_content + '

'; } - for (let par of pars) { - par = par.split('}')[0]; - if (par.includes(',content:')) { - let content = par.split(',content:"')[1].split('",')[0]; - let par_title = ''; - if (par.includes(',title:')) - par_title = par.split(',title:')[1].split(',')[0].replace(/(^\"|\"$)/g, ''); - if (content) { - par = content.replace('class=', ''); - if (par_title.length > 2 && par_title !== par_main_title) - par = '' + par_title + '

' + content; - par = par.replace(/\\u003C/g, '<').replace(/\\u003E/g, '>').replace(/\\u002F/g, '/').replace(/\\"/g, '"').replace(/(^\"|\"$)/g, '').replace(/\\t/g, ''); - article_text += '

' + par + '

'; - } - } - } - } - par_main = par_main.split('}]')[0]; - if (par_main.includes(',media:')) { - let media = par_main.split(',media:')[1].split('}}')[0] + '}'; - if (media.includes('ratio:')) { - let ratio = media.split('ratio:')[1].split(',')[0].split('}')[0]; - if (!parseInt(ratio)) - ratio = 1.5; - let url = media.split('url:"')[1].split('"')[0].replace(/\\u002F/g, '/').replace('{width}', '400').replace('{height}', parseInt(400 / ratio)).replace('{quality}', '75'); - if (url) - article_text += '

'; - } - } + } else if (par.media && par.media.url && par.media.ratio) { + let ratio = par.media.ratio; + if (!parseInt(ratio)) + ratio = 1.5; + let url = par.media.url.replace(/\\u002F/g, '/').replace('{width}', '400').replace('{height}', parseInt(400 / ratio)).replace('{quality}', '75'); + article_text += '

'; + if (par.media.legende && par.media.legende.length > 2) + article_text += '

' + par.media.legende + '

'; + } else if (par.__type && !par.layout) + console.log(par); } article_dom = parser.parseFromString('
' + DOMPurify.sanitize(article_text) + '
', 'text/html'); article.appendChild(article_dom.querySelector('div')); } } else - ext_api.runtime.sendMessage({request: 'refreshCurrentTab'}); - } + window.setTimeout(function () { + ext_api.runtime.sendMessage({request: 'refreshCurrentTab'}); + }, 500); + } } } diff --git a/manifest.json b/manifest.json index 490466ff..36d3561d 100644 --- a/manifest.json +++ b/manifest.json @@ -673,5 +673,5 @@ "*://*.wsj.net/*", "*://webcache.googleusercontent.com/*" ], - "version": "2.6.6.0" + "version": "2.6.6.1" }