/    Sign up×
Community /Pin to ProfileBookmark

Disable script on condition

Good evening, could you help me, please? From this saved (static) page, [page two](https://smartsite.w3spaces.com/page_two.html), I’m running a [script](https://pastebin.com/hhHWqEnc) 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](https://smartsite.w3spaces.com/page_one.html), 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](https://pastebin.com/hhHWqEnc)):

“`
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.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@SempervivumFeb 05.2023 — Did you already check in the developer tools if the entry in local storage is really set? You can find local storage in the tab "application".
Copy linkTweet thisAlerts:
@parvaresauthorFeb 06.2023 — Thanks for the answer. It seems not set infact, isn't it?


https://imgur.com/a/yPNhjgg
Copy linkTweet thisAlerts:
@ceribenanoche12345Feb 06.2023 — See daily results of [ceribenanoche](https://)
Copy linkTweet thisAlerts:
@ceribenanoche12345Feb 06.2023 — See daily results of [ceribenanoche](https://ceribenanoche.com/)
Copy linkTweet thisAlerts:
@KaripsonJackFeb 06.2023 — Thanks for share this informative information for all

again thanks for thid

https://hardshellsuitcase.com/
Copy linkTweet thisAlerts:
@pryinfestedFeb 22.2023 — Have you checked already in the developer tools to make sure that the entry in the local storage is really set? The "application" tab is where you'll discover the "local storage" section.

https://forum.webdeveloper.com/d/402748-i-finally-have-to-ask-the-question-about-nodejs
×

Success!

Help @parvares spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 3.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...