// ==UserScript== // @name 清水河畔领奖提醒 // @namespace http://tampermonkey.net/ // @version 0.4 // @description 自动领奖提醒 // @author DARK-FLAME-MASTER FROM RIVERSIDE // @match *://*.uestc.edu.cn/forum.php?mod=viewthread* // @icon https://www.google.com/s2/favicons?sz=64&domain=uestc.edu.cn // @require https://cdn.bootcdn.net/ajax/libs/dom-to-image/2.6.0/dom-to-image.min.js // @grant GM_setValue // @grant GM_getValue // @grant unsafeWindow // @license MIT // @downloadURL none // ==/UserScript== (function () { 'use strict'; //const rewardPost = "https://bbs.uestc.edu.cn/forum.php?mod=post&action=reply&fid=42&tid=463952&extra=&replysubmit=yes" function getReward(postLink, type, post_params) { let ele = document.querySelector("table.plhin > tbody > tr > td") let temp = ele.innerHTML return fetch(postLink) .then(data => data.text()) .then(data => { let doc = new DOMParser().parseFromString(data, 'text/html') let info = doc.querySelector("table.plhin > tbody > tr > td") ele.innerHTML = info.innerHTML return domtoimage.toBlob(ele) }) .then(blob => { ele.innerHTML = temp let img = new File([blob], "reward.png", { type: "image/png" }) let fd = new FormData(); fd.append('uid', post_params.uid) fd.append('hash', post_params.hash) fd.append("type", "image"); fd.append("filetype", "png"); fd.append("Filename", "reward.png") fd.append("Filedata", img) fetch("https://bbs.uestc.edu.cn/misc.php?mod=swfupload&action=swfupload&operation=upload&fid=42&html5=image", { "headers": { }, "body": fd, "method": "POST", }).then(data => data.text()) .then(aid => { let formhash = document.querySelector("#scbar_form > input[name=formhash]").value let message = `吾名乃${document.querySelector("#toptb > div.y > strong > a").text},特来此帖取${type.data + (type.name == 'time' ? '小时' : '帖')}奖励` //let message = "测试" return fetch(rewardPost, { "headers": { "content-type": "application/x-www-form-urlencoded", }, "body": `formhash=${formhash}&message=${message}&attachnew[${aid}][description]=`, "method": "POST", }); }) }) } function notice(message) { Notification.requestPermission().then((result) => { if (result === 'granted') { let n = new Notification(message) } }) } function init() { if (!GM_getValue('postLink', null)) { fetch('https://bbs.uestc.edu.cn/home.php?mod=space&do=thread&view=me') .then(data => data.text()) .then(data => { let doc = new DOMParser().parseFromString(data, 'text/html') let postLink = doc.querySelector("#delform > table > tbody > tr:nth-child(2) > th > a").href GM_setValue('postLink', postLink) }) } } function checkAndGetReward() { let link = document.querySelector('#toptb > div.y > strong > a') if (link) { fetch(link.href + '&do=profile') .then(data => data.text()) .then(text => { let reply = parseInt(text.match(/回帖数 (\d+)/)[1]) + parseInt(text.match(/主题数 (\d+)/)[1]) let online = parseInt(text.match(/在线时间<\/em>(\d+)/)[1]) let rewardReply = Math.round(reply / 5000) * 5000 let rewardTime = Math.round(online / 500) * 500 let requiredReply = rewardReply - reply let requiredTime = rewardTime - online if (requiredReply >= -50 && requiredReply <= 10) { notice(`距离领水仅差${requiredReply}帖`) } if (requiredTime >= -20 && requiredTime <= 1) { notice(`距离领水仅差${requiredTime}小时`) } /* if (requiredReply >= -50 && requiredReply <= 0 && rewardReply != lastRewardReply) { getReward(postLink, { name: 'reply', data: rewardReply }, post_params) .then((a) => { notice(`已自动领取${rewardReply}帖奖励`) GM_setValue("lastRewardReply", rewardReply) }) } if (requiredTime >= -20 && requiredTime <= 0 && rewardTime != lastRewardTime) { getReward(postLink, { name: 'time', data: rewardTime }, post_params) .then((a) => { notice(`已自动领取${rewardTime}小时奖励`) GM_setValue("lastRewardTime", rewardTime) }) } */ }) } } //init() checkAndGetReward() setInterval(checkAndGetReward, 1000 * 60 * 10) // Your code here... })();