为了账号安全,请及时绑定邮箱和手机立即绑定

延时设置间隔功能

延时设置间隔功能

绝地无双 2021-06-17 14:01:50
我试图延迟点击第一张图片,因为它在进入屏幕之前就触发了,也许我需要将它放在 if else 语句中?// Instagram hacks//  Search field// let Searchtest= prompt("Please enter the hashtag you want to like","Trending");// var search = document.querySelector('.x3qfX').value = "#" + Searchtest;document.querySelector(".glyphsSpriteSafari__outline__24__grey_9").click();let firstPicture = document.querySelector("div._9AhH0");firstPicture.click();let likesGiven = 0;setInterval(() => {  let heart = document.getElementsByClassName(      "glyphsSpriteHeart__outline__24__grey_9"    ),    arrow = document.querySelector(".coreSpriteRightPaginationArrow");  if (heart[1]) {    heart = heart[1].parentElement;    likesGiven++, heart.click();  }  arrow.click();  console.log(`You've liked ${likesGiven} post(s)!`);}, 2000);// Button LikerMy Last Attempt Run this in your console from instagrams homepage and you u will see what 我是说document.querySelector(".glyphsSpriteSafari__outline__24__grey_9").click();    let firstPicture = document.querySelector("div._9AhH0");    if (firstPicture){        firstPicture.click();    }
查看完整描述

2 回答

?
Qyouu

TA贡献1786条经验 获得超11个赞

好的,就是这样:也许你应该等待文档被加载,似乎你可以用 DOMContentLoaded evenListener 来完成,然后在 onready 回调中你可以执行你的点击函数:见下面的例子


DOM 在 ES6 中没有改变,ES6 给了 JavaScript 新的特性,仅此而已。在纯 js 中,dom 加载的存在事件它是从 jquery 等价物准备好的文档


document.addEventListener("DOMContentLoaded",function(){ //do something here });

使用 DOM 树的模块可以在里面有监听器,或者应该在 dom 准备好后使用。我创建了示例 DOM 函数来说明我的意思:


var DOM=function(selector){


 document.addEventListener("DOMContentLoaded",()=>{


 this.element=document.querySelector(selector);


 if (typeof this.callback === 'function')

 this.callback();


});


};


//HERE WE HAVE CALLBACK WHEN OUR MODULE CAN BE USED

DOM.prototype.onReady=function(callback){


 this.callback=callback;


};


DOM.prototype.getElement=function(){

//example object method


return this.element;


};


DOM.prototype.click=function(){


return this.element.click


};

用法示例:


document.querySelector(".glyphsSpriteSafari__outline__24__grey_9").click();

var d=new DOM("div._9AhH0");

firstPicture.onReady(()=>{


firstPicture.click();


});

//your other code

模块应该独立于 DOM,创建直接导出 DOM 元素的模块是非常错误的做法。所以它可以通过两种方式完成:


模块应该在属性中获取选择器 DOM 对象,并且应该在 DOM 准备好后调用。所以你的模块不知道在哪里被调用,但它需要准备好的 DOM 结构。在这种情况下,DOM 就绪回调仅在使用模块并调用它们的主文件中。


模块可以有一些 DOM 就绪侦听器,但我们还需要一些信息何时可以使用模块(我在示例和 onReady 函数中展示了这种情况)。


查看完整回答
反对 回复 2021-06-18
  • 2 回答
  • 0 关注
  • 146 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信