随机布尔70/30内部功能?

问题描述 投票:-1回答:1

我跑在我的控制台中的脚本刷的火种的网页与下面的脚本:

https://github.com/dhrubesh/Tinder/blob/master/tinder.js

但现在它可以被看作是一个机器人,它一直不断地刷卡权,为此我想有70/30规则刷卡并修改了以下内容:

var random_boolean = Math.random() < 0.7; //Random boolean added
let run = true, time_step = 1000;
const wait = (n = 1) => new Promise((rs, rj) => run ? setTimeout(rs, n) : rj()),
  click = async (cn, i = 0) => {
    document.getElementsByClassName(cn)[i].click();
    return wait(time_step)
  };
document.onkeydown = (e = window.event) => {
  if (e.key === "a") run = run ? true : explore() || true;
  else if (e.key === "z") console.log(time_step *= 0.9);
  else if (e.key === "x") console.log(time_step *= 1.1);
  else run = false;
};
const explore = async () =>
  click("recCard__info").then(() =>
    Array.from(document.getElementsByClassName("bullet")).reduce((p, e) =>
      p.then(() => {
        e.click();
        return wait(time_step)
      }), Promise.resolve())
  ).then(() => {
    // This if statement below doesn't work
    if(random_boolean){
      click("recsGamepad__button--like")
    }else{
      click("recsGamepad__button--dislike")
    }
    //click("recsGamepad__button--like")  <-- this works if there is no if statement
  }

  ).then(() => explore());
explore();
javascript random boolean
1个回答
0
投票

你需要把分配的功能里面,所以变量重新计算每次。

).then(() => {
    var random_boolean = Math.random() < 0.7;
    if(random_boolean){
      click("recsGamepad__button--like")
    }else{
      click("recsGamepad__button--dislike")
    }
© www.soinside.com 2019 - 2024. All rights reserved.