VickScarlet / lifeRestart

やり直すんだ。そして、次はうまくやる。
https://liferestart.syaro.io
MIT License
10.13k stars 2.33k forks source link

手动点太累了,自动玩 #351

Closed shaoguanlee closed 2 years ago

shaoguanlee commented 2 years ago
function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function start() {
    await sleep(1000);
    $('#restart').trigger("click");

    await sleep(1000);
    $('#random').trigger('click');

    let k = {};
    while(true) {
        let i = Math.floor(Math.random() * $('#talents > li').length);
        if(!k[i]) {
            k[i] = true;
        }
        if(Object.keys(k).length === 3) {
            break;
        }
    }

    Object.keys(k).forEach(e=>{
        $('#talents > li').eq(e).trigger('click');
    });

    await sleep(1000);
    $('#next').trigger('click');

    await sleep(1000);
    $('#random').trigger('click');

    await sleep(1000);
    $('#start').trigger('click');

    await sleep(1000);
    $('#auto2x').trigger('click');
}

setInterval(async ()=>{
    let v = $("#summary");
    if(v.is(':visible') && v.html() === '人生总结') {
        await sleep(1000);
        v.trigger("click");
        await sleep(1000);
        $("#again").trigger("click");
        await sleep(1000);
        start();
    }
}, 2000);

start();
shaoguanlee commented 2 years ago

上面的代码会导致玩一段时间后无法继续自动玩 这是修正后的代码

页面加载完成后,F12,选择控制台,复制粘贴以下内容,并回车

function sleep(ms) {
  return new Promise(resolve => setTimeout(resolve, ms))
}

async function start() {
    await sleep(1000);
    $('#restart').trigger("click");

    await sleep(1000);
    $('#random').trigger('click');

    await sleep(1000);
    $('#talents').children("li.selected").removeClass("selected");
    while($('#talents').children("li.selected").length < 3) {
        await sleep(1000);
        let size = $('#talents').children("li").length;
        $('#talents > li').eq(Math.floor(Math.random() * size)).trigger('click');
    }

    await sleep(1000);
    $('#next').trigger('click');

    await sleep(1000);
    $('#random').trigger('click');

    await sleep(1000);
    $('#start').trigger('click');

    await sleep(1000);
    $('#auto2x').trigger('click');

    console.info("开始");
}

setInterval(async ()=>{
    let v = $("#summary");
    if(v.is(':visible') && v.html() === '人生总结') {
        console.info("结束");
        v.trigger("click");
        await sleep(1000);
        $("#again").trigger("click");
        await sleep(1000);
        console.info("重新开始");
        start();
    } else {
        let e = $("#lifeTrajectory");
        if(e[0] && $("#lifeProperty").is(':visible')) {
            e.trigger("click");
        }
    }
}, 100);

start();