[英]Increment with remainder not working
在我的脚本中,计算机单击WhatsApp Web中的联系人选项卡,然后每次检查该人是否在线。 这是通过一个循环完成的,当到达触点号16时,该循环再次开始。 无论如何,循环不起作用,变量“ i”也不会增加。 这很奇怪,因为如果我用console.log替换selectContact( ${i}
),那么增量就可以了。 也许${}
阻止i更新?
var i = 1
setInterval(function () {
selectContact(`${i}`)
if (document.getElementsByClassName("O90ur")[0] !== undefined) {
var online = document.getElementsByClassName("O90ur")[0].innerHTML
if (online == "online") {
console.log(`${i}`)};
}
i = i % 16 + 1
}, 1000);
如果问题应在此处,则这是selectContact的代码。
var jq = document.createElement('script');
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
contacts = [];
chat_div = [];
function triggerMouseEvent(node, eventType) {
var event = document.createEvent('MouseEvents');
event.initEvent(eventType, true, true);
node.dispatchEvent(event);
}
function getChatname(){
$("#pane-side > div > div > div").find("._2FBdJ > div._25Ooe").each(function(){
contacts.push($(this).text());
chat_div.push($(this));
})
}
function selectContact(name){
getChatname()
for (i = 0; i < contacts.length; i++){
if (name.toUpperCase() === contacts[i].toUpperCase()){
triggerMouseEvent(chat_div[i][0],"mousedown")
}
}
}
您已经错过了在var
循环中声明i
的var
语句,这意味着它会覆盖全局i
。
function selectContact(name){
getChatname()
for (var i = 0; i < contacts.length; i++){
if (name.toUpperCase() === contacts[i].toUpperCase()){
triggerMouseEvent(chat_div[i][0],"mousedown")
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.