diff --git a/jobs.js b/jobs.js index 583f62f..34a477f 100644 --- a/jobs.js +++ b/jobs.js @@ -278,7 +278,7 @@ async function submitOrderFromShoppingCart( } // loopTime 0: 50 // loopTime 1: 100 - await sleep(100); + await sleep(loopTime * 50 + 50); } if (!isAvailable) { console.log('访问结算页面彻底失败, 溜了'); @@ -469,11 +469,13 @@ async function submitOrderProcess( let printPoints = false; const id = setInterval(async () => { const now = Date.now(); - printPoints = !printPoints; - process.stdout.write('\r\x1b[K'); - process.stdout.write(dayjs(now).format('YYYY-MM-DD HH:mm:ss.SSS')); - if (printPoints) { - process.stdout.write('...'); + if (process.platform !== 'win32') { + printPoints = !printPoints; + process.stdout.write('\r\x1b[K'); + process.stdout.write(dayjs(now).format('YYYY-MM-DD HH:mm:ss.SSS')); + if (printPoints) { + process.stdout.write('...'); + } } if (now + m * 60 * 1000 >= date) { for (let i = 0; i < skuIds.length; i++) { diff --git a/package.json b/package.json index 242993e..ca5bdaf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "jd-yuyue", - "version": "1.2.1", + "version": "1.2.3", "description": "", "main": "index.js", "scripts": { diff --git a/timer.js b/timer.js index ca6d730..29535bf 100644 --- a/timer.js +++ b/timer.js @@ -4,7 +4,7 @@ const dayjs = require('./dayjs.min.js'); const getDiffTime = async () => { const old = Date.now(); - const res = await fetch('https://a.jd.com//ajax/queryServerData.html', { + const res = await fetch('https://api.m.jd.com/client.action?functionId=queryMaterialProducts&client=wh5', { headers: { // 瞎鸡儿填写一个 UA 'User-Agent': config.userAgent || 'chrome 81.0', @@ -12,29 +12,27 @@ const getDiffTime = async () => { }); const now = Date.now(); const json = await res.json(); - return Date.now() - (now - old) / 2 - json.serverTime; + return Date.now() - (now - old) / 2 - json.currentTime2; }; module.exports = async (d, fn, im = false) => { // Should excute immediately if (im) return Promise.resolve(fn()); - // const diffTime = await Promise.race([ - // getDiffTime(), - // getDiffTime(), - // getDiffTime(), - // getDiffTime(), - // ]); - // console.log( - // '多次请求中最快的一次与服务器时间差,', - // 'now - 请求往返/2 - jd服务器时间=', - // diffTime - // ); - console.log('jd时间服务器挂壁, 请自行根据以往误差往前调抢购时间'); + const diffTime = await Promise.race([ + getDiffTime(), + getDiffTime(), + getDiffTime(), + getDiffTime(), + ]); + console.log( + '多次请求中最快的一次与服务器时间差,', + 'now - 请求往返/2 - jd服务器时间=', + diffTime + ); return new Promise(r => { console.log('等待时间到达:', dayjs(d).format('YYYY-MM-DD HH:mm:ss.SSS')); while (true) { - // if (Date.now() - diffTime >= d) { - if (Date.now() >= d) { + if (Date.now() - diffTime >= d) { r(fn()); break; }