清水河畔自动领奖

自动领奖

目前为 2022-11-12 提交的版本。查看 最新版本

// ==UserScript==
// @name         清水河畔自动领奖
// @namespace    http://tampermonkey.net/
// @version      0.3.1
// @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
// ==/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')
        let post_params = unsafeWindow.upload.settings.post_params;
        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

                    let lastRewardTime = GM_getValue("lastRewardTime", 0)
                    let lastRewardReply = GM_getValue("lastRewardReply", 0)

                    let postLink = GM_getValue('postLink', null)

                    if (requiredReply <= 10 && rewardReply != lastRewardReply) {
                        notice(`距离领水仅差${requiredReply}帖`)
                    }
                    if (requiredTime <= 1 && rewardTime != lastRewardTime) {
                        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...
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址