添加 'mcbbs/vending-machine.user.js'
This commit is contained in:
parent
405dd2e3b5
commit
2449b12d17
137
mcbbs/vending-machine.user.js
Normal file
137
mcbbs/vending-machine.user.js
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
// ==UserScript==
|
||||||
|
// @name MCBBS自动售卖机
|
||||||
|
// @namespace http://tampermonkey.net/
|
||||||
|
// @version 0.1
|
||||||
|
// @description 自动售卖道具
|
||||||
|
// @author MiaoWoo
|
||||||
|
// @match https://www.mcbbs.net/home.php?mod=magic**
|
||||||
|
// @grant none
|
||||||
|
// ==/UserScript==
|
||||||
|
|
||||||
|
(async function () {
|
||||||
|
let store = window.localStorage
|
||||||
|
const lastOrderKey = 'circlebox:lastorder'
|
||||||
|
let checkTimes = 0
|
||||||
|
async function sleep(time) {
|
||||||
|
return new Promise((resolve, reject) => setTimeout(resolve, time))
|
||||||
|
}
|
||||||
|
async function main() {
|
||||||
|
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' }
|
||||||
|
console.log(params)
|
||||||
|
switch (params.action || "shop") {
|
||||||
|
case "shop":
|
||||||
|
await shopAction(params)
|
||||||
|
break
|
||||||
|
case "mybox":
|
||||||
|
await myboxAction(params)
|
||||||
|
break
|
||||||
|
case "log":
|
||||||
|
await logAction(params)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function shopAction() {
|
||||||
|
sendOrderAction(() => window.showWindow('magics', 'home.php?mod=magic&action=shop&operation=give&mid=mcbbs_mcserver_plus:serverBump'), true)
|
||||||
|
}
|
||||||
|
async function myboxAction() {
|
||||||
|
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 duplicateNotify(order_id) {
|
||||||
|
await fetch('https://reward.yumc.pw/mcbbs/duplicateNotify/order_id' + order_id).then(r => r.json())
|
||||||
|
}
|
||||||
|
async function sendOrderAction(openFn, back = false) {
|
||||||
|
let count = 0
|
||||||
|
let result = await fetch('https://reward.yumc.pw/mcbbs/needSendOrder').then(r => r.json())
|
||||||
|
if (result.code != 200) {
|
||||||
|
if (++checkTimes > 30) {
|
||||||
|
location.href = '/home.php?mod=magic&action=mybox'
|
||||||
|
}
|
||||||
|
return setTimeout(() => sendOrderAction(openFn), 15000)
|
||||||
|
}
|
||||||
|
try { openFn() } catch (ex) { }
|
||||||
|
let order = result.data
|
||||||
|
if (store.getItem(lastOrderKey) == order.order_id) {
|
||||||
|
console.error('重复发送订单: ' + order.order_id + ' 5秒后刷新重试...')
|
||||||
|
duplicateNotify(order.order_id)
|
||||||
|
return setTimeout(() => location.href = '/home.php?mod=magic&action=mybox', 5000)
|
||||||
|
}
|
||||||
|
console.log(`开始发送订单 ${order.order_id}`)
|
||||||
|
let username = undefined
|
||||||
|
while ((username = jq('#selectedusername')[0]) == undefined) {
|
||||||
|
if (count > 5) {
|
||||||
|
console.log('检测窗口超时!')
|
||||||
|
if (!back) {
|
||||||
|
if (order.allowAutoBuy) {
|
||||||
|
location.href = '/home.php?mod=magic&action=shop'
|
||||||
|
} else {
|
||||||
|
lowStockNotify()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
await sleep(1000)
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
username.value = order.reciver_name
|
||||||
|
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}`
|
||||||
|
store.setItem(lastOrderKey, order.order_id)
|
||||||
|
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 > 5) {
|
||||||
|
error = jq('#ntcwin').text()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
await sleep(1000)
|
||||||
|
count++
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
let finish = await fetch('https://reward.yumc.pw/mcbbs/updateOrder', {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({
|
||||||
|
"order_id": order.order_id,
|
||||||
|
"status": error ? 3 : 2,
|
||||||
|
"remark": info || error || "未获取到结果!"
|
||||||
|
})
|
||||||
|
}).then(r => r.json())
|
||||||
|
console.log(finish)
|
||||||
|
} catch (ex) {
|
||||||
|
console.log(ex)
|
||||||
|
}
|
||||||
|
await sleep(800)
|
||||||
|
if (back) {
|
||||||
|
return location.href = '/home.php?mod=magic&action=mybox'
|
||||||
|
}
|
||||||
|
jq('#fwin_dialog_submit').click()
|
||||||
|
}
|
||||||
|
async function logAction(params) {
|
||||||
|
switch (params.operation) {
|
||||||
|
case "givelog":
|
||||||
|
await givelogOperation()
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function givelogOperation() {
|
||||||
|
let logs = jq('table.dt').children().children().map((index, item) => {
|
||||||
|
let line = jq(item).text().split('\n').filter(f => f)
|
||||||
|
return line.join(' ')
|
||||||
|
}).splice(1)//去除第一行无效数据
|
||||||
|
console.log(logs)
|
||||||
|
}
|
||||||
|
main()
|
||||||
|
})()
|
Loading…
Reference in New Issue
Block a user