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

This commit is contained in:
502647092 2023-05-24 01:18:08 +00:00
parent 51f382891b
commit 5d1b52edc2

View File

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name MCBBS自动售卖机 // @name MCBBS自动售卖机
// @namespace https://miaowoo.cc/ // @namespace https://miaowoo.cc/
// @version 0.8.0 // @version 0.8.1
// @description 自动售卖道具 // @description 自动售卖道具
// @author MiaoWoo // @author MiaoWoo
// @match https://www.mcbbs.net/home.php?mod=magic** // @match https://www.mcbbs.net/home.php?mod=magic**
@ -16,6 +16,7 @@
let stock = 0 let stock = 0
let messagetext = undefined let messagetext = undefined
let storeUsername = undefined let storeUsername = undefined
let gateway = "https://reward.yumc.pw"
async function sleep(time) { async function sleep(time) {
return new Promise((resolve, reject) => setTimeout(resolve, time)) return new Promise((resolve, reject) => setTimeout(resolve, time))
} }
@ -40,6 +41,7 @@
if (errorh1 && errorh1.innerText.startsWith(50)) { if (errorh1 && errorh1.innerText.startsWith(50)) {
return refresh() return refresh()
} }
setTimeout(refresh, 600000)
let taskId = setTimeout(refresh, 60000) let taskId = setTimeout(refresh, 60000)
createMenu() createMenu()
if (!params.nodeType) { return console.log('nodeType is undefined skip...') } if (!params.nodeType) { return console.log('nodeType is undefined skip...') }
@ -97,7 +99,7 @@
async function needReplenishment() { async function needReplenishment() {
let timeoutTask = setTimeout(() => { refresh() }, 120000) let timeoutTask = setTimeout(() => { refresh() }, 120000)
if (stock == 0) { return } if (stock == 0) { return }
let result = await fetch('https://s.yumc.pw/mcbbs/needReplenishment').then(r => r.json()) let result = await fetch(gateway + '/mcbbs/needReplenishment').then(r => r.json())
if (result.code != 200) { if (result.code != 200) {
if (++checkTimes > 5) { return refresh() } if (++checkTimes > 5) { return refresh() }
clearTimeout(timeoutTask) clearTimeout(timeoutTask)
@ -126,17 +128,17 @@
if (serverBump) { if (serverBump) {
stock = serverBump.nextElementSibling.nextElementSibling.children[0].innerText stock = serverBump.nextElementSibling.nextElementSibling.children[0].innerText
} }
await fetch(`https://s.yumc.pw/mcbbs/updateStock/username/${storeUsername}/stock/${stock}`).then(r => r.json()) await fetch(gateway + `/mcbbs/updateStock/username/${storeUsername}/stock/${stock}`).then(r => r.json())
return stock return stock
} }
async function updateStatus(message) { async function updateStatus(message) {
await fetch(`https://s.yumc.pw/mcbbs/updateStatus/username/${storeUsername}/message/${message}`).then(r => r.json()) await fetch(gateway + `/mcbbs/updateStatus/username/${storeUsername}/message/${message}`).then(r => r.json())
} }
async function lowStockNotify(stock, order_id, goods_amount) { async function lowStockNotify(stock, order_id, goods_amount) {
await fetch(`https://s.yumc.pw/mcbbs/lowStockNotify/username/${storeUsername}/stock/${stock}/order_id/${order_id}/goods_amount/${goods_amount}`).then(r => r.json()) await fetch(gateway + `/mcbbs/lowStockNotify/username/${storeUsername}/stock/${stock}/order_id/${order_id}/goods_amount/${goods_amount}`).then(r => r.json())
} }
async function clearOrderCache(order_id) { async function clearOrderCache(order_id) {
await fetch('https://s.yumc.pw/mcbbs/clearOrderCache/order_id/' + order_id).then(r => r.json()) await fetch(gateway + '/mcbbs/clearOrderCache/order_id/' + order_id).then(r => r.json())
} }
async function handleLowStock(order, stock) { async function handleLowStock(order, stock) {
if (order.allowAutoBuy) { if (order.allowAutoBuy) {
@ -202,9 +204,9 @@
setTimeout(() => { refresh() }, 15000) setTimeout(() => { refresh() }, 15000)
} }
document.getElementById('scbar_txt').value = "订单 第"+(checkTimes+1)+"次 检查中..." document.getElementById('scbar_txt').value = "订单 第"+(checkTimes+1)+"次 检查中..."
let result = await fetch('https://s.yumc.pw/mcbbs/needSendOrder').then(r => r.json()) let result = await fetch(gateway + '/mcbbs/needSendOrder').then(r => r.json())
if (result.code != 200) { if (result.code != 200) {
if (++checkTimes > 10 || back) { if (checkTimes++ > 10 || back) {
refresh() refresh()
} }
clearTimeout(timeoutTask) clearTimeout(timeoutTask)
@ -212,7 +214,7 @@
} }
let order = result.data let order = result.data
if (store.getItem(lastOrderKey) == order.order_id) { if (store.getItem(lastOrderKey) == order.order_id) {
let finish = await fetch('https://s.yumc.pw/mcbbs/updateOrder', { let finish = await fetch(gateway + '/mcbbs/updateOrder', {
method: "POST", method: "POST",
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',
@ -268,7 +270,7 @@
if (!info && !error) { if (!info && !error) {
store.setItem(lastOrderKey, order.order_id) store.setItem(lastOrderKey, order.order_id)
} }
let finish = await fetch('https://s.yumc.pw/mcbbs/updateOrder', { let finish = await fetch(gateway + '/mcbbs/updateOrder', {
method: "POST", method: "POST",
headers: { headers: {
'Accept': 'application/json', 'Accept': 'application/json',