zarkin404 / sweater

薅 🐑 毛,做衬衫
GNU General Public License v3.0
938 stars 305 forks source link

根据原脚本改了下,改成定时执行炸弹的脚本 #30

Closed worning97 closed 3 years ago

worning97 commented 4 years ago

// 请求函数
var request = (functionId, body = {}) =>
  fetch("https://api.m.jd.com/client.action", {
    body: `functionId=${functionId}&body=${JSON.stringify(
      body
    )}&client=wh5&clientVersion=1.0.0`,
    headers: {
      "content-type": "application/x-www-form-urlencoded",
    },
    method: "POST",
    credentials: "include",
  });

// 循环执行主程序
var excuteMain = () => {
    let myDate = new Date();
    let hour = myDate.getHours(); 
    let minute = myDate.getMinutes();

    // 按照时间排好序
    let boomTimes = [[10, 0], [12, 0], [16, 0], [18 ,0], [20 ,0], [21, 0], [21, 30]];

    // 匹配到开始抢炸弹的时间
    let pergNum = boomTimes.findIndex(function (item, index) {
       return ((hour === item[0] && Math.abs(minute - item[1]) < 1) || (hour === (item[0] - 1) && minute >= 59) );
    })

    // 提前1分钟开始抢 一共执行2分钟
    if(pergNum >= 0) {
        // 战队抢炸弹,感谢 @elevenDimension 提供 functionId
        console.log("开始抢炸弹~" + "hour: " + hour + " minute : " + minute);
        request("cakebaker_pk_getCakeBomb");
        setTimeout(excuteMain, 100);
    }
    // 如果时间超过炸弹时间则取消本次全部执行
    else if(hour > boomTimes[boomTimes.length - 1][0] || (hour == boomTimes[boomTimes.length - 1][0] && minute > boomTimes[boomTimes.length - 1][1])) {
        console.log("本天任务执行结束" + "hour: " + hour + " minute : " + minute);
        return;
    } 
    else {
        console.log("等待 不再抢炸弹时间范围内");
        setTimeout(excuteMain, 50000);
    }
};

excuteMain();

wintercoder commented 4 years ago

老哥,把代码格式处理下,直接复制出来的各种语法错

worning97 commented 4 years ago

老哥,把代码格式处理下,直接复制出来的各种语法错

哦了大兄弟

lero007 commented 4 years ago

还是加个pre标签看着舒服呀

var currentCycle = 0;

// 请求函数
var request = (functionId, body = {}) =>
    fetch("https://api.m.jd.com/client.action", {
        body: `functionId=${functionId}&body=${JSON.stringify(
            body
        )}&client=wh5&clientVersion=1.0.0`,
        headers: {
            "content-type": "application/x-www-form-urlencoded",
        },
        method: "POST",
        credentials: "include",
    });

// 循环执行主程序
var excuteMain = () => {
    let myDate = new Date();
    let hour = myDate.getHours();
    let minute = myDate.getMinutes();
    let boomTimes = [10, 12, 16, 18, 20];
    let pergHourIndex = boomTimes.indexOf(hour);
    let pergHour = pergHourIndex >= 0 ? boomTimes[pergHourIndex] : 0;
    // 提前1分钟开始抢 一共执行2分钟
    if (pergHourIndex >= 0 && (hour == pergHour && minute <= 1) || (hour == (pergHour - 1) && minute >= 59)) {
        // 战队抢炸弹,感谢 @elevenDimension 提供 functionId
        request("cakebaker_pk_getCakeBomb");
        setTimeout(excuteMain, 100);
    } else if (hour >= boomTimes[boomTimes.length - 1] && minute > 1) {
        console.log("本天任务执行结束");
        return;
    } else {
        console.log("等待 不再时间范围内");
        setTimeout(excuteMain, 29000);
    }
};

excuteMain();
ilss commented 4 years ago

不错不错!

worning97 commented 4 years ago

还是加个pre标签看着舒服呀

var currentCycle = 0;

// 请求函数 var request = (functionId, body = {}) => fetch("https://api.m.jd.com/client.action", { body: functionId=${functionId}&body=${JSON.stringify( body )}&client=wh5&clientVersion=1.0.0, headers: { "content-type": "application/x-www-form-urlencoded", }, method: "POST", credentials: "include", });

// 循环执行主程序 var excuteMain = () => { let myDate = new Date(); let hour = myDate.getHours(); let minute = myDate.getMinutes(); let boomTimes = [10, 12, 16, 18, 20]; let pergHourIndex = boomTimes.indexOf(hour); let pergHour = pergHourIndex >= 0 ? boomTimes[pergHourIndex] : 0; // 提前1分钟开始抢 一共执行2分钟 if (pergHourIndex >= 0 && (hour == pergHour && minute <= 1) || (hour == (pergHour - 1) && minute >= 59)) { // 战队抢炸弹,感谢 @elevenDimension 提供 functionId request("cakebaker_pk_getCakeBomb"); setTimeout(excuteMain, 100); } else if (hour >= boomTimes[boomTimes.length - 1] && minute > 1) { console.log("本天任务执行结束"); return; } else { console.log("等待 不再时间范围内"); setTimeout(excuteMain, 29000); } };

excuteMain();

nice

igangx commented 4 years ago

第一 致敬作者~ 写的有点糙,就是个定时器不断触发炸弹的,只需要在页面上run下就可以了

var currentCycle = 0;

// 请求函数 var request = (functionId, body = {}) => fetch("https://api.m.jd.com/client.action", { body: `functionId=${functionId}&body=${JSON.stringify( body )}&client=wh5&clientVersion=1.0.0`, headers: { "content-type": "application/x-www-form-urlencoded", }, method: "POST", credentials: "include", });

// 循环执行主程序 var excuteMain = () => { let myDate = new Date(); let hour = myDate.getHours(); let minute = myDate.getMinutes(); let boomTimes = [10, 12, 16, 18, 20]; let pergHourIndex = boomTimes.indexOf(hour); let pergHour = pergHourIndex >= 0 ? boomTimes[pergHourIndex] : 0; // 提前1分钟开始抢 一共执行2分钟 if(pergHourIndex >= 0 && (hour == pergHour && minute <= 1) || (hour == (pergHour - 1) && minute >= 59)) { // 战队抢炸弹,感谢 @elevenDimension 提供 functionId request("cakebaker_pk_getCakeBomb"); setTimeout(excuteMain, 100); } else if(hour >= boomTimes[boomTimes.length - 1] && minute > 1) { console.log("本天任务执行结束"); return; } else { console.log("等待 不再时间范围内"); setTimeout(excuteMain, 29000); } };

excuteMain();

大神,原脚本挂了,要不你给改改呗?

igangx commented 4 years ago

还是加个pre标签看着舒服呀

var currentCycle = 0;

// 请求函数 var request = (functionId, body = {}) => fetch("https://api.m.jd.com/client.action", { body: functionId=${functionId}&body=${JSON.stringify( body )}&client=wh5&clientVersion=1.0.0, headers: { "content-type": "application/x-www-form-urlencoded", }, method: "POST", credentials: "include", });

// 循环执行主程序 var excuteMain = () => { let myDate = new Date(); let hour = myDate.getHours(); let minute = myDate.getMinutes(); let boomTimes = [10, 12, 16, 18, 20]; let pergHourIndex = boomTimes.indexOf(hour); let pergHour = pergHourIndex >= 0 ? boomTimes[pergHourIndex] : 0; // 提前1分钟开始抢 一共执行2分钟 if (pergHourIndex >= 0 && (hour == pergHour && minute <= 1) || (hour == (pergHour - 1) && minute >= 59)) { // 战队抢炸弹,感谢 @elevenDimension 提供 functionId request("cakebaker_pk_getCakeBomb"); setTimeout(excuteMain, 100); } else if (hour >= boomTimes[boomTimes.length - 1] && minute > 1) { console.log("本天任务执行结束"); return; } else { console.log("等待 不再时间范围内"); setTimeout(excuteMain, 29000); } };

excuteMain();

大神,原脚本挂了,要不你给改改呗?

lero007 commented 4 years ago

@igangx 哪是啥大神。。。 你说的原脚本挂了是说执行完还有没浏览完的吗?

igangx commented 4 years ago

@igangx 哪是啥大神。。。 你说的原脚本挂了是说执行完还有没浏览完的吗?

大部分都不起作用啊,控制台显示success: false……你的不会吗?

little-cabbage1994 commented 4 years ago

哥哥我运行时候显示uncaught syntaxerror:invalid or unexpected token 怎么办

worning97 commented 4 years ago

哥哥我运行时候显示uncaught syntaxerror:invalid or unexpected token 怎么办

给个图看下

little-cabbage1994 commented 4 years ago

哥哥我运行时候显示uncaught syntaxerror:invalid or unexpected token 怎么办

给个图看下

今天可以啦哈哈,是运行一次就可以了吗

lero007 commented 4 years ago

@igangx 哪是啥大神。。。 你说的原脚本挂了是说执行完还有没浏览完的吗?

大部分都不起作用啊,控制台显示success: false……你的不会吗?

你说了之后咋都是false了,之前好好的。。。

igangx commented 4 years ago

@igangx 哪是啥大神。。。 你说的原脚本挂了是说执行完还有没浏览完的吗?

大部分都不起作用啊,控制台显示success: false……你的不会吗?

你说了之后咋都是false了,之前好好的。。。

哈哈哈哈哈哈哈哈哈哈哈。。。。。我已经自己搞定了

lero007 commented 4 years ago

@igangx 哪是啥大神。。。 你说的原脚本挂了是说执行完还有没浏览完的吗?

大部分都不起作用啊,控制台显示success: false……你的不会吗?

你说了之后咋都是false了,之前好好的。。。

哈哈哈哈哈哈哈哈哈哈哈。。。。。我已经自己搞定了

独乐乐不如众乐乐!

igangx commented 4 years ago

@igangx 哪是啥大神。。。 你说的原脚本挂了是说执行完还有没浏览完的吗?

大部分都不起作用啊,控制台显示success: false……你的不会吗?

你说了之后咋都是false了,之前好好的。。。

哈哈哈哈哈哈哈哈哈哈哈。。。。。我已经自己搞定了

独乐乐不如众乐乐!

https://github.com/zarkin404/sweater/issues/27#issuecomment-643756848

lero007 commented 4 years ago

哥哥我运行时候显示uncaught syntaxerror:invalid or unexpected token 怎么办

给个图看下

为什么我的好像只有第一次可以成功抢到,后面就不行了?

咦。。。我好像用的旧版,我自己改一改再试试。

lero007 commented 4 years ago

@igangx 谢啦。