延时设置间隔功能

我试图延迟点击第一张图片,因为它在进入屏幕之前就触发了,也许我需要将它放在 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 Liker


My 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();


    }


绝地无双
浏览 147回答 2
2回答

Qyouu

好的,就是这样:也许你应该等待文档被加载,似乎你可以用 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 USEDDOM.prototype.onReady=function(callback){ this.callback=callback;};DOM.prototype.getElement=function(){//example object methodreturn 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 函数中展示了这种情况)。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript