1
0
Fork 0

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

master
502647092 2020-12-11 02:50:41 +00:00
parent 310a76d51d
commit dee9fb2acd
1 changed files with 9 additions and 3 deletions

View File

@ -13,6 +13,7 @@
const lastOrderKey = 'circlebox:lastorder' const lastOrderKey = 'circlebox:lastorder'
let checkTimes = 0 let checkTimes = 0
let stock = 0 let stock = 0
let messagetext = undefined
async function sleep(time) { async function sleep(time) {
return new Promise((resolve, reject) => setTimeout(resolve, time)) return new Promise((resolve, reject) => setTimeout(resolve, time))
} }
@ -21,6 +22,13 @@
let params = location.href.split('?')[1].split('&').map(s => s.split('=')).reduce((pre, cur, index) => { pre[cur[0]] = cur[1]; return pre }, {}) 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' } if (!params.action) { return location.href = '/home.php?mod=magic&action=mybox' }
console.log(params) console.log(params)
messagetext = document.getElementById('messagetext')
if (messagetext) {
updateStatus(messagetext.innerText)
return
} else {
updateStatus('')
}
switch (params.action || "shop") { switch (params.action || "shop") {
case "shop": case "shop":
await shopAction(params) await shopAction(params)
@ -78,12 +86,10 @@
} }
async function sendOrderAction(openFn, back = false) { async function sendOrderAction(openFn, back = false) {
let timeoutTask = setTimeout(() => { location.href = '/home.php?mod=magic&action=mybox' }, 120000) let timeoutTask = setTimeout(() => { location.href = '/home.php?mod=magic&action=mybox' }, 120000)
let messagetext = document.getElementById('messagetext')
updateStatus(messagetext && messagetext.innerText || '')
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 > 5 || back) {
location.href = '/home.php?mod=magic&action=mybox' location.href = '/home.php?mod=magic&action=mybox'
} }
clearTimeout(timeoutTask) clearTimeout(timeoutTask)