更新 'mcbbs/vending-machine.user.js'
This commit is contained in:
parent
dee9fb2acd
commit
1ce4da222e
@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name MCBBS自动售卖机
|
||||
// @namespace https://miaowoo.cc/
|
||||
// @version 0.5
|
||||
// @version 0.6
|
||||
// @description 自动售卖道具
|
||||
// @author MiaoWoo
|
||||
// @match https://www.mcbbs.net/home.php?mod=magic**
|
||||
@ -11,17 +11,21 @@
|
||||
(async function () {
|
||||
let store = window.localStorage
|
||||
const lastOrderKey = 'circlebox:lastorder'
|
||||
let params = 0
|
||||
let checkTimes = 0
|
||||
let stock = 0
|
||||
let messagetext = undefined
|
||||
let storeUsername = undefined
|
||||
async function sleep(time) {
|
||||
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' }
|
||||
params = location.href.split('?')[1].split('&').map(s => s.split('=')).reduce((pre, cur, index) => { pre[cur[0]] = cur[1]; return pre }, {})
|
||||
if (!params.nodeType) { return console.log('nodeType is undefined skip...') }
|
||||
if (!params.action) { return refresh() }
|
||||
console.log(params)
|
||||
try {
|
||||
storeUsername = document.getElementsByClassName('username')[0].innerText
|
||||
messagetext = document.getElementById('messagetext')
|
||||
if (messagetext) {
|
||||
updateStatus(messagetext.innerText)
|
||||
@ -29,22 +33,58 @@
|
||||
} else {
|
||||
updateStatus('')
|
||||
}
|
||||
switch (params.nodeType) {
|
||||
case "master":
|
||||
master(params)
|
||||
break
|
||||
case "slave":
|
||||
slave(params)
|
||||
break
|
||||
}
|
||||
} catch (ex) {
|
||||
await sleep(1500)
|
||||
refresh()
|
||||
}
|
||||
}
|
||||
async function master(params) {
|
||||
switch (params.action || "shop") {
|
||||
case "shop":
|
||||
await shopAction(params)
|
||||
break
|
||||
case "mybox":
|
||||
stock = updateStock()
|
||||
stock = await updateStock()
|
||||
await myboxAction(params)
|
||||
break
|
||||
case "log":
|
||||
await logAction(params)
|
||||
break
|
||||
}
|
||||
} catch (ex) {
|
||||
await sleep(1500)
|
||||
location.href = '/home.php?mod=magic&action=mybox'
|
||||
}
|
||||
async function slave(params) {
|
||||
switch (params.action || "shop") {
|
||||
case "shop":
|
||||
case "log":
|
||||
refresh()
|
||||
break
|
||||
case "mybox":
|
||||
stock = await updateStock()
|
||||
await needReplenishment()
|
||||
break
|
||||
}
|
||||
}
|
||||
async function needReplenishment() {
|
||||
let timeoutTask = setTimeout(() => { refresh() }, 120000)
|
||||
let result = await fetch('https://reward.yumc.pw/mcbbs/needReplenishment').then(r => r.json())
|
||||
if (result.code != 200) {
|
||||
if (++checkTimes > 5) { return refresh() }
|
||||
clearTimeout(timeoutTask)
|
||||
return setTimeout(() => needReplenishment(), 2000)
|
||||
}
|
||||
let masterInfo = result.data
|
||||
sendItem(() => window.showWindow('magics', 'home.php?mod=magic&action=mybox&operation=give&magicid=32', 'get', 0), masterInfo.username, masterInfo.amount || stock)
|
||||
}
|
||||
async function refresh() {
|
||||
location.href = '/home.php?mod=magic&action=mybox&nodeType=' + params.nodeType
|
||||
}
|
||||
async function shopAction() {
|
||||
await sendOrderAction(() => window.showWindow('magics', 'home.php?mod=magic&action=shop&operation=give&mid=mcbbs_mcserver_plus:serverBump'), true)
|
||||
@ -57,15 +97,15 @@
|
||||
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())
|
||||
}
|
||||
await fetch(`https://reward.yumc.pw/mcbbs/updateStock/username/${storeUsername}/stock/${stock}`).then(r => r.json())
|
||||
return stock
|
||||
}
|
||||
async function updateStatus(message) {
|
||||
await fetch(`https://reward.yumc.pw/mcbbs/updateStatus/message/${message}`).then(r => r.json())
|
||||
await fetch(`https://reward.yumc.pw/mcbbs/updateStatus/username/${storeUsername}/message/${message}`).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())
|
||||
await fetch(`https://reward.yumc.pw/mcbbs/lowStockNotify/username/${storeUsername}/stock/${stock}/order_id/${order_id}/goods_amount/${goods_amount}`).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())
|
||||
@ -77,20 +117,65 @@
|
||||
if (order.allowAutoBuy) {
|
||||
await clearOrderCache(order.order_id)
|
||||
await sleep(1500)
|
||||
location.href = '/home.php?mod=magic&action=shop'
|
||||
location.href = '/home.php?mod=magic&action=shop&nodeType=' + params.nodeType
|
||||
} else {
|
||||
await lowStockNotify(stock, order.order_id, order.goods_amount)
|
||||
await sleep(120000)
|
||||
location.href = '/home.php?mod=magic&action=mybox'
|
||||
}
|
||||
}
|
||||
async function sendItem(openFn, usernameValue, amountValue) {
|
||||
try { openFn() } catch (ex) { }
|
||||
amountValue = Math.min(stock, amountValue)
|
||||
let username = undefined
|
||||
let count = 0
|
||||
while ((username = jq('#selectedusername')[0]) == undefined) {
|
||||
if (count > 3) {
|
||||
console.log('检测窗口超时!')
|
||||
return false
|
||||
}
|
||||
await sleep(800)
|
||||
count++
|
||||
}
|
||||
username.value = usernameValue
|
||||
let amount = username.parentNode.parentNode.nextElementSibling.childNodes[3].childNodes[0]
|
||||
amount.value = amountValue
|
||||
let remark = username.parentNode.parentNode.nextElementSibling.nextElementSibling.childNodes[3].childNodes[0]
|
||||
remark.value = `子节点补货 补货账号: ${storeUsername} 补货数量: ${amountValue}`
|
||||
await sleep(300)
|
||||
jq('#operatesubmit').click()
|
||||
await sleep(500)
|
||||
jq('#fwin_dialog_submit').click()
|
||||
let info = ''
|
||||
let error = ''
|
||||
while ((info = jq('.alert_info').text()) == '') {
|
||||
if (count > 3) {
|
||||
error = jq('#ntcwin').text()
|
||||
break
|
||||
}
|
||||
await sleep(800)
|
||||
count++
|
||||
}
|
||||
if (error && error.startsWith('抱歉,对方道具包容量不足')) {
|
||||
amountValue = error.replace(/[^0-9]/ig, "")
|
||||
if (amountValue == 0) {
|
||||
return refresh()
|
||||
}
|
||||
await sleep(200)
|
||||
amount.value = amountValue
|
||||
await sleep(300)
|
||||
jq('#operatesubmit').click()
|
||||
await sleep(500)
|
||||
jq('#fwin_dialog_submit').click()
|
||||
}
|
||||
await sleep(800)
|
||||
refresh()
|
||||
}
|
||||
async function sendOrderAction(openFn, back = false) {
|
||||
let timeoutTask = setTimeout(() => { location.href = '/home.php?mod=magic&action=mybox' }, 120000)
|
||||
let timeoutTask = setTimeout(() => { refresh() }, 120000)
|
||||
let count = 0
|
||||
let result = await fetch('https://reward.yumc.pw/mcbbs/needSendOrder').then(r => r.json())
|
||||
if (result.code != 200) {
|
||||
if (++checkTimes > 5 || back) {
|
||||
location.href = '/home.php?mod=magic&action=mybox'
|
||||
refresh()
|
||||
}
|
||||
clearTimeout(timeoutTask)
|
||||
return setTimeout(() => sendOrderAction(openFn), 2000)
|
||||
@ -113,7 +198,7 @@
|
||||
let amount = username.parentNode.parentNode.nextElementSibling.childNodes[3].childNodes[0]
|
||||
amount.value = order.goods_amount
|
||||
let remark = username.parentNode.parentNode.nextElementSibling.nextElementSibling.childNodes[3].childNodes[0]
|
||||
remark.value = `圈云盒子 自动发货订单: ${order.order_id} 物品: ${order.goods_name} 数量: ${order.goods_amount}`
|
||||
remark.value = `圈云盒子 自动发货订单: ${order.order_id} 物品: ${order.goods_name} 数量: ${order.goods_amount} 发货账号: ${storeUsername}`
|
||||
store.setItem(lastOrderKey, order.order_id)
|
||||
await sleep(300)
|
||||
jq('#operatesubmit').click()
|
||||
@ -130,7 +215,10 @@
|
||||
count++
|
||||
}
|
||||
if (error == "抱歉,操作数量不合法") {
|
||||
return await handleLowStock(order, stock)
|
||||
if (order.goods_amount > stock) {
|
||||
error = `发货账号: ${storeUsername} 库存 ${stock} 不足 ${order.goods_amount} 已通知管理员(QQ: 502647092) 请等待...`
|
||||
}
|
||||
await handleLowStock(order, stock)
|
||||
}
|
||||
try {
|
||||
let finish = await fetch('https://reward.yumc.pw/mcbbs/updateOrder', {
|
||||
@ -150,10 +238,7 @@
|
||||
console.log(ex)
|
||||
}
|
||||
await sleep(800)
|
||||
if (back || error) {
|
||||
return location.href = '/home.php?mod=magic&action=mybox'
|
||||
}
|
||||
jq('#fwin_dialog_submit').click()
|
||||
refresh()
|
||||
}
|
||||
async function logAction(params) {
|
||||
switch (params.operation) {
|
||||
|
Loading…
Reference in New Issue
Block a user