Good evening, could you help me, please? From this saved (static) page, page two, I’m running a script that extracts, in “Nome” field, the publisher from the bibliographic item (Feltrinelli, in the example). I would like the script to be NOT executed when on the previous page, page one, there is the expression “Editore moderno” (that is the publisher) under the heading “Persone, enti e famiglie”, that is in “fieldset.legami_tito”).
In Page one I tried to set a local variable if the expression “Editore moderno” is found:
var elencoLabel = document.querySelectorAll("span.grid-6");
if (elencoLabel.length > 8)
{
localStorage.removeItem("voce");
if (elencoLabel[8].innerText == "Editore moderno")
{
localStorage.setItem("voce","Editore moderno");
}
}
In Page two I tried with this script (replacing the last line of the script):
function getNome(tmp) {
var idx = tmp.indexOf('. ((');
if(idx > -1){
tmp = tmp.substr(0, idx);
}
tmp = tmp.split('. - ');
switch(tmp.length){
case 3:
tmp = tmp[1];
break;
case 4:
tmp = tmp[2];
break;
default:
tmp = "";
break;
}
if(tmp !== ''){
tmp = tmp.substr(tmp.indexOf(' : ') + 2);
console.log(tmp);
if(tmp.indexOf('.') != -1 && tmp.split('.').length == 2){
tmp = tmp.substr(tmp.indexOf('. ') + 1, tmp.indexOf(', ') -3);
tmp = tmp.trim();
}
else {
tmp = tmp.split(",")[0];
tmp = tmp.trim();
}
}
return tmp;
}
function impostaNome(tmp) {
Array.from(document.querySelectorAll('article section.grid_container form div.grid-row label span')).filter( e => e.innerText.trim() === 'Nome')[0].parentNode.querySelector('input').value = tmp;
}
var elencoLabel = document.querySelectorAll("span.grid-6");
if (elencoLabel.length < 8 )
{
var miaVoce = localStorage.getItem("voce");
if (miaVoce == "Editore moderno")
{
impostaNome(getNome(document.querySelector('div.meta.tito div.evidence.isbd').innerText));
}
}
But with these changes the publisher is never extracted.