1
0
Fork 0

feat: 更新脚本

master
502647092 2021-03-13 06:12:34 +00:00
parent 7535550630
commit bbea25c48f
1 changed files with 21 additions and 4 deletions

View File

@ -1,15 +1,16 @@
// ==UserScript==
// @name 圈云盒子顶帖器
// @namespace https://circlecloud.ltd/
// @version 0.1
// @version 0.1.1
// @description 自动顶贴
// @author MiaoWoo
// @match https://www.mcbbs.net/forum-server-1.html
// @match https://www.mcbbs.net/forum-server-1.html**
// @grant none
// ==/UserScript==
/* global jq */
(function () {
'use strict'
let store = window.localStorage
let nextPage = undefined
async function sleep(time) {
return new Promise((resolve, reject) => setTimeout(resolve, time))
@ -28,6 +29,7 @@
let line = server.nextElementSibling
serverInfo.tid = parseInt(line.children[0].id.split('_')[1])
serverInfo.title = line.children[3].innerText
serverInfo.view = line.parentNode.children[3].children[1].innerText
let timeInfo = line.parentNode.children[4].children[1].children[0].children[0]
if (timeInfo) {
serverInfo.lastpost_time = timeInfo.title
@ -50,11 +52,26 @@
}).then(r => r.json())
}
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 }, {}) || {}
nextPage = document.getElementById('autopbn')
post('alive', { type: 'servers' })
let servers = await readServers()
await post('updateServers', servers)
if (store.lastPostServer != servers[25].tid) {
await post('updateServers', servers)
}
store.lastPostServer = servers[25].tid
if (!params.autoRefresh) { return }
console.log('数据上报完成 已开启自动刷新!')
await sleep(60000)
location.href = 'https://www.mcbbs.net/forum-server-1.html'
refresh()
}
async function refresh() {
try {
await fetch('/api/mobile/index.php?version=4&module=credit')
location.href = 'https://www.mcbbs.net/forum-server-1.html?autoRefresh=true'
} catch (error) {
setTimeout(refresh, 5000)
}
}
main()
})()