Greasy Fork

mcbbs 自动领取任务

自动领取任务。

当前为 2022-05-20 提交的版本,查看 最新版本

// ==UserScript==
// @name         mcbbs 自动领取任务
// @version      0.9.1
// @include      https://www.mcbbs.net/*
// @author       xmdhs
// @description  自动领取任务。
// @namespace https://greasyfork.org/users/166541
// ==/UserScript==

(function () {
    let times = localStorage.getItem("autoapply")
    if (Math.round(new Date().getTime() / 1000) - times >= 60) {
        localStorage.setItem("autoapply", Math.round(new Date().getTime() / 1000))
    } else {
        return
    }
    let url = document.querySelector(`#user_info_menu > ul.user_info_menu_btn > li > a[href^="member.php?mod=logging"]`).href
    let u = new URL(url)
    const key = u.searchParams.get("formhash")

    sign()
    async function sign() {
        await sleep(1000);
        run(key, "39", "draw");
        run(key, "22", "draw");
        run(key, "40", "draw");
        run(key, "24", "draw");
        await sleep(2000);
        run(key, "24", "apply");
        run(key, "39", "apply");
        run(key, "22", "apply");
        run(key, "40", "apply");
    }

    async function sleep(t) {
        return new Promise((rs, rj) => {
            setTimeout(rs, t)
        })
    }

    function run(key, a, type) {
        return fetch("home.php?mod=task&do=" + type + "&id=" + a + "&hash=" + key, { credentials: "same-origin" })
    }
}
)();