83 lines
3.4 KiB
JavaScript
83 lines
3.4 KiB
JavaScript
// ==UserScript==
|
|
// @name 自动抓取用户信息
|
|
// @namespace https://miaowoo.cc/
|
|
// @version 0.4
|
|
// @description 自动抓取用户信息
|
|
// @author MiaoWoo
|
|
// @match https://www.mcbbs.net/forum.php?mod=viewthread&tid=**
|
|
// @match https://www.mcbbs.net/thread-**-*-*.html
|
|
// @match https://www.mcbbs.net/home.php?mod=space&uid=**
|
|
// @grant none
|
|
// ==/UserScript==
|
|
|
|
(function () {
|
|
'use strict'
|
|
let store = window.localStorage
|
|
function postUserInfo(uid, username, glod, emerald) {
|
|
post('update', {
|
|
"uid": parseInt(uid),
|
|
"username": username,
|
|
"glod": parseInt(glod),
|
|
"emerald": parseInt(emerald),
|
|
})
|
|
}
|
|
function readUserInfo(user) {
|
|
var userline = user.querySelector('a.xw1')
|
|
if (!userline) return
|
|
var scoreInfo = user.querySelectorAll('dl.pil')[0]
|
|
postUserInfo(userline.href.split('uid=')[1].split('&')[0], userline.innerText, scoreInfo.children[1].innerText, scoreInfo.children[3].innerText)
|
|
}
|
|
function readAllUserInfo() {
|
|
if (location.href == 'https://www.mcbbs.net/thread-1121423-1-1.html') {
|
|
console.log("已开启自动刷新...")
|
|
setTimeout(function () {
|
|
location.href = location.href
|
|
}, 20000)
|
|
}
|
|
let users = document.querySelectorAll('div.pls')
|
|
let lastpostuser = users[1].querySelector('a.xw1').innerText
|
|
if (store.lastpostuser == lastpostuser) return
|
|
store.lastpostuser = lastpostuser
|
|
users.forEach(readUserInfo)
|
|
}
|
|
function readSingleUserInfo() {
|
|
var uid = location.href.split('uid=')[1].split('&')[0]
|
|
var username = document.querySelector('.mt').outerText
|
|
var scoreInfo = document.querySelector('#psts').querySelector('.pf_l')
|
|
var glod = scoreInfo.children[3].innerText.replace(scoreInfo.children[3].children[0].innerText, '')
|
|
var emerald = scoreInfo.children[5].innerText.replace(scoreInfo.children[5].children[0].innerText, '')
|
|
postUserInfo(uid, username, glod, emerald)
|
|
}
|
|
setTimeout(location.pathname == "/home.php" ? readSingleUserInfo : readAllUserInfo, 200)
|
|
function addiFrame(url) {
|
|
var body = document.getElementsByTagName("body")
|
|
var div = document.createElement("div")
|
|
div.innerHTML = '<iframe src="' + url + '" height = "0" width = "0" frameborder="0" scrolling="auto" style = "display:none;visibility:hidden" ></iframe>'
|
|
document.body.appendChild(div)
|
|
}
|
|
function updateOldUserInfo() {
|
|
fetch('https://reward.yumc.pw/mcbbs/updateList').then(function (response) {
|
|
return response.json()
|
|
}).then(function (result) {
|
|
if (result.code == 200 && result.data && result.data.length) {
|
|
result.data.forEach(function (user) {
|
|
addiFrame(`https://www.mcbbs.net/home.php?mod=space&uid=${user.uid}`)
|
|
})
|
|
}
|
|
})
|
|
}
|
|
async function post(method, data) {
|
|
return await fetch('https://reward.yumc.pw/mcbbs/' + method, {
|
|
method: "POST",
|
|
headers: {
|
|
'Accept': 'application/json',
|
|
'Content-Type': 'application/json'
|
|
},
|
|
body: JSON.stringify(data)
|
|
}).then(r => r.json())
|
|
}
|
|
if (window.parent == window) {
|
|
setTimeout(updateOldUserInfo, 3000)
|
|
}
|
|
})()
|