From fd4c405d20c743e5e4e3c49fbb8b9d3a9d1d0f8e Mon Sep 17 00:00:00 2001 From: 502647092 Date: Fri, 8 Dec 2023 08:12:45 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20ele/auto-meal-complete.use?= =?UTF-8?q?r.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ele/auto-meal-complete.user.js | 36 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/ele/auto-meal-complete.user.js b/ele/auto-meal-complete.user.js index 5382075..544f4ec 100644 --- a/ele/auto-meal-complete.user.js +++ b/ele/auto-meal-complete.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name 饿了么自动出餐 // @namespace https://circlecloud.ltd/ -// @version 0.1 +// @version 0.0.5 // @description 自动出餐 // @author MiaoWoo // @match https://melody.shop.ele.me/app/shop/**/order__processing @@ -95,7 +95,7 @@ } localStorage.setItem(SubmitOrdersKey, JSON.stringify(ele.submitOrders)) await sleep(5) - await updateOrders() + await syncOrders() return result } async function checkCooking() { @@ -108,7 +108,7 @@ let leftTime = cook.mealPreparationInfo.commonShowTime let deliveOnShop = cook.deliveryInfo.distTraceView.traceView.status == '骑士已到店' || (cook.deliveryInfo.deliveryDistance - && cook.deliveryInfo.deliveryDistance.endsWith('m') + && !cook.deliveryInfo.deliveryDistance.endsWith('km') && parseInt(cook.deliveryInfo.deliveryDistance) < 100) if (deliveOnShop && cook.mealPreparationInfo.minMealCompleteTimeCount < 0 && leftTime < ele.autoSubmitLeftTimeWhenOnShop) { @@ -128,7 +128,7 @@ cook.mealPreparationInfo.commonShowTime -= 5 } } - async function updateOrders() { + async function syncOrders() { let orders = await queryInProcessOrders() ele.processOrders = orders.result || [] debug('更新订单数据 目前进行中订单: ' + ele.processOrders.length + '个') @@ -139,7 +139,7 @@ if (ele.logs.length > ele.maxLogLength) { ele.logs = ele.logs.slice(ele.logs.length - ele.maxLogLength) } - let title = '饿了么自动出餐 By MiaoWoo' + let title = `${ele.title} Version: ${ele.version} By ${ele.author}` let configInfo = `当前配置:
骑手到店 提前 ${ele.autoSubmitLeftTimeWhenOnShop}s 出餐 @@ -188,17 +188,31 @@ console.log(msg) } } + async function scheduleCheck() { + await sleep(ele.checkInterval * 1000) + await checkCooking() + scheduleCheck() + } + async function scheduleSync() { + await sleep(ele.syncInterval * 1000) + await syncOrders() + scheduleCheck() + } async function main() { - setTimeout(() => { + setTimeout(async () => { window.appContainerNoticeBar = document.getElementById('app-container-notice-bar') - updateOrders() - }, 5000) - setInterval(() => { checkCooking() }, 5000) - setInterval(() => { updateOrders() }, 20000) + await scheduleSync() + await scheduleCheck() + }, 3000) } var SubmitOrdersKey = 'AutoMealComplete:SubmitOrders' var ele = { + title: '饿了么自动出餐', + version: '0.0.5', + author: 'MiaoWoo', logs: [], + checkInterval: 5, + syncInterval: 15, maxLogLength: 20, maxLogOrderLength: 20, orderStatus: {}, @@ -208,7 +222,7 @@ autoSubmitLeftTime: 200, autoSubmitLeftTimeWhenOnShop: 320, debug: debug, - updateOrders: updateOrders, + syncOrders: syncOrders, checkCooking: checkCooking, mealComplete: mealComplete, }