🔥任何网页下完成🔥52破解论坛自动签到

在任何网页下完成吾爱破解论坛签到, 使用了tampermonkey进行跨域请求, 弹出提示请选择"总是允许域名"

As of 2020-08-28. See the latest version.

// ==UserScript==
// @name         🔥任何网页下完成🔥52破解论坛自动签到
// @namespace    https://greasyfork.org/zh-CN/users/412790
// @version      1.0.0.0
// @description  在任何网页下完成吾爱破解论坛签到, 使用了tampermonkey进行跨域请求, 弹出提示请选择"总是允许域名"
// @require      https://cdn.jsdelivr.net/npm/sweetalert2@9
// @author       Permission
// @match        http://*/*
// @match        https://*/*
// @grant        GM_xmlhttpRequest
// @grant        GM_setValue
// @grant        GM_getValue
// @noframes
// ==/UserScript==
/* global Swal */
const tz_offset = new Date().getTimezoneOffset() + 480;

const checkNewDay = (ts) => {
    // 检查是否为新的一天,以UTC+8为准
    const t = new Date(ts);
    t.setMinutes(t.getMinutes() + tz_offset);
    t.setHours(0, 0, 0, 0);
    const d = new Date();
    d.setMinutes(t.getMinutes() + tz_offset);
    return (d - t > 86400e3);
};

const sign = () => {
    if (GM_getValue("notified")) {
        sendRequest();
    }
    else {
        Swal.fire(`由于脚本使用了tampermonkey进行跨域请求, 弹出提示请选择"总是允许域名"`).then(() => {
            GM_setValue("notified", true);
            sendRequest();
        })
    }
};

const sendRequest = () => {
    GM_xmlhttpRequest({
        method: "GET",
        url: "https://www.52pojie.cn/home.php?mod=task&do=apply&id=2",
        timeout: 10e3,
        onload: function (response) {
            response = response.response;
            if(response.match("任务已完成")!==null){
                Swal.fire({
                    icon: 'success',
                    title: '52破解论坛自动签到',
                    html: `<div><strong>成功!</strong><br>喜欢的话可以请我喝一杯咖啡哦~<img style="width:100%!important;height:100%!importent!" src='https://i.loli.net/2020/04/13/EBpmgMvVLlKFux1.png'></div>`
                });
                GM_setValue("ts", Date.now());
            }
            else if(response.match("您已申请过此任务")!==null){
                Swal.fire({
                    icon: 'warning',
                    title: '52破解论坛自动签到',
                    text: '您已经签到过了!'
                });
                GM_setValue("ts", Date.now());
            }
            else if(response.match("您需要先登录才能继续本操作")!==null){
                Swal.fire({
                    icon: 'error',
                    title: '52破解论坛自动签到',
                    text: '您需要先登录才能继续本操作!'
                });
            }
            else{
                Swal.fire({
                    icon: 'error',
                    title: '52破解论坛自动签到',
                    text: '未知返回信息❗ 请打开控制台查看详情。'
                });
                console.log(response);
            }
        },
        onerror: function () {
            Swal.fire({
                icon: 'error',
                title: '52破解论坛自动签到',
                text: '请求签到时发生错误, 请检查网络或代理, 防火墙等',
            });
        }
    });
};

window.onload = () => {
    if (!GM_getValue("ts") || checkNewDay(GM_getValue("ts"))) {
        sign();
    }
};