diff --git a/mcbbs/server-bump.user.js b/mcbbs/server-bump.user.js index ff9bab6..9b63f2b 100644 --- a/mcbbs/server-bump.user.js +++ b/mcbbs/server-bump.user.js @@ -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() })()