hello,
i would like the read lemonde.fr into a page.
i've done a javascript that works well (I use to launch it into firefox)
how can I launch this script into my kobo forma (via KOREADER ? calibre ?) ?
Quote:
javascript:
async function ledebut()
{
le_monde_du_jour = "Le Monde";
texte = '<html><head><meta charset="UTF-8"></head>\n<body>\n<div style="font-size: 42"><a name="debut">'+le_monde_du_jour+'</a></div>\n';
texte += "<style>\n
.alb-article-title { font-size:2.11em; font-weight: bold; }\n
.alb-article-author { color: #a2a9ae; font-size: 1em; }\n
.alb-article-introduction { color: #16212c; font-size: 1.294em; }\n
.alb-article-subtitle .rubrique .TeleLMQ .Nomdufilm
{ color: #026b9c; text-transform: uppercase; font-size: 1.3em; margin: 5px 0 10px; }\n
.alb-slide-img-capture { color: #a2a9ae; font-size: .89em; margin-top: 8px; margin-bottom: 0; }\n
.fenetre { background-color: #eef1f5; padding: 20px; }
.LieuActuLMQ { color: #16212c; text-transform: uppercase; }
.Texteuneliresuite { color: #8b9299; font-size: .7em; letter-spacing: 0; text-transform: uppercase; }
</style>\n";
articles = new Object();
/* premier clic */
await attendre_selector_et_cliquer('.p1 > div:nth-child(3) > div:nth-child(1)');
/* articles présents */
do
{
div_articles = document.querySelector('.swiper-wrapper-alb').children;
for (i=0; i<div_articles.length; i++)
{
id = div_articles[i].dataset.sliden+"_"+div_articles[i].dataset.pagen+"_"+div_articles[i].dataset.articlen;
articles[id] = div_articles[i];
console.log(id);
}
await attendre_selector_et_cliquer('.alb-nav-next');
}
while( ! document.querySelector(".alb-nav-next").classList.contains("inactive"));
count = 0;
/* index */
page = -1;
for (var key in articles)
{
lpage = parseInt(articles[key].dataset.sliden) * 2 + parseInt(articles[key].dataset.pagen);
if (page != lpage)
{
texte += '<div style="font-size: 30"><a name="Ipage_'+lpage+'" href="#page_'+lpage+'">PAGE '+lpage+"</a></div>\n";
page = lpage;
}
texte += '<div style="font-size: 16"><a href="#article_'+key+'">'+getTitre(articles[key])+"</a></div>\n";
count++;
}
console.log("on a "+count+" articles");
/* articles */
page = -1;
image_number = 0;
for (var key in articles)
{
lpage = parseInt(articles[key].dataset.sliden) * 2 + parseInt(articles[key].dataset.pagen);
if (page != lpage)
{
texte += '<h1 style="font-size: 30"><a name="page_'+lpage+'" href="#Ipage_'+lpage+'">PAGE '+lpage+"</a></h1>\n";
page = lpage;
}
texte += '<div><a name="article_'+key+'" href="#debut">'+le_monde_du_jour+'</a></div>';
texte += articles[key].outerHTML+"\n";
}
texte = texte.replaceAll(' style="height: 250px;"', "");
texte = texte.replaceAll(' style="width: 514px;"', "");
texte = texte.replaceAll(' style="height: 0px;"', "");
texte = texte.replaceAll('src="//lmo-lmo-production-api', 'src="https://lmo-lmo-production-api');
texte += '</body></html>\n';
/* téléchargement */
download_DATA_to_file(texte, 'pages.htm');
}
function getTitre(htmlelement)
{
subtitle = getTextFromClasse(htmlelement, "alb-article-subtitle");
title = getTextFromClasse(htmlelement, "alb-article-title");
principal = getTextFromClasse(htmlelement, "principal-titre");
cabochon = getTextFromClasse(htmlelement, "cabochon");
Cle_titre = getTextFromClasse(htmlelement, "Clé-titre");
Breve_surtitre = getTextFromClasse(htmlelement, "Brève-surtitre");
Breve_titre = getTextFromClasse(htmlelement, "Brève-titre");
Appui_surtitre = getTextFromClasse(htmlelement, "Appui-surtitre");
return principal+" "+subtitle+" "+title+" "+cabochon+" "+Cle_titre+" "+Breve_surtitre+" "+Breve_titre+" "+Appui_surtitre;
}
function getTextFromClasse(htmlelement, classe)
{
text = "";
textes = htmlelement.getElementsByClassName(classe);
if (textes.length > 0)
{
for (j=0; j<textes.length; j++)
{
text += textes[j].innerText+" ";
}
}
return text;
}
async function download_DATA_to_file(data, file)
{
var a = document.createElement('a');
a.download = file;
a.href = "data:application/octet-stream,"+encodeURIComponent(data);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
delete a;
}
async function attendre_selector_et_cliquer(sel)
{
/*console.log("attendre_selector "+sel);*/
while ( ! document.querySelector(sel))
{
await sleep(10);
}
/*console.log("clic "+sel);*/
document.querySelector(sel).click();
await sleep(100);
}
function sleep(ms)
{
/*console.log("sleep "+ms+"ms");*/
return new Promise(resolve =>
{
setTimeout(() =>
{
resolve('resolved');
}, ms);
});
}
ledebut();
|