-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstable_userscript.js
More file actions
142 lines (125 loc) · 5.61 KB
/
stable_userscript.js
File metadata and controls
142 lines (125 loc) · 5.61 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// ==UserScript==
// @name 积极分子在线课程全自动挂机(稳定版)
// @namespace http://tampermonkey.net/
// @version 2.0
// @description 全自动挂机、自动提交完成、自动播放下一集(不修改倍速,避免卡顿)
// @author 99
// @match *://*/*/play?v_id=*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
console.log("========== 挂机脚本启动 ==========");
// 等待视频和播放器加载
function waitForPlayer(callback) {
const video = document.getElementById('video');
if (video && typeof player !== 'undefined' && player.ready) {
callback(video);
} else {
setTimeout(() => waitForPlayer(callback), 500);
}
}
waitForPlayer(function(video) {
console.log("✓ 视频和播放器已就绪");
// 1. 屏蔽 5 分钟暂停弹窗
window.loop_pause = function() {
console.log("✓ 已拦截 loop_pause 弹窗");
};
if (window.loop_flag) clearTimeout(window.loop_flag);
console.log("✓ 已屏蔽 5 分钟暂停弹窗");
// 2. 获取页面参数
const urlParams = new URLSearchParams(location.search);
const v_id = urlParams.get('v_id') || "";
const r_id = urlParams.get('r_id') || "";
const backLink = $(".video_goback").attr("href") || "";
const lesson_id = backLink.match(/lesson_id=(\d+)/)?.[1] || "";
console.log("✓ 参数:", { v_id, r_id, lesson_id });
// 3. 自动播放(延迟以等待加载完成弹窗)
setTimeout(() => {
if (video.paused) {
player.play().catch(err => {
console.warn("⚠ 自动播放需要用户点击:", err.message);
});
}
}, 2000);
// 4. 定期上报进度(每 30 秒)
let progressInterval = setInterval(() => {
if (!video.paused && video.currentTime > 0) {
$.ajax({
type: "POST",
url: "/jjfz/lesson/current_time",
data: {
rid: r_id,
time: video.currentTime,
_xsrf: $("input[name='_xsrf']").val()
},
success: function(data) {
if (Number(data.code) == 0) {
console.error("❌ 检测到异常,页面即将刷新");
location.reload();
} else {
const minutes = Math.floor(video.currentTime / 60);
const seconds = Math.floor(video.currentTime % 60);
console.log(`✓ 进度上报: ${minutes}:${seconds.toString().padStart(2, '0')}`);
}
},
error: function(xhr, status, error) {
console.error("❌ 进度上报失败:", error);
}
});
}
}, 30000);
// 5. 视频播放结束处理
video.addEventListener('ended', function videoEndHandler() {
console.log("========== 视频播放完毕 ==========");
clearInterval(progressInterval);
$.ajax({
type: "POST",
url: "/jjfz/lesson/resource_record",
data: {
rid: "1507010",
resource_id: r_id,
video_id: v_id,
lesson_id: lesson_id,
_xsrf: $("input[name='_xsrf']").val()
},
success: function(data) {
console.log("✓ 完成记录已提交");
if (Number(data.code) == 1) {
// 查找下一个视频
const currentLi = $(".video_lists ul li.video_red1");
const nextLi = currentLi.next("li");
const nextLink = nextLi.find("a").attr("href");
if (nextLink) {
console.log("→ 2 秒后跳转下一集:", nextLi.find("a").text().trim());
setTimeout(() => {
location.href = nextLink;
}, 2000);
} else {
console.log("✓✓✓ 本课程所有视频已完成!✓✓✓");
}
} else if (Number(data.code) == -1) {
console.error("❌ 异常学习行为,视频无效");
}
},
error: function(xhr, status, error) {
console.error("❌ 提交失败:", error);
}
});
}, { once: true }); // 使用 once 确保只触发一次
// 6. 页面可见性变化处理(切回标签页时自动播放)
document.addEventListener('visibilitychange', function() {
if (document.visibilityState === 'visible' && video.paused && video.currentTime > 0) {
console.log("→ 标签页切回,恢复播放");
player.play().catch(() => {});
}
});
// 7. 监听播放开始
video.addEventListener('play', function() {
console.log("▶ 视频开始播放");
}, { once: true });
console.log("========== 脚本初始化完成 ==========");
console.log("提示: 打开浏览器控制台(F12)可查看实时日志");
});
})();