UserScript/mcbbs/fetch-emerald.user.js

40 lines
1.8 KiB
JavaScript

// ==UserScript==
// @name 自动抓取用户信息
// @namespace https://miaowoo.cc/
// @version 0.2
// @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';
function postUserInfo(uid, username, glod, emerald) {
fetch('https://reward.yumc.pw/mcbbs/update/uid/' + uid + '/username/' + username + '/glod/' + parseInt(glod) + '/emerald/' + parseInt(emerald)).then(function (response) {
return response.json();
}).then(function (result) {
console.log(result);
});
}
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], userline.innerText, scoreInfo.children[1].innerText, scoreInfo.children[3].innerText);
}
function readAllUserInfo() {
document.querySelectorAll('div.pls').forEach(readUserInfo);
}
function readSingleUserInfo() {
var uid = location.href.split('uid=')[1];
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);
})();