From 3997dafb605bdd63cee8c7e693608be298a8249c Mon Sep 17 00:00:00 2001 From: 502647092 Date: Sun, 10 Jan 2021 03:34:42 +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 | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/mcbbs/fetch-emerald.user.js b/mcbbs/fetch-emerald.user.js index 3ce1b3c..70d9d25 100644 --- a/mcbbs/fetch-emerald.user.js +++ b/mcbbs/fetch-emerald.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name 自动抓取用户信息 // @namespace https://miaowoo.cc/ -// @version 0.3 +// @version 0.4 // @description 自动抓取用户信息 // @author MiaoWoo // @match https://www.mcbbs.net/forum.php?mod=viewthread&tid=** @@ -12,11 +12,13 @@ (function () { 'use strict' + let store = window.localStorage 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) + post('update', { + "uid": parseInt(uid), + "username": username, + "glod": parseInt(glod), + "emerald": parseInt(emerald), }) } function readUserInfo(user) { @@ -26,7 +28,17 @@ postUserInfo(userline.href.split('uid=')[1].split('&')[0], userline.innerText, scoreInfo.children[1].innerText, scoreInfo.children[3].innerText) } function readAllUserInfo() { - document.querySelectorAll('div.pls').forEach(readUserInfo) + 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] @@ -54,6 +66,16 @@ } }) } + 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) }