Greasy Fork 还支持 简体中文。

Grab Lecture in SZU

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

  1. // ==UserScript==
  2. // @name Grab Lecture in SZU
  3. // @name:cn 深圳大学抢领航讲座脚本
  4. // @namespace http://tampermonkey.net/
  5. // @version 0.7.4
  6. // @description 【使用前先看介绍/有问题可反馈】深圳大学抢领航讲座脚本 (Grab Lecture in SZU):可用于在深圳大学抢领航讲座。
  7. // @author cc
  8. // @match http://lecture.szu.edu.cn/*
  9. // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.js
  10. // @require https://greasyfork.org/scripts/422854-bubble-message.js
  11. // @noframes
  12. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict'
  18. let config = null
  19. let bm = new BubbleMessage()
  20. bm.config.cmap.info = '#009688'
  21. bm.config.width = 300
  22. function getStartTime () {
  23. let now = new Date()
  24. let year = now.getFullYear()
  25. let month = now.getMonth() + 1
  26. let day = now.getDate()
  27. let startTime = new Date(`${year}-${month}-${day} 12:30:00`)
  28. return startTime.getTime()
  29. }
  30. function rushLecture () {
  31. $.ajax({
  32. url: 'http://lecture.szu.edu.cn/tLectureSignUp/list?page=1&limit=10',
  33. type: 'GET',
  34. }).then(res => {
  35. if (res.code === 0) {
  36. let availableLectures = res.data.filter(lecture => Date.now() < new Date(lecture.lectureEndTime))
  37. Promise.all(availableLectures.map(lecture => {
  38. return $.ajax({
  39. url: `http://lecture.szu.edu.cn/lectureClassroomSignUp/list?page=1&limit=20&lectureId=${lecture.id}`,
  40. type: 'GET',
  41. }).then(res => {
  42. return res.code === 0 ? res.data.filter(room => room.remainSeats > 0) : []
  43. })
  44. })).then(res => {
  45. let availableRooms = []
  46. res.forEach(rooms => availableRooms = availableRooms.concat(rooms))
  47. availableRooms = availableRooms.filter(room => config.campus.indexOf(room.campus) >= 0)
  48. if (availableRooms.length === 0) {
  49. bm.message({
  50. type: 'warning',
  51. message: '无可抢讲座',
  52. duration: 1500,
  53. })
  54. } else {
  55. Promise.all(availableRooms.map(room => {
  56. return $.ajax({
  57. url: `http://lecture.szu.edu.cn/tSelectLecture/addItem?lectureClassroomId=${room.id}&lectureId=${room.lectureId}&classroomId=${room.classroomId}`,
  58. type: 'POST',
  59. }).then(res => {
  60. return res
  61. })
  62. })).then(res => {
  63. bm.message({
  64. type: 'info',
  65. message: '抢领航讲座已完成,请刷新页面查看结果',
  66. duration: 3000,
  67. })
  68. console.info(res)
  69. })
  70. }
  71. })
  72. } else {
  73. bm.message({
  74. type: 'error',
  75. message: '请求失败',
  76. duration: 3000,
  77. })
  78. }
  79. })
  80. }
  81. function setSelect () {
  82. let div = document.createElement('div')
  83. div.style = 'display: inline-flex; height: 100%; align-items: center; margin-left: 10px;'
  84. let select = document.createElement('select')
  85. select.name = 'campus'
  86. let optionYHCH = document.createElement('option')
  87. optionYHCH.value = '粤海校区/沧海校区'
  88. optionYHCH.innerHTML = optionYHCH.value
  89. let optionLH = document.createElement('option')
  90. optionLH.value = '丽湖校区'
  91. optionLH.innerHTML = optionLH.value
  92. select.appendChild(optionYHCH)
  93. select.appendChild(optionLH)
  94. select.addEventListener('change', function (event) {
  95. config.campusIndex = event.target.selectedIndex
  96. config.campus = event.target.value.split('/')
  97. GM_setValue('config', config)
  98. })
  99. div.appendChild(select)
  100. let nextItem = document.querySelector('.layui-nav.layui-layout-right')
  101. nextItem.parentNode.insertBefore(div, nextItem)
  102. }
  103. function loadConfig () {
  104. let select = document.querySelector('select[name=campus]')
  105. config = GM_getValue('config')
  106. if (!config) {
  107. config = {
  108. campus: select.options[select.selectedIndex].value.split('/'),
  109. campusIndex: select.selectedIndex,
  110. }
  111. GM_setValue('config', config)
  112. } else {
  113. select.selectedIndex = config.campusIndex
  114. }
  115. }
  116. window.onload = function () {
  117. setSelect()
  118. loadConfig()
  119. let currentTime = Date.now()
  120. let startTime = getStartTime()
  121. if (currentTime < startTime) {
  122. let deltaTime = startTime - currentTime
  123. bm.message({
  124. type: 'info',
  125. message: `准备于 ${parseInt(deltaTime / 1000)} 秒后开抢`,
  126. duration: 3000,
  127. })
  128. setTimeout(rushLecture, deltaTime)
  129. } else {
  130. bm.message({
  131. type: 'info',
  132. message: `已经过了抢课时间`,
  133. duration: 3000,
  134. })
  135. }
  136. }
  137. })()