forked from yanyaoli/cuit-course-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcourse-helper.user.js
More file actions
58 lines (50 loc) · 2.08 KB
/
course-helper.user.js
File metadata and controls
58 lines (50 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// ==UserScript==
// @name CUIT课程中心助手
// @namespace https://cuit.edu.cn
// @version 1.3
// @author ooyq
// @description 成都信息工程大学课程中心网课助手 自动完成课程
// @match https://kczx.cuit.edu.cn/learn/course/spoc/*
// @grant GM_xmlhttpRequest
// @grant GM_notification
// @license Apache License 2.0
// ==/UserScript==
(function() {
'use strict';
// 获取URL中的courseId和subsectionId
var urlParts = window.location.href.match(/\/spoc\/([a-zA-Z0-9]+)\/([a-zA-Z0-9]+)/);
var courseId = urlParts[1];
var subsectionId = urlParts[2];
// 构建获取id的URL
var idUrl = "https://kczx.cuit.edu.cn/learn/v1/learningsituation?courseId=" + courseId + "&subsectionId=" + subsectionId;
// 获取id
GM_xmlhttpRequest({
method: "GET",
url: idUrl,
onload: function(response) {
var data = JSON.parse(response.responseText);
// 获取id
var id = data.data.id;
// 构建学习情况状态页面的URL
var statusUrl = "https://kczx.cuit.edu.cn/learn/v1/learningsituation/status?id=" + id + "&status=2";
// 获取学习情况状态页面的数据
GM_xmlhttpRequest({
method: "GET",
url: statusUrl,
onload: function(response) {
var statusData = JSON.parse(response.responseText);
// 判断学习情况状态页面的数据内容
if (statusData.status === 200 && statusData.message === "OK") {
// 如果课程已完成,则显示通知
GM_notification({
text: "课程已完成,请刷新查看",
title: "课程状态",
timeout: 2000, // 持续显示通知的时间(毫秒)
silent: true // 静音通知,不会发出声音
});
}
}
});
}
});
})();