更新 ele/auto-meal-complete.user.js

This commit is contained in:
502647092 2023-12-08 08:12:45 +00:00
parent a73e863fe7
commit fd4c405d20

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name 饿了么自动出餐 // @name 饿了么自动出餐
// @namespace https://circlecloud.ltd/ // @namespace https://circlecloud.ltd/
// @version 0.1 // @version 0.0.5
// @description 自动出餐 // @description 自动出餐
// @author MiaoWoo // @author MiaoWoo
// @match https://melody.shop.ele.me/app/shop/**/order__processing // @match https://melody.shop.ele.me/app/shop/**/order__processing
@ -95,7 +95,7 @@
} }
localStorage.setItem(SubmitOrdersKey, JSON.stringify(ele.submitOrders)) localStorage.setItem(SubmitOrdersKey, JSON.stringify(ele.submitOrders))
await sleep(5) await sleep(5)
await updateOrders() await syncOrders()
return result return result
} }
async function checkCooking() { async function checkCooking() {
@ -108,7 +108,7 @@
let leftTime = cook.mealPreparationInfo.commonShowTime let leftTime = cook.mealPreparationInfo.commonShowTime
let deliveOnShop = cook.deliveryInfo.distTraceView.traceView.status == '骑士已到店' let deliveOnShop = cook.deliveryInfo.distTraceView.traceView.status == '骑士已到店'
|| (cook.deliveryInfo.deliveryDistance || (cook.deliveryInfo.deliveryDistance
&& cook.deliveryInfo.deliveryDistance.endsWith('m') && !cook.deliveryInfo.deliveryDistance.endsWith('km')
&& parseInt(cook.deliveryInfo.deliveryDistance) < 100) && parseInt(cook.deliveryInfo.deliveryDistance) < 100)
if (deliveOnShop && cook.mealPreparationInfo.minMealCompleteTimeCount < 0 if (deliveOnShop && cook.mealPreparationInfo.minMealCompleteTimeCount < 0
&& leftTime < ele.autoSubmitLeftTimeWhenOnShop) { && leftTime < ele.autoSubmitLeftTimeWhenOnShop) {
@ -128,7 +128,7 @@
cook.mealPreparationInfo.commonShowTime -= 5 cook.mealPreparationInfo.commonShowTime -= 5
} }
} }
async function updateOrders() { async function syncOrders() {
let orders = await queryInProcessOrders() let orders = await queryInProcessOrders()
ele.processOrders = orders.result || [] ele.processOrders = orders.result || []
debug('更新订单数据 目前进行中订单: ' + ele.processOrders.length + '个') debug('更新订单数据 目前进行中订单: ' + ele.processOrders.length + '个')
@ -139,7 +139,7 @@
if (ele.logs.length > ele.maxLogLength) { if (ele.logs.length > ele.maxLogLength) {
ele.logs = ele.logs.slice(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 = `当前配置: </br> let configInfo = `当前配置: </br>
<div class="ant-alert-content"> <div class="ant-alert-content">
骑手到店 提前 ${ele.autoSubmitLeftTimeWhenOnShop}s 出餐 骑手到店 提前 ${ele.autoSubmitLeftTimeWhenOnShop}s 出餐
@ -188,17 +188,31 @@
console.log(msg) 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() { async function main() {
setTimeout(() => { setTimeout(async () => {
window.appContainerNoticeBar = document.getElementById('app-container-notice-bar') window.appContainerNoticeBar = document.getElementById('app-container-notice-bar')
updateOrders() await scheduleSync()
}, 5000) await scheduleCheck()
setInterval(() => { checkCooking() }, 5000) }, 3000)
setInterval(() => { updateOrders() }, 20000)
} }
var SubmitOrdersKey = 'AutoMealComplete:SubmitOrders' var SubmitOrdersKey = 'AutoMealComplete:SubmitOrders'
var ele = { var ele = {
title: '饿了么自动出餐',
version: '0.0.5',
author: 'MiaoWoo',
logs: [], logs: [],
checkInterval: 5,
syncInterval: 15,
maxLogLength: 20, maxLogLength: 20,
maxLogOrderLength: 20, maxLogOrderLength: 20,
orderStatus: {}, orderStatus: {},
@ -208,7 +222,7 @@
autoSubmitLeftTime: 200, autoSubmitLeftTime: 200,
autoSubmitLeftTimeWhenOnShop: 320, autoSubmitLeftTimeWhenOnShop: 320,
debug: debug, debug: debug,
updateOrders: updateOrders, syncOrders: syncOrders,
checkCooking: checkCooking, checkCooking: checkCooking,
mealComplete: mealComplete, mealComplete: mealComplete,
} }