Hi, from page 1 (copied, the original is protected) this userscript extracts the publisher, but I would like the script not to be executed on page 2, which has same URL but differs from page 1 only in the addition of a section/banner.
Thank you!
Hi, from page 1 (copied, the original is protected) this userscript extracts the publisher, but I would like the script not to be executed on page 2, which has same URL but differs from page 1 only in the addition of a section/banner.
Thank you!
The text is contained in a li element, right?
So you can grab all the li elements, then use Array.prototype.some
to test whether at least one element in the array contains that text.
const lis = document.querySelectorAll('li');
const textFound = Array.from(lis).some(li => li.textContent.includes("La ricerca in polo e in indice non ha prodotto risultati"));
if (!textFound) {
// Run script
}
HTH
Whether this is appropriate or overkill in this instance I don’t know, but import() sprung to mind. The function allows for conditionally importing modules.
Thank you, James_Hibbard, the extra text included in page 2 (where the script should not run) is contained in a li
element. Unfortunally the script still runs on the other page. I even tried this, but the result is the same:
const excludedSection = document.querySelector('section.messages.warnings');
if (!excludedSection) {
// Call the functions to extract "Nome" value and set it in the input field
impostaNome(getNome(document.querySelector('div.meta.tito div.evidence.isbd').innerText));
}
Thanks, rpg_digital, it seems a bit complex.
I guess we are back to this thing of the real page being slightly different than the copied page.
This is what happens for me:
pagina_1
pagina_2
I’m sorry, I forgot that it’s an inherent behavior of the software, not of the userscript. So I simply added this userscript on page 2. Thanks again, James_Hibbard and rpg_digital, and sorry again!
var section = document.querySelector('section.messages.warnings');
if (section) {
var field = document.getElementById('ds');
if (field) {
field.value = '';
}
}
So you got it working?
If so, would you mind posting the code? (I’m just curious)
James_Hibbard, Certainly. I leaved the userscript as it was in Page 1 and added last userscript in Page 2, that’s it.
Ah ok. So you have different userscripts for different pages?
Yes, exactly.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.