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

This commit is contained in:
502647092 2020-11-10 04:11:14 +00:00
parent 2449b12d17
commit a1651e690d

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name MCBBS自动售卖机
// @namespace http://tampermonkey.net/
// @version 0.1
// @version 0.2
// @description 自动售卖道具
// @author MiaoWoo
// @match https://www.mcbbs.net/home.php?mod=magic**
@ -16,6 +16,7 @@
return new Promise((resolve, reject) => setTimeout(resolve, time))
}
async function main() {
try {
let params = location.href.split('?')[1].split('&').map(s => s.split('=')).reduce((pre, cur, index) => { pre[cur[0]] = cur[1]; return pre }, {})
if (!params.action) { return location.href = '/home.php?mod=magic&action=mybox' }
console.log(params)
@ -30,45 +31,57 @@
await logAction(params)
break
}
} catch (ex) {
await sleep(1500)
location.href = '/home.php?mod=magic&action=mybox'
}
}
async function shopAction() {
sendOrderAction(() => window.showWindow('magics', 'home.php?mod=magic&action=shop&operation=give&mid=mcbbs_mcserver_plus:serverBump'), true)
await sendOrderAction(() => window.showWindow('magics', 'home.php?mod=magic&action=shop&operation=give&mid=mcbbs_mcserver_plus:serverBump'), true)
}
async function myboxAction() {
sendOrderAction(() => window.showWindow('magics', 'home.php?mod=magic&action=mybox&operation=give&magicid=32', 'get', 0))
await sendOrderAction(() => window.showWindow('magics', 'home.php?mod=magic&action=mybox&operation=give&magicid=32', 'get', 0))
}
async function lowStockNotify() {
await fetch('https://reward.yumc.pw/mcbbs/lowStockNotify').then(r => r.json())
}
async function clearOrderCache() {
await fetch('https://reward.yumc.pw/mcbbs/clearOrderCache').then(r => r.json())
}
async function duplicateNotify(order_id) {
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) {
let count = 0
let result = await fetch('https://reward.yumc.pw/mcbbs/needSendOrder').then(r => r.json())
if (result.code != 200) {
if (++checkTimes > 30) {
if (++checkTimes > 30 || back) {
location.href = '/home.php?mod=magic&action=mybox'
}
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)
return setTimeout(() => location.href = '/home.php?mod=magic&action=mybox', 5000)
}
// 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) {
if (count > 5) {
if (count > 3) {
console.log('检测窗口超时!')
if (!back) {
if (order.allowAutoBuy) {
await clearOrderCache()
await sleep(1500)
location.href = '/home.php?mod=magic&action=shop'
} else {
lowStockNotify()
await lowStockNotify()
await sleep(10000)
location.href = '/home.php?mod=magic&action=mybox'
}
}
return
@ -91,6 +104,18 @@
while ((info = jq('.alert_info').text()) == '') {
if (count > 5) {
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)
@ -114,7 +139,7 @@
console.log(ex)
}
await sleep(800)
if (back) {
if (back || error) {
return location.href = '/home.php?mod=magic&action=mybox'
}
jq('#fwin_dialog_submit').click()