Hi, i have saved two protected page, page1 and page2. I would like to set “R.D.” on field “Sezione” (selector #cdSezi) of page2 if page1 contains the string “Letteratura per ragazzi” beside “Generi”. Otherwise if page one (see here) doesn’t contain “Letteratura per ragazzi” beside “Generi” then field “Sezione” should be set to “A”.
I tried this userscript, but it gives me always “R.D.” on field “Sezione” of page2, even when the string “Letteratura per ragazzi” is not present in page1. Thanks very much!
In your userscript, there is no mechanism for clearing localstorage. Could this be why once the string “Letteratura per ragazzi” is present in page1, you will always get “R.D.” on page2?
if (conditionElement && conditionElement.textContent.trim() === "Letteratura per ragazzi") {
// As before
} else {
// Add this
localStorage.removeItem("cdSeziValue");
}
Yes, maybe the problem is the local storage, if I delete data on browser after “R.D.” has been set, then it sets correctly #cdSezi to “A.” if the string “Letteratura per ragazzi” is missing. I tried your suggestion, but with your modifications it gives me always “A.”. Do you mean this?
if (conditionElement && conditionElement.textContent.trim() === "Letteratura per ragazzi") {
// Set the value in local storage only if the condition is met
localStorage.setItem("cdSeziValue", "R.D.");
cdSeziValue = "R.D.";
} else {
// Set cdSeziValue to "A." if the condition is not met
localStorage.removeItem("cdSeziValue");
cdSeziValue = "A.";
}
Yeah, that’s what I meant. If it’s not working, I would remove some of the pieces and simplify the problem. For example on page1 have your userscript pop up an alert depending on whether the initial value is present. Once that is working, have it save something to local storage (e.g. true or false) depending on the presence of the value. Once the correct value is being saved to local storage, move on to page2…
With this script the pop-up alert correctly opens when there is the string “Letteratura per ragazzi” and doesn’t when it’s not present… Now I don’t know how to go on…
if (conditionElement && conditionElement.textContent.trim() === "Letteratura per ragazzi") {
// Set the value in local storage only if the condition is met
localStorage.setItem("cdSeziValue", "R.D.");
cdSeziValue = "R.D.";
// Pop up an alert if the condition is met
alert("Condition 'Letteratura per ragazzi' is met!");
} else {
// Set cdSeziValue to "A." if the condition is not met
localStorage.removeItem("cdSeziValue");
cdSeziValue = "A.";
Page1 and page2 have the same URL. In page1, for example, there is always the string “Risorsa”, in page2 the string “Inserimento nuovo inventario collocato”, if this is the question…
I don’t know how to identify pageOne and pageTwo, but I think this would be the right way. Infact if “Lettereatura per ragazzi” is present in pageOne I get correctly on console:
Condition Element: null
cdSeziValue: A.
Stored cdSeziValue: null
So since the element with selector #cdGenerePbb1 > span.no-grid does not exist on the pageTwo, conditionElement will be null, leading incorrectly to the “A.” value, even if “Lettereatura per ragazzi” is present in pageOne.