提交 13820888 编写于 作者: C CodFrm

视频 题目 自动挂机

上级 97bd32e4
......@@ -6,28 +6,35 @@ const moocConfig = require('../config');
* 开始监控暂停,自动重新播放
*/
window.monitorPlay = function (playOver) {
var player = document.querySelector('object');
var reader = player.parentNode.parentNode;
play();
$(reader).bind('onPause', function (h, g) {
play();
});
//监听完成事件
$(reader).bind('onEnd', function (h, g) {
if (playOver != undefined) {
playOver();
var timer = setInterval(function () {
var player = document.querySelector('object');
if (player != undefined) {
clearInterval(timer);
} else {
return;
}
});
function play() {
var time = setInterval(function () {
if (player.getPlayState() != 1) {
player.playMovie();
} else {
clearInterval(time);
var reader = player.parentNode.parentNode;
play();
$(reader).bind('onPause', function (h, g) {
play();
});
//监听完成事件
$(reader).bind('onEnd', function (h, g) {
if (playOver != undefined) {
playOver();
}
}, 1000);
}
});
function play() {
var time = setInterval(function () {
if (player.getPlayState() != 1) {
player.playMovie();
} else {
clearInterval(time);
}
}, 1000);
}
}, 200);
}
window.removeOldPlayer = function (obj) {
......
......@@ -6,6 +6,15 @@ const video = require('./video');
*/
export function showExpand(_this) {
var ans = _this.contentDocument.getElementsByClassName('ans-job-icon');
var config = JSON.parse(localStorage['config']);
if (ans.length <= 0 && config['auto']) {
//没有任务点,正在挂机的状态,5s后切换下一个
console.log('null,switch task');
setTimeout(function () {
switchTask();
}, 5000);
return;
}
for (var i = 0; i < ans.length; i++) {
ans[i].style.width = '100%';
ans[i].style.textAlign = 'center';
......@@ -19,6 +28,10 @@ export function showExpand(_this) {
//未做完的题目
topic(_this, ans[i], i, false);
}
//如果是挂机模式,并且是第一个,点击,启动!
if (i == 0 && config['auto']) {
_this.contentDocument.getElementById('action-btn').click();
}
}
}
......@@ -110,12 +123,49 @@ export function switchChoice() {
if (tab.length <= 0) {
return false;
}
var tabs=tab[0].getElementsByTagName('span');
for(var i=0;i<tabs.length;i++){
if(tabs[i].className.indexOf('currents')>0){
var tabs = tab[0].getElementsByTagName('span');
for (var i = 0; i < tabs.length; i++) {
if (tabs[i].className.indexOf('currents') > 0) {
//现行,切换到下一个
if (i + 1 >= tabs.length) {
//超过长度
break;
} else {
return tabs[i + 1];
}
}
}
//可以换页了
console.log(tabs);
return false;
}
export function switchTask() {
//判断选项夹
var tab = switchChoice();
if (tab !== false) {
tab.click();
return true;
}
//判断任务点
var course = document.getElementById('coursetree');
var now = course.getElementsByClassName('currents');
if (now.length <= 0) {
alert('很奇怪啊');
return false;
}
now = now[0];
var next = now.parentNode.parentNode;
if (next.nextElementSibling == undefined) {
if (next.parentNode.nextElementSibling == undefined) {
alert('挂机完成了');
return true;
} else {
next = next.parentNode;
}
}
console.log(next);
//两个父节点后,下一个兄弟节点的第一个节点,点击,启动!
next.nextElementSibling.getElementsByTagName('a')[0].click();
console.log('next task');
return true;
}
\ No newline at end of file
......@@ -55,7 +55,7 @@
</div>
<div class="config-item">
<input type="checkbox" id="auto" />
<label for="auto" title="点开始挂机,播放完一个视频之后会自动进入下一个">全自动挂机</label>
<label for="auto" title="进入一个页面就会自动开始挂机,完成一个任务之后会自动进行下一个">全自动挂机</label>
</div>
<div id="auto-m" class="config-item" style="display: none;">
<label for="interval" title="播放(题目)完成后n分钟再继续下一个任务">间隔时间:</label>
......@@ -64,6 +64,7 @@
</div>
<div>
<h4>其他说明:</h4>
<p>1.4之后采用了修改的播放器,需要能够从服务器下载才能使用全自动挂机</p>
<p>GitHub开源地址:
<br>
<a href="https://github.com/CodFrm/cxmooc-tools" target="_black">https://github.com/CodFrm/cxmooc-tools</a>
......
......@@ -43,7 +43,6 @@ window.onload = function () {
chrome.storage.sync.set({
'auto': check.checked
});
document.getElementById('version').innerHTML = check.checked;
}
document.getElementById('interval').onblur = function () {
chrome.storage.sync.set({
......
......@@ -9,11 +9,22 @@ module.exports = function (_this, elLogo, index, over) {
var topicDoc = doc.getElementById('frame_content').contentDocument;
if (over) {
//完成的提交答案
var auto = common.createBtn('下一个');
auto.id = 'action-btn';
elLogo.appendChild(auto);
auto.onclick = function () {
//进入下一个
setTimeout(function () {
nextTask();
}, 4000);
}
dealDocumentTopic(topicDoc);
} else {
//未完成的填入答案
var auto = common.createBtn('搜索答案');
auto.id = 'action-btn';
elLogo.appendChild(auto);
var config = JSON.parse(localStorage['config']);
auto.onclick = function () {
var topicList = topicDoc.getElementsByClassName('Zy_TItle');
var topic = [];
......@@ -37,12 +48,48 @@ module.exports = function (_this, elLogo, index, over) {
for (let i in json) {
fillIn(json[i].topic, json[i].result == undefined ? [] : json[i].result);
}
//如果是自动挂机,填入之后自动提交
if (!config['auto']) {
return;
}
setTimeout(function () {
//提交操作
var submit = topicDoc.getElementsByClassName('Btn_blue_1');
submit = submit[0];
submit.click();
//判断有没有未填的题目
setTimeout(function () {
if (topicDoc.getElementById('tipContent').innerText.indexOf('未做完') > 0) {
alert('提示:' + topicDoc.getElementById('tipContent').innerText);
return;
}
//确定提交
var submit = topicDoc.getElementsByClassName('bluebtn');
submit[0].click();
setTimeout(function () {
doc.getElementById('frame_content').contentWindow.location.reload();
}, 2000);
}, 1000);
}, config['interval'] * 1000 * 60);
}
}
}
}
}
function nextTask() {
//判断有没有下一个,自动进行下一个任务
var ans = _this.contentDocument.getElementsByClassName('ans-job-icon');
if (ans.length > index + 1) {
//点击
var nextAction = ans[index + 1].firstElementChild;
nextAction.click();
} else {
//已经是最后一个,切换任务
common.switchTask();
}
}
/**
* 用document方式提取题目
*/
......
......@@ -10,7 +10,6 @@ const get = common.get;
* @param {*} index
*/
module.exports = function (_this, elLogo, index) {
common.switchChoice();
//获取要操作的对象和视频id
var wid = _this.contentDocument.getElementsByTagName('iframe')[index].contentWindow;
var doc = _this.contentDocument.getElementsByTagName('iframe')[index].contentDocument;
......@@ -41,25 +40,28 @@ module.exports = function (_this, elLogo, index) {
if (config['auto']) {
//全自动挂机开始
hang_btn.innerText = '挂机中...';
wid.monitorPlay(function () {
//播放完成
console.log('over');
setTimeout(function () {
//判断有没有下一个,自动进行下一个任务
var ans = _this.contentDocument.getElementsByClassName('ans-job-icon');
if (ans.length > index + 1) {
//点击
console.log('下一任务点');
console.log(ans[index + 1]);
var nextAction = ans[index + 1].firstElementChild;
console.log(nextAction);
nextAction.click();
} else {
//已经是最后一个,搜索下一个选项夹
console.log('下一选项夹');
}
}, config['interval'] * 1000 * 60);
});
var timer = setInterval(function () {
if (wid.monitorPlay != undefined) {
clearInterval(timer);
wid.monitorPlay(function () {
//播放完成
console.log('over');
setTimeout(function () {
//判断有没有下一个,自动进行下一个任务
var ans = _this.contentDocument.getElementsByClassName('ans-job-icon');
if (ans.length > index + 1) {
//点击
var nextAction = ans[index + 1].firstElementChild;
nextAction.click();
} else {
//已经是最后一个,切换任务
common.switchTask();
}
}, config['interval'] * 1000 * 60);
});
}
}, 1000);
} else {
wid.monitorPlay();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册