Grab Lecture in SZU

【使用前先看介绍/有问题可反馈】深圳大学抢领航讲座脚本 (Grab Lecture in SZU):可用于在深圳大学抢领航讲座,目前处于测试阶段。

2021-04-10 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Grab Lecture in SZU
// @namespace    http://tampermonkey.net/
// @version      0.6.2
// @description  【使用前先看介绍/有问题可反馈】深圳大学抢领航讲座脚本 (Grab Lecture in SZU):可用于在深圳大学抢领航讲座,目前处于测试阶段。
// @author       cc
// @match        http://lecture.szu.edu.cn/*
// @require      http://libs.baidu.com/jquery/2.0.0/jquery.min.js
// @require      https://greasyfork.org/scripts/422854-bubble-message.js
// @noframes
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
  'use strict'
  let campus
  let bm = new BubbleMessage()
  bm.config.cmap.info = '#009688'
  bm.config.width = 300
  function getStartTime() {
    let now = new Date()
    let year = now.getFullYear()
    let month = now.getMonth() + 1
    let day = now.getDate()
    let startTime = new Date(`${year}-${month}-${day} 12:30:00`)
    return startTime.getTime()
  }
  function rushLecture() {
    let deltaTime = startTime - currentTime
    bm.message({
      type: 'info',
      message: `将在 ${parseInt(deltaTime / 1000)} 秒后开抢`,
      duration: 3000,
    })
    $.ajax({
      url: 'http://lecture.szu.edu.cn/tLectureSignUp/list?page=1&limit=10',
      type: 'GET',
    }).then(res => {
      if (res.code === 0) {
        let availableLectures = res.data.filter(lecture => Date.now() < new Date(lecture.lectureEndTime))
        Promise.all(availableLectures.map(lecture => {
          return $.ajax({
            url: `http://lecture.szu.edu.cn/lectureClassroomSignUp/list?page=1&limit=20&lectureId=${lecture.id}`,
            type: 'GET',
          }).then(res => {
            return res.code === 0 ? res.data.filter(room => room.remainSeats > 0) : []
          })
        })).then(res => {
          let availableRooms = []
          res.forEach(room => availableRooms.concat(room))
          availableRooms = availableRooms.filter(room => campus.indexOf(room.campus) >= 0)
          if (availableRooms.length === 0) {
            bm.message({
              type: 'warning',
              message: '无可抢讲座',
              duration: 1500,
            })
          } else {
            Promise.all(availableRooms.map(room => {
              return $.ajax({
                url: `http://lecture.szu.edu.cn/tSelectLecture/addItem?lectureClassroomId=${room.id}&lectureId=${room.lectureId}&classroomId=${room.classroomId}`,
                type: 'POST',
              }).then(res => {
                return res
              })
            })).then(res => {
              bm.message({
                type: 'info',
                message: '抢领航讲座已完成,请刷新页面查看结果',
                duration: 3000,
              })
              console.log(res)
            })
          }
        })
      } else {
        bm.message({
          type: 'error',
          message: '请求失败',
          duration: 3000,
        })
      }
    })
  }
  function loadConfig () {
    let config = GM_getValue('config')
    let duration = 0
    if (!config) {
      if (!confirm(`是否选择粤海校区/沧海校区的讲座?(丽湖校区请点击'取消')`))
        campus = ['丽湖校区']
      else
        campus = ['粤海校区', '沧海校区']
      GM_setValue('config', { campus: campus })
      duration = 3000
      bm.message({
        type: 'info',
        message: `已经设置校区为${campus.join('/')},可以通过重新安装脚本进行重置`,
        duration: duration,
      })
    } else {
      campus = config.campus
    }
    return duration
  }
  function run () {
    let duration = loadConfig()
    setTimeout(() => {
      let currentTime = Date.now()
      let startTime = getStartTime()
      if (currentTime < startTime) {
        let deltaTime = startTime - currentTime
        bm.message({
          type: 'info',
          message: `准备于${parseInt(deltaTime / 1000)}秒后开抢`,
          duration: 3000,
        })
        setTimeout(rushLecture, deltaTime)
      } else {
        bm.message({
          type: 'info',
          message: `已经过了抢课时间`,
          duration: 3000,
        })
      }
    }, duration)
  }
  run()
})()