Rush lecture

【深圳大学2020级新生专用/使用前请看使用说明】可用于抢领航讲座,由于无法进行测试,大家请抱着试用的心态使用该脚本。

Version vom 02.12.2020. Aktuellste Version

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Rush lecture
// @name:en      Rush lecture
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  【深圳大学2020级新生专用/使用前请看使用说明】可用于抢领航讲座,由于无法进行测试,大家请抱着试用的心态使用该脚本。
// @description:en 【深圳大学2020级新生专用/使用前请看使用说明】可用于抢领航讲座,由于无法进行测试,大家请抱着试用的心态使用该脚本。
// @author       cc
// @match        http://lecture.szu.edu.cn/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const IS_LIHU_AREA = false;
    location.area = ['粤海校区', '沧海校区'];
    function sendRequest (url, params='', mode='GET') {
        let request = new XMLHttpRequest();
        request.open(mode, url, true);
        request.setRequestHeader('Content-Type', 'application/json');
        request.send(params);
        request.onreadystatechange = function () {
            if (request.readyState == 4 && request.status == 200) {
                location.ans = request.responseText;
            };
        };
    };
    function getStartTime() {
        let currentTime = new Date();
        let year = currentTime.getFullYear();
        let month = currentTime.getMonth() + 1;
        let day = currentTime.getDate();
        let startTime = new Date(`${year}-${month}-${day} 12:30:00`);
        return startTime.getTime();
    };
    function searchCourse() {
        location.ans = undefined;
        let listUrl = 'http://lecture.szu.edu.cn/tLectureSignUp/list?page=1&limit=20';
        sendRequest(listUrl);
        (function waitListResponse() {
            if (location.ans) {
                let firstItem = JSON.parse(location.ans)['data'][0];
                location.ans = undefined;
                if (firstItem.status == '正在报名中') {
                    let lectureId = firstItem.id;
                    let signUpUrl = `http://lecture.szu.edu.cn/lectureClassroomSignUp/list?page=1&limit=20&lectureId=${lectureId}`;
                    sendRequest(signUpUrl);
                    (function waitSignUpResponse() {
                        if (location.ans) {
                            let reservedSeats = JSON.parse(location.ans)['data'];
                            location.ans = undefined;
                            let availableReservedSeats = [];
                            for (let reservedSeat of reservedSeats) {
                                if (location.area.includes(reservedSeat.campus)) {
                                    availableReservedSeats.push(reservedSeat);
                                };
                            };
                            if (availableReservedSeats.length > 0) {
                                let iframe = window.frames[1].document;
                                let course = iframe.querySelector('.layui-table-box .layui-table-main table tr:first-child td:last-child a');
                                if (course) {
                                    course.click();
                                    (function waitFrame() {
                                        if (window.frames.length > 2) {
                                            let innerIframe = window.frames[2].document;
                                            let seats = innerIframe.querySelectorAll('.layui-table-box .layui-table-main table tr');
                                            if (seats && seats.length > 0) {
                                                let availableSeats =  [];
                                                for (let seat of seats) {
                                                    let a = seat.querySelector('td:last-child a');
                                                    if (!a.classList.contains('layui-btn-disabled')) {
                                                        availableSeats.push(a);
                                                    };
                                                };
                                                if (availableSeats.length > 0) {
                                                    let a = availableSeats[0];
                                                    a.click();
                                                    (function waitClick() {
                                                        if (a.innerHTML == '已报名') {
                                                            console.log('已经抢到领航讲座 (code: 5)');
                                                        } else {
                                                            setTimeout(waitClick, 50);
                                                        };
                                                    })();
                                                } else {
                                                    console.log('已经没有可抢位置 (code: 4)');
                                                };
                                            } else {
                                                setTimeout(waitFrame, 50);
                                            };
                                        } else {
                                            setTimeout(waitFrame, 50);
                                        };
                                    })();
                                } else {
                                    console.log('找不到课程列表,请重试 (code: 3)');
                                };
                            } else {
                                console.log('所在校区没有位置 (code: 2)');
                            };
                        } else {
                            setTimeout(waitSignUpResponse, 50);
                        };
                    })();
                } else if (firstItem.status == '报名待启动') {
                    let currentTime = new Date().getTime();
                    let startTime = getStartTime();
                    if (Math.abs(currentTime - startTime) < 3 * 1000) {
                        location.reload();
                    };
                } else {
                    console.log('暂无可报名的领航讲座 (code: 1)');
                };
            } else {
                setTimeout(waitListResponse, 50);
            };
        })();
    };
    function exec() {
        if (IS_LIHU_AREA) {
            location.area = ['丽湖校区'];
        };
        let startTime = getStartTime();
        let currentTime = new Date().getTime();
        if (currentTime < startTime) {
            let deltaTime = startTime - currentTime;
            setTimeout(() => {
                location.reload();
            }, deltaTime);
        } else {
            searchCourse();
        };
    };
    exec();
})();