I have two different scripts. At the end of one, it opens a new web page that starts the other script then waits for that script to set a value to true to allow the first script to open another page.
This is the script for the function called at the end of the first script. It waits for the flag value, continueValue, to be set to true. The console displays the "checking flag" message over and over implying the other script isn't changing the value to true.
function checkFlag() {
console.log("Checking flag");
if(GM_getValue("continueValue") === false) {
window.setTimeout(checkFlag, 2000); /* this checks the flag every 3000 milliseconds*/
} else {
//--- Opens the next cove
if (!(currentCoveNum = -1)) {
window.open(coveLinks[currentCoveNum + 1],"_self");
}
}
}
At the end of the next script the following code is performed:
//--- If the text "Next Creature" exists on the page, click next creature button
if ((document.documentElement.textContent || document.documentElement.innerText).indexOf('Next Creature') > -1) {
window.location.href = nextCreatureLink[0].href;
//--- Otherwise set the continue value to true to allow Super Auto Feed, Open Coves to open the next cove
} else {
GM_setValue("continueValue", true);
console.log("continueValue is "+GM_getValue("continueValue"));
setTimeout(function() {
window.close();
}, (2 * 1000));
}
The issue is when this script reaches the message "continueValue is " it displays true, implying that the other script should open the next page, but it doesn't. It just keeps checking for the flag to become true.
I am wondering maybe getValue and setValue don't work between scripts? Or maybe something with the loop of checking for the flag to become true is wrong.
If someone could enlighten me as to where my script is wrong I would be extremely greatful.
GM_setValue and GM_getValue do run cross tab or window within the same script, but they do not run cross script. Thus when the value is set in on script it doesn't change the value for the other script.
Try local storage or storage in an external database.