Tampermonkey-刷新后跟踪迭代
我正在玩浏览器游戏,我遇到了这个脚本,但它并不是我想要的。
通常,此脚本仅运行一次,而不会在Tampermonkey上运行。脚本本身正在按预期工作,但每秒运行。
我试图使它连续两次运行,然后等待X弹出量的X弹出时间。
这是初始脚本。
// ==UserScript==
// @name Shinko BT Renamer
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://*/game.php*mode=incomings*
// @icon https://www.google.com/s2/favicons?sz=64&domain=devilicious.dev
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==
var FORMAT = "#unit# from #coords# -> BT: #backtime#";
let refreshTime = 5; // time to refresh the page in minutes
function main()
{
if(window.location.href.indexOf("subtype=attacks")==-1)
{
window.location.href = window.location.pathname+ "?screen=overview_villages&mode=incomings&mode=incomings&subtype=attacks";
return;
}
if (typeof FORMAT === 'undefined')
FORMAT = "#unit# from #coords# - #player# Backtime: #backtime#";
FORMAT = FORMAT.replace(/#/g, "%");
if(FORMAT.match(/%backtime%/g)!=null)
FORMAT = ("`" + FORMAT + "`").replace(/%backtime%/, "%return%:${('00' + ((arrivalSeconds+parseInt('%duration%'.split(':')[2]))%60).toString()).slice(-2)}");
console.log(FORMAT);
$('input[name=label_format]').val(FORMAT);
let tagRows =$("#incomings_table > tbody > tr").not(':first').not(':last');
tagRows = $.grep(tagRows, (obj)=> $(".quickedit-label", obj)[0].innerText.match(/`.*`/g)!=null);
if(tagRows.length >0)
$.map(tagRows, (obj, key)=>setTimeout(()=>{
evalTag(obj);
/*if(key == tagRows.length -1)
tagCommands();*/
}, 250* key));
else
tagCommands();
}
function renameCommand(command, name)
{
$('.rename-icon', command).click();
$('.quickedit-edit input[type="text"]', command).val(name);
$('.quickedit-edit input[type="button"]', command).click();
}
function evalTag(row)
{
let command = $("td:nth-child(1)", row)[0];
let arrivalTime = $("td:nth-child(6)", row)[0].innerText;
let arrivalSeconds = parseInt(arrivalTime.split(":")[2]);
let evalCommandTag;
try
{
evalCommandTag = eval(command.innerText);
}
catch(err)
{
evalCommandTag = command.innerText;
}
renameCommand(command, evalCommandTag);
}
function tagCommands()
{
if($("#incomings_form").length > 0)
{
selectAll($("#incomings_form")[0], true);
$("[name='label']")[0].click();
}
}
main();
I tried to do this but with no luck.
for (i ; i < 2; i++){
if(i<2){
main();
console.log(i);
}else{
setTimeout(function(){ location.reload(); },refreshTime * 60 * 1000);
console.log(i);
}
}
exec();
我最初认为的是。因此,我想运行两次,然后一个IF语句应该做到这一点,然后我做到了,可以跑一个cicle,但是当页面重新加载时,Tampermonkey失去了“ I”的
跟踪在Tampermonkey变量中i的值,但我无法使其起作用。任何输入都非常感谢。
谢谢!
var i = GM_getValue('i', 0);
GM_setValue('i', i+1);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看LocalStorage,以保留页面刷新之间的数据 - 快速简便的解决方案。
示例:
在脚本的顶部:
将计数例程更改为:
参考:
https://wwwww.w3schools.com/jschools.com/jsref/jsref/jsref/met_storage_setitem.storage_setitem.asp
https://www.w3schools.com/jsref/jsref/api_storage.asp
Look into localStorage to preserve data between page refreshes - quick and easy solution.
Example:
At the top of your script:
Change your count routine to:
Reference:
https://www.w3schools.com/jsref/met_storage_getitem.asp
https://www.w3schools.com/jsref/met_storage_setitem.asp
https://www.w3schools.com/jsref/api_storage.asp