更新 'mcbbs/vending-machine.user.js'

This commit is contained in:
502647092 2020-11-10 09:14:44 +00:00
parent a1651e690d
commit aea85dd6b1

View File

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