更新 'mcbbs/vending-machine.user.js'
This commit is contained in:
parent
97b94e13e6
commit
11a6b26c15
@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name MCBBS自动售卖机
|
||||
// @namespace https://miaowoo.cc/
|
||||
// @version 0.3
|
||||
// @version 0.5
|
||||
// @description 自动售卖道具
|
||||
// @author MiaoWoo
|
||||
// @match https://www.mcbbs.net/home.php?mod=magic**
|
||||
@ -42,25 +42,46 @@
|
||||
async function myboxAction() {
|
||||
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 updateStock() {
|
||||
let serverBump = document.getElementById('magic_mcbbs_mcserver_plus:serverBump')
|
||||
let stock = 0
|
||||
if (serverBump) {
|
||||
stock = serverBump.nextElementSibling.nextElementSibling.children[0].innerText
|
||||
await fetch(`https://reward.yumc.pw/mcbbs/updateStock/stock/${stock}`).then(r => r.json())
|
||||
}
|
||||
return stock
|
||||
}
|
||||
async function clearOrderCache() {
|
||||
await fetch('https://reward.yumc.pw/mcbbs/clearOrderCache').then(r => r.json())
|
||||
async function lowStockNotify(stock, order_id, goods_amount) {
|
||||
await fetch(`https://reward.yumc.pw/mcbbs/lowStockNotify/stock/${stock}/order_id/${order_id}/goods_amount/${goods_amount}`).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())
|
||||
async function clearOrderCache(order_id) {
|
||||
await fetch('https://reward.yumc.pw/mcbbs/clearOrderCache/order_id/' + order_id).then(r => r.json())
|
||||
}
|
||||
async function duplicateNotify(order_id, goods_amount) {
|
||||
await fetch(`https://reward.yumc.pw/mcbbs/duplicateNotify/order_id/${order_id}/goods_amount/${goods_amount}`).then(r => r.json())
|
||||
}
|
||||
async function handleLowStock(order, stock) {
|
||||
if (order.allowAutoBuy) {
|
||||
await clearOrderCache(order.order_id)
|
||||
await sleep(1500)
|
||||
location.href = '/home.php?mod=magic&action=shop'
|
||||
} else {
|
||||
await lowStockNotify(stock, order.order_id, order.goods_amount)
|
||||
await sleep(120000)
|
||||
location.href = '/home.php?mod=magic&action=mybox'
|
||||
}
|
||||
}
|
||||
async function sendOrderAction(openFn, back = false) {
|
||||
let timeoutTask = setTimeout(() => { location.href = '/home.php?mod=magic&action=mybox' }, 30000)
|
||||
let timeoutTask = setTimeout(() => { location.href = '/home.php?mod=magic&action=mybox' }, 90000)
|
||||
let count = 0
|
||||
let stock = updateStock()
|
||||
let result = await fetch('https://reward.yumc.pw/mcbbs/needSendOrder').then(r => r.json())
|
||||
if (result.code != 200) {
|
||||
if (result.code != 200 && result.data.order_id) {
|
||||
if (++checkTimes > 30 || back) {
|
||||
location.href = '/home.php?mod=magic&action=mybox'
|
||||
}
|
||||
clearTimeout(timeoutTask)
|
||||
return setTimeout(() => sendOrderAction(openFn), 15000)
|
||||
return setTimeout(() => sendOrderAction(openFn), 2000)
|
||||
}
|
||||
try { openFn() } catch (ex) { }
|
||||
let order = result.data
|
||||
@ -69,17 +90,7 @@
|
||||
while ((username = jq('#selectedusername')[0]) == undefined) {
|
||||
if (count > 3) {
|
||||
console.log('检测窗口超时!')
|
||||
if (!back) {
|
||||
if (order.allowAutoBuy) {
|
||||
await clearOrderCache()
|
||||
await sleep(1500)
|
||||
location.href = '/home.php?mod=magic&action=shop'
|
||||
} else {
|
||||
await lowStockNotify()
|
||||
await sleep(10000)
|
||||
location.href = '/home.php?mod=magic&action=mybox'
|
||||
}
|
||||
}
|
||||
if (!back) { await handleLowStock(order, stock) }
|
||||
return
|
||||
}
|
||||
await sleep(800)
|
||||
@ -106,16 +117,7 @@
|
||||
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
|
||||
return await handleLowStock(order, stock)
|
||||
}
|
||||
try {
|
||||
let finish = await fetch('https://reward.yumc.pw/mcbbs/updateOrder', {
|
||||
|
Loading…
Reference in New Issue
Block a user