Greasy Fork

通用_自动签到

自动或半自动地签到。

当前为 2023-01-21 提交的版本,查看 最新版本

// ==UserScript==
// @name               通用_自动签到
// @name:zh-CN         通用_自动签到
// @name:en-US         Uni_Auto sign
// @description        自动或半自动地签到。
// @version            2.0.1
// @author             LiuliPack
// @license            WTFPL
// @namespace          https://gitlab.com/LiuliPack/UserScript
// @match              *://*/*
// @run-at             document-end
// ==/UserScript==

/* 参数示范 / Config demo
"网页链接": {
    "remark": "备注",
    "check": ["元素外层容器", "元素自身", "元素文本或元素参数键", "元素参数值"],
    "getBonuses": [
        ["元素", "等待"]
    ],
    "refresh": "刷新",
    "close": "关闭"
},
"URL": {
    "remark": "remark",
    "check": ["Ele Wrap", "Ele Self", "Ele Text or Ele Attr Name", "Ele Param-val"],
    "getBonuses": [
        ["Ele", "delay"]
    ],
    "refresh": true,
    "close": true
},
*/

'use strict';

// 定义参数(cfg)、网页标题(title)和网页链接(URL)变量,元素快捷选取($(元素定位符))、消息提醒(notify)函数
let $ = ele => document.querySelector(ele),
    title = document.title,
    notify = msg => { document.title = `[${msg}]${title}` },
    cfg = {
        "https://www.hmoe11.net/author/732546": {
            "remark": "萌幻之乡",
            "check": [".inn-nav-tool__container", "#inn-nav__point-sign-daily .poi-tooltip"],
            "getBonuses": [
                ["#inn-nav__point-sign-daily .poi-tooltip", 500]
            ],
            "refresh": true,
            "close": true
        },
        "https://bbs.acgrip.com/dsu_paulsign-sign.html": {
            "remark": "Anime 字幕论坛_签到插件",
            "check": ["#ct", "#shuai_menu + table .tac a"],
            "getBonuses": [
                ["#yl", 0],
                ["#qiandao > table.tfm > tbody > tr:nth-child(1) > td > label:nth-child(3) > input[type=radio]", 0],
                ["#shuai_menu + table .tac a", 0]
            ],
            "refresh": true,
            "close": true
        },
        "https://bbs.acgrip.com/home.php?mod=task": {
            "remark": "Anime 字幕论坛_Discuz 任务",
            "check": ["#ct", "#ct a[href='home.php?mod=task&do=apply&id=1']"],
            "getBonuses": [
                ["#ct a[href='home.php?mod=task&do=apply&id=1']", 0]
            ],
            "refresh": false,
            "close": true
        },
        "https://www.2dfan.com/": {
            "remark": "2DFun",
            "check": ["#sidebar .block-content.collapse.in", "#do_checkin"],
            "getBonuses": [
                ["#do_checkin", 0]
            ],
            "refresh": true,
            "close": true
        },
        "https://www.south-plus.net/plugin.php?H_name-tasks.html": {
            "remark": "南+_接任务",
            "check": ["#main > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > div:nth-child(2) > table:nth-child(1)", "#p_15 a", "title", "按这申请此任务"],
            "getBonuses": [
                ["#p_11 a", 0],
                ["#p_15 a", 0],
                ["#p_19 a", 0],
                ["tr.tr3:nth-child(3) > td:nth-child(1) > a:nth-child(1)", 0],
            ],
            "refresh": false,
            "close": true
        },
        "https://www.south-plus.net/plugin.php?H_name-tasks-actions-newtasks.html.html": {
            "remark": "南+_完成任务",
            "check": ["#main > table:nth-child(2) > tbody:nth-child(1) > tr:nth-child(1) > td:nth-child(2) > div:nth-child(2)", "#both_15 a", "title", "领取此奖励"],
            "getBonuses": [
                ["#both_11 a", 0],
                ["#both_15 a", 0],
                ["#both_19 a", 0],
            ],
            "refresh": false,
            "close": true
        },
    },
    URL = location.href;

function $$(ele) {
    return new Promise(resolve => {
        if ($(ele)) {
            return resolve($(ele));
        }
        const observer = new MutationObserver(mutations => {
            if ($(ele)) {
                resolve($(ele));
                observer.disconnect();
            }
        })
        observer.observe(document.body, {
            childList: true,
            subtree: true
        })
    })
}

// 如果匹配网页、
if(cfg[URL]) {
    // 当指定元素存在
    notify('检测状态');
    $$(cfg[URL].check[0]).then(() => {
        // 如果检查项为 2 且元素存在或检查项为 3 或 4、元素存在且匹配内容
        if(cfg[URL].check.length === 2 && $(cfg[URL].check[1]) ||
           cfg[URL].check.length === 3 && $(cfg[URL].check[1]) && $(cfg[URL].check[1]).textContent === cfg[URL].check[2] ||
           cfg[URL].check.length === 4 && $(cfg[URL].check[1]) && $(cfg[URL].check[1]).getAttribute(cfg[URL].check[2]) === cfg[URL].check[3]) {
            // 遍历按钮
            notify('正在签到');
            cfg[URL].getBonuses.forEach((data, arr) => {
                setTimeout(() => {
                    // 如果按钮存在,就点击
                    $((data[0])) ? $(data[0]).click() : '' ;

                    // 如果遍历到最后一个元素
                    if(cfg[URL].getBonuses.length === (arr - 1)) {
                        // 根据参数刷新和关闭
                        notify('签到过了');
                        (cfg[URL].refresh) ? location.reload() : '' ;
                        (cfg[URL].close) ? window.close() : '';
                    }
                }, data[1])
            })
        }else {
            // 根据参数刷新和关闭
            notify('签到过了');
            (cfg[URL].refresh) ? location.reload() : '' ;
            (cfg[URL].close) ? window.close() : '';
        }
    })
}