var myHeaders = new Headers();
var token = sessionStorage.getItem('jwtToken');
myHeaders.append("Hrttoken", token);// 固定值
var platformId = window.location.href.match(/platformId=([^&]*)/)[1]
// 培训id url 获得
var trainplanId = window.location.href.match(/trainplanId=([^&]*)/)[1]var requestOptions = {method: 'GET',headers: myHeaders,
};// 未完成课程列表
fetch("https://gp.chinahrt.com/gp6/lms/stu/trainplanCourseHandle/selected_course?curPage=1&pageSize=100&learnFinish=0&trainplanId=" + trainplanId + "&platformId=" + platformId, requestOptions).then(response => response.json()).then(result => {var courseStudyList = result.data.courseStudyListif (courseStudyList == null || courseStudyList.length == 0) {console.log("没有未完成课程!!!");return;}for(var i = 0; i < courseStudyList.length; i++) {var courseId = courseStudyList[i].courseIdfetch("https://gp.chinahrt.com/gp6/lms/stu/course/courseDetail?courseId=" + courseStudyList[i].courseId + "&trainplanId=" + courseStudyList[i].trainplanId, requestOptions).then(response => response.json()).then(result => {var sectionList = result.data.course.chapter_list[0].section_listfor(var j = 0; j < sectionList.length; j++) {//console.log(sectionList[j])if (sectionList[j].study_status === '已学完') {continue;}// 待学习的章节idvar sectionId = sectionList[j].idvar sectionUrl = 'https://gp.chinahrt.com/index.html#/v_video?platformId=' + platformId + '&trainplanId=' + trainplanId + '&courseId=' + courseId + '§ionId=' + sectionId//console.log(sectionUrl)var openedWindow = window.open(sectionUrl, "_blank", "headers=Hrttoken: " + token)openedWindow.window.onfocus = function(){console.log('on focus')};openedWindow.window.onblur = function(){console.log('on blur')};openedWindow.window.frames['player'].videoPlay();var loopCheck = setTimeout(function(){fetch("https://gp.chinahrt.com/gp6/lms/stu/course/courseDetail?courseId=" + courseId + "&trainplanId=" + trainplanId, requestOptions).then(response => response.json()).then(result => {sectionList = result.data.course.chapter_list[0].section_listfor(var k = 0; k < sectionList.length; k++) {if(sectionList[k].id === sectionId) {console.log('当前学习学习进度: ' + sectionList[k].studyProcess)console.log('【' + sectionList[k].name + '】 学习进度' + sectionList[k].studyProcess + '%')if (sectionList[k].studyProcess == 100) {clearInterval(loopCheck);openedWindow.close();break;}}}}).catch(error => console.log('error', error))}, 3000);}}).catch(error => console.log('error', error));}}).catch(error => console.log('error', error));
以上存在dom跨域无法操作iframe进而控制视频播放,放弃。
油猴脚本