Skip to content

Commit 7d70314

Browse files
author
wuwei
committed
优化,自动学习算法
1 parent 6a6ffec commit 7d70314

2 files changed

Lines changed: 50 additions & 28 deletions

File tree

StudyChromeApp/manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"name": "自动学习",
2+
"name": "OpenLearning自动学习",
33
"manifest_version": 2,
44
"version": "1.0",
5-
"description":"自动学习",
5+
"description":"自动学习插件支持OpenLearning网络学习平台课程自动学习,进入一个课程自动判断学习状态进入下一个视频。",
66
"browser_action": {
77
"default_icon": "images/logo.png",
88
"default_popup": "popup.html"

StudyChromeApp/script.js

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ if(els.length > 0){
77

88
console.log("找到了下一个按钮!");
99

10-
// startStudy();
1110

1211
setTimeout(function(){
1312

14-
var time = getTime();
15-
startStudy(time);
13+
// var time = getTime();
14+
startStudy();
1615

1716

1817
}, 1000);
@@ -36,11 +35,21 @@ function getTime(){
3635
}
3736

3837

38+
/**
39+
* 获取当前的学习进度是否完成
40+
* @returns {*|jQuery}
41+
*/
42+
function getStatus(){
43+
var span = $(window.parent["w_lms_content"].document).find("#tdRemark span");
44+
return $(span).hasClass("completed");
45+
}
46+
47+
3948
/**
4049
* 开始学习
4150
* @param time
4251
*/
43-
function startStudy(time) {
52+
function startStudy() {
4453

4554
/**
4655
* 该自动学习脚本仅用于学习研究,未经作者同意不得用于商业用途。
@@ -50,60 +59,73 @@ function startStudy(time) {
5059
* @type {number}
5160
*/
5261

53-
/* 全局变量配置 */
54-
var STUDY_DELAY_TIME = 1; // 延时启动。单位:秒
55-
var STUDY_PERIOD_TIME = time + delayTime; // 下一章节周期 单位:秒
5662

5763

5864

5965
/**
6066
* 自动学习函数
6167
*/
6268
var myInterval;
69+
var i = 0;
6370
function study(){
64-
console.log("学习完成,准备下一章节...")
65-
console.log(window.JQUERY_CUSTERM );
66-
// 10秒后开始
67-
if(window.JQUERY_CUSTERM ("#btnNext")){
68-
console.log("进入下一章节...")
69-
window.JQUERY_CUSTERM("#btnNext").click();
71+
i++;
72+
console.log("自动正在学习中...");
7073

71-
// 清楚定时任务
72-
clearTimeout(myInterval);
74+
if(!($("#StudyStatus").length > 0)){
75+
$('body').append("<div id='StudyStatus' style='position: fixed; z-index: 11111;font-weight: bold; bottom: 30px; left: 6px; color: red'>自动正在学习中...</div>")
76+
}
77+
78+
if((i%2)==1){
79+
$('#StudyStatus').text('自动正在学习中...');
80+
} else{
81+
$('#StudyStatus').text('自动正在学习中');
82+
}
7383

7484

75-
setTimeout(function(){
85+
if (getStatus()){ // 判断是否学习完成
86+
console.log("学习完成...");
7687

77-
// 获取当前课程需要的时间
78-
STUDY_PERIOD_TIME = getTime() + delayTime;
88+
if(window.JQUERY_CUSTERM ("#btnNext")){
89+
console.log("进入下一章节...")
90+
window.JQUERY_CUSTERM("#btnNext").click();
7991

92+
// 清除定时任务
93+
clearInterval(myInterval);
8094

81-
startRun();
95+
// 延时执行
96+
setTimeout(function(){
97+
startRun();
98+
}, 1000);
8299

83100

84-
}, 1000);
101+
}else{
102+
console.error("没有找到【下一个】按钮");
103+
console.log("正在关闭周期循环管理器!");
104+
clearInterval(myInterval);
85105

106+
$("#StudyStatus").css("color","green");
107+
$("#StudyStatus").html("学习完成!");
108+
}
86109

87-
}else{
88-
console.error("没有找到【下一个】按钮");
89-
console.log("正在关闭周期循环管理器!");
90-
clearTimeout(myInterval);
91110
}
92111
};
93112

94113

95114
function startRun(){
96115
console.log("【下一个】按钮获取焦点")
97116
window.JQUERY_CUSTERM("#btnNext", window.frames['w_main']).focus();
98-
myInterval = setTimeout(study, STUDY_PERIOD_TIME * 1000);
117+
myInterval = setInterval(study, 1000);
99118
}
100119

101120

102121
window.JQUERY_CUSTERM = $;
103122
console.log("自动学习脚本启动...");
104123

105124

106-
setTimeout(startRun, STUDY_DELAY_TIME * 1000);
125+
126+
127+
128+
setTimeout(startRun, 1000);
107129

108130

109131

0 commit comments

Comments
 (0)