From 58df4552517d6e437e209b3a757eda8d13a3b426 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Wed, 2 Sep 2020 08:40:28 +0000 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'mcbbs/fetch-emerald.user.?= =?UTF-8?q?js'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mcbbs/fetch-emerald.user.js | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/mcbbs/fetch-emerald.user.js b/mcbbs/fetch-emerald.user.js index 4d6a5c1..d874c4c 100644 --- a/mcbbs/fetch-emerald.user.js +++ b/mcbbs/fetch-emerald.user.js @@ -1,32 +1,40 @@ // ==UserScript== // @name 自动抓取用户信息 // @namespace https://miaowoo.cc/ -// @version 0.1 +// @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() { +(function () { 'use strict'; - - function readUserInfo(user){ - var userline = user.querySelector('a.xw1'); - if (!userline) return; - var uid = userline.href.split('uid=')[1]; - var username = userline.innerText; - var glod = user.querySelectorAll('dl.pil')[0].children[1].innerText; - var emerald = user.querySelectorAll('dl.pil')[0].children[3].innerText; - fetch('https://reward.yumc.pw/mcbbs/update/uid/'+uid+'/username/'+username+'/glod/'+parseInt(glod)+'/emerald/'+parseInt(emerald)).then(function(response) { + 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) { + }).then(function (result) { console.log(result); }); } - function readAllUserInfo(){ + 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); } - setTimeout(readAllUserInfo, 200); + 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); })(); \ No newline at end of file