North-Plus Auto Task

自动领取和完成北+日常和周常任务

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         North-Plus Auto Task
// @namespace    https://github.com/starliiit
// @version      0.5.2
// @description  自动领取和完成北+日常和周常任务
// @author       sl
// @match        https://*.summer-plus.net
// @match        https://*.summer-plus.net/index.php
// @match        https://*.level-plus.net
// @match        https://*.level-plus.net/index.php
// @match        https://*.white-plus.net
// @match        https://*.white-plus.net/index.php
// @match        https://*.south-plus.net
// @match        https://*.white-plus.net/index.php
// @match        https://*.imoutolove.me
// @match        https://*.imoutolove.me/index.php
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==

(function () {
    'use strict';

    // Your code here...

    const LOGIN_SPAN_ID = 'login_0';

    const TASK_BASEURL = 'plugin.php?H_name=tasks&action=ajax&actions=job&cid=';
    const REWARD_BASEURL = 'plugin.php?H_name=tasks&action=ajax&actions=job2&cid=';

    const DAILY_ID = '15';
    const WEEKLY_ID = '14';

    const TASK_DAILY_KEY = 'lastTaskDaily';
    const TASK_WEEKLY_KEY = 'lastTaskWeekly';

    const HOUR = 1000 * 60 * 60;
    const DAILY_INTERVAL = HOUR * 18;

    // const WEEKLY_INTERVAL = HOUR * 158;
    const WEEKLY_INTERVAL = DAILY_INTERVAL;

    const TIME_BEING_GRACEFUL = 1500;


    function checkTask(now, taskID, taskKey, taskInterval) {
        let lastSignIn = GM_getValue(taskKey);
        if (lastSignIn === undefined || (now - lastSignIn) > taskInterval) {
            // 领取任务
            ajax.send(TASK_BASEURL + taskID, '', function () {
                console.log(ajax.request.responseText);

                setTimeout(function () {
                    // 等 1.5s,领取奖励
                    ajax.send(REWARD_BASEURL + taskID, '', function () {
                        console.log(ajax.request.responseText);
                        GM_setValue(taskKey, now);
                    });
                }, TIME_BEING_GRACEFUL);

            });
        }
        else {
            // do nothing.
            let interval = (now - lastSignIn) / (HOUR);
            console.log('距离上次任务过了 ' + interval.toFixed(2) + ' 小时');
        }
    }

    // 检查是否已经登录
    if(document.getElementById(LOGIN_SPAN_ID) === null) {

        let now = Date.now();
        checkTask(now, DAILY_ID, TASK_DAILY_KEY, DAILY_INTERVAL);
        setTimeout(function () {
            checkTask(now, WEEKLY_ID, TASK_WEEKLY_KEY, WEEKLY_INTERVAL);
        }, TIME_BEING_GRACEFUL);

    }


})();