更新 'mcbbs/vending-machine.user.js'
This commit is contained in:
parent
2449b12d17
commit
a1651e690d
@ -1,7 +1,7 @@
|
|||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name MCBBS自动售卖机
|
// @name MCBBS自动售卖机
|
||||||
// @namespace http://tampermonkey.net/
|
// @namespace http://tampermonkey.net/
|
||||||
// @version 0.1
|
// @version 0.2
|
||||||
// @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 @@
|
|||||||
return new Promise((resolve, reject) => setTimeout(resolve, time))
|
return new Promise((resolve, reject) => setTimeout(resolve, time))
|
||||||
}
|
}
|
||||||
async function main() {
|
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 }, {})
|
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)
|
||||||
@ -30,45 +31,57 @@
|
|||||||
await logAction(params)
|
await logAction(params)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
} catch (ex) {
|
||||||
|
await sleep(1500)
|
||||||
|
location.href = '/home.php?mod=magic&action=mybox'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
async function shopAction() {
|
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() {
|
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() {
|
async function lowStockNotify() {
|
||||||
await fetch('https://reward.yumc.pw/mcbbs/lowStockNotify').then(r => r.json())
|
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) {
|
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) {
|
async function sendOrderAction(openFn, back = false) {
|
||||||
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) {
|
if (++checkTimes > 30 || back) {
|
||||||
location.href = '/home.php?mod=magic&action=mybox'
|
location.href = '/home.php?mod=magic&action=mybox'
|
||||||
}
|
}
|
||||||
return setTimeout(() => sendOrderAction(openFn), 15000)
|
return setTimeout(() => sendOrderAction(openFn), 15000)
|
||||||
}
|
}
|
||||||
try { openFn() } catch (ex) { }
|
try { openFn() } catch (ex) { }
|
||||||
let order = result.data
|
let order = result.data
|
||||||
if (store.getItem(lastOrderKey) == order.order_id) {
|
// if (store.getItem(lastOrderKey) == order.order_id) {
|
||||||
console.error('重复发送订单: ' + order.order_id + ' 5秒后刷新重试...')
|
// console.error('重复发送订单: ' + order.order_id + ' 5秒后刷新重试...')
|
||||||
duplicateNotify(order.order_id)
|
// duplicateNotify(order.order_id)
|
||||||
return setTimeout(() => location.href = '/home.php?mod=magic&action=mybox', 5000)
|
// await sleep(5000)
|
||||||
}
|
// return location.href = '/home.php?mod=magic&action=mybox'
|
||||||
|
// }
|
||||||
console.log(`开始发送订单 ${order.order_id}`)
|
console.log(`开始发送订单 ${order.order_id}`)
|
||||||
let username = undefined
|
let username = undefined
|
||||||
while ((username = jq('#selectedusername')[0]) == undefined) {
|
while ((username = jq('#selectedusername')[0]) == undefined) {
|
||||||
if (count > 5) {
|
if (count > 3) {
|
||||||
console.log('检测窗口超时!')
|
console.log('检测窗口超时!')
|
||||||
if (!back) {
|
if (!back) {
|
||||||
if (order.allowAutoBuy) {
|
if (order.allowAutoBuy) {
|
||||||
|
await clearOrderCache()
|
||||||
|
await sleep(1500)
|
||||||
location.href = '/home.php?mod=magic&action=shop'
|
location.href = '/home.php?mod=magic&action=shop'
|
||||||
} else {
|
} else {
|
||||||
lowStockNotify()
|
await lowStockNotify()
|
||||||
|
await sleep(10000)
|
||||||
|
location.href = '/home.php?mod=magic&action=mybox'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -91,6 +104,18 @@
|
|||||||
while ((info = jq('.alert_info').text()) == '') {
|
while ((info = jq('.alert_info').text()) == '') {
|
||||||
if (count > 5) {
|
if (count > 5) {
|
||||||
error = jq('#ntcwin').text()
|
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
|
break
|
||||||
}
|
}
|
||||||
await sleep(1000)
|
await sleep(1000)
|
||||||
@ -114,7 +139,7 @@
|
|||||||
console.log(ex)
|
console.log(ex)
|
||||||
}
|
}
|
||||||
await sleep(800)
|
await sleep(800)
|
||||||
if (back) {
|
if (back || error) {
|
||||||
return location.href = '/home.php?mod=magic&action=mybox'
|
return location.href = '/home.php?mod=magic&action=mybox'
|
||||||
}
|
}
|
||||||
jq('#fwin_dialog_submit').click()
|
jq('#fwin_dialog_submit').click()
|
||||||
|
Loading…
Reference in New Issue
Block a user