我有两个不同的剧本。在一个脚本的末尾,它打开一个新的web页面,该页面启动另一个脚本,然后等待该脚本将一个值设置为true,以允许第一个脚本打开另一个页面。
这是在第一个脚本末尾调用的函数的脚本。它等待将标志值continueValue设置为true。控制台一次又一次地显示“检查标志”消息,这意味着其他脚本没有将值更改为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");
}
}
}在下一个脚本的末尾执行以下代码:
//--- 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));
}问题是当这个脚本到达消息"continueValue is“时,它显示为true,这意味着其他脚本应该打开下一页,但它没有打开,它只是不断地检查标志是否为真。
我在想,也许getValue和setValue在脚本之间不起作用?或者,使用循环检查标志是否变为真的方法是错误的。
如果有人能告诉我我的剧本哪里错了,我将是非常伟大的。
发布于 2016-06-12 17:14:57
GM_setValue和GM_getValue确实在同一个脚本中运行交叉选项卡或窗口,但它们不运行交叉脚本。因此,当在脚本上设置值时,它不会更改其他脚本的值。
尝试本地存储或外部数据库中的存储。
https://stackoverflow.com/questions/37776277
复制相似问题