为避免错误,请检查元素是否存在。添加了一个条件以检查元素是否存在或未定义
if(typeof $('._4gt3b')[0] !== 'undefined')
这是经过修改的脚本,缩进适当,
window.setInterval(function(){
var x = 0;
$("button:contains('Follow')").each(function(){
if($(this).text()=="Follow"){
if(x==2) return false;
$(this).trigger("click");
if(typeof $('._4gt3b')[0] !== 'undefined'){
$('._4gt3b').scrollTop($('._4gt3b')[0].scrollHeight);
}
x++;
}
});
if(typeof $('._4gt3b')[0] !== 'undefined'){
$('._4gt3b').scrollTop($('._4gt3b')[0].scrollHeight);
}
console.log('loop');
}, 70000);