diff --git a/mcbbs/vending-machine.user.js b/mcbbs/vending-machine.user.js index dbd4328..98a19e2 100644 --- a/mcbbs/vending-machine.user.js +++ b/mcbbs/vending-machine.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name MCBBS自动售卖机 -// @namespace http://tampermonkey.net/ -// @version 0.2 +// @namespace https://miaowoo.cc/ +// @version 0.3 // @description 自动售卖道具 // @author MiaoWoo // @match https://www.mcbbs.net/home.php?mod=magic** @@ -52,22 +52,18 @@ await fetch('https://reward.yumc.pw/mcbbs/duplicateNotify/order_id/' + order_id).then(r => r.json()) } async function sendOrderAction(openFn, back = false) { + let timeoutTask = setTimeout(() => { location.href = '/home.php?mod=magic&action=mybox' }, 30000) let count = 0 let result = await fetch('https://reward.yumc.pw/mcbbs/needSendOrder').then(r => r.json()) if (result.code != 200) { if (++checkTimes > 30 || back) { location.href = '/home.php?mod=magic&action=mybox' } + clearTimeout(timeoutTask) return setTimeout(() => sendOrderAction(openFn), 15000) } try { openFn() } catch (ex) { } let order = result.data - // if (store.getItem(lastOrderKey) == order.order_id) { - // console.error('重复发送订单: ' + order.order_id + ' 5秒后刷新重试...') - // duplicateNotify(order.order_id) - // await sleep(5000) - // return location.href = '/home.php?mod=magic&action=mybox' - // } console.log(`开始发送订单 ${order.order_id}`) let username = undefined while ((username = jq('#selectedusername')[0]) == undefined) { @@ -86,7 +82,7 @@ } return } - await sleep(1000) + await sleep(800) count++ } username.value = order.reciver_name @@ -102,25 +98,25 @@ let info = '' let error = '' while ((info = jq('.alert_info').text()) == '') { - if (count > 5) { + if (count > 3) { error = jq('#ntcwin').text() - if (error == "抱歉,操作数量不合法") { - if (order.allowAutoBuy) { - await clearOrderCache() - await sleep(1500) - location.href = '/home.php?mod=magic&action=shop' - return - } else { - lowStockNotify() - await sleep(10000) - location.href = '/home.php?mod=magic&action=mybox' - } - } break } - await sleep(1000) + await sleep(800) count++ } + if (error == "抱歉,操作数量不合法") { + if (order.allowAutoBuy) { + await clearOrderCache() + await sleep(1500) + location.href = '/home.php?mod=magic&action=shop' + } else { + lowStockNotify() + await sleep(10000) + location.href = '/home.php?mod=magic&action=mybox' + } + return + } try { let finish = await fetch('https://reward.yumc.pw/mcbbs/updateOrder', { method: "POST",