我正在控制台中运行脚本,以使用以下脚本在Tinder的网页上滑动:
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();
答案 0 :(得分:0)
您需要将赋值放入函数中,以便每次都重新计算变量。
).then(() => {
var random_boolean = Math.random() < 0.7;
if(random_boolean){
click("recsGamepad__button--like")
}else{
click("recsGamepad__button--dislike")
}