// ==UserScript== // @name 学习通刷课助手-自动静音,防止鼠标移出暂停,章节结束自动跳转下一节 // @namespace http://tampermonkey.net/ // @version 0.0.10 // @description 学习通课程自动挂机,当前脚本支持课程视频播放完成,自动跳转下一小节,章节测试自动跳过,后台播放防止视频暂停。 // @author Sweek // @match *://*.chaoxing.com/* // @license GPLv3 // @icon https://www.google.com/s2/favicons?sz=64&domain=csdn.net // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @require https://code.jquery.com/jquery-2.1.4.min.js // @downloadURL none // ==/UserScript== // 定义全局变量 let currentTime = null // 当前视频当前播放节点 let duration = null // 当前视频总长度 let progress = null // 当前视频播放进度 let playbackRate = 1 // 当前视频播放倍速 // 课程章节相关数据 let courseName = null // 当前课程名称 let courseId = null // 当前课程id let chapterInfo = [] // 当前课程所有章节数据 let currentChapterId = null // 当前所在章节id let currentChapterName = null // 当前所在章节名称 let allChapterName = [] // 所有章节名称 let currentChapterTabArr = [] // 当前页面所有的分栏 let currentChapterTabName = '' // 当前页面激活的分栏名称 let videoProgressId = '' // 定时监听页面内容监听事件 // 获取当前页面的 URL url = '' chapterId = '' // 页面模板部分 // 页面模板部分 // 页面模板部分 // 页面样式 var popCSs = ` #my-window { position: fixed; top: 5px; left: 20px; width: 300px; height: auto; background-color: rgba(247, 247, 247, 1); border: 1px solid #fff; border-radius: 5px; z-index: 9999; overflow: hidden; } #my-window .header { background-color: #4497fa; color: #fff; padding: 5px; font-size: 16px; font-family: 'fangsong'; font-weight: bold; border-radius: 5px; cursor: move; height: 25px; width: 300px; } #my-window .content { width: 300px; height: 570px; } #my-window .content .content-title { height: 22px; width: 280px; background-color: #dadada; line-height: 22px; padding-left: 5px; font-size: 12px; font-family: 'fangsong'; font-weight: 600; boder-radius: 5px; border-left: 4px solid #2196f3; border-right: 4px solid #dadada; margin-top: 5px; } #my-window .content .content-notice { height: 80px; width: 280px; overflow: auto; border: 1px solid gray; border-radius: 5px; padding: 5px; margin-top: 5px; } #my-window .content .content-process { height: 60px; width: 280px; overflow: auto; border: 1px solid gray; border-radius: 5px; padding: 5px; margin-top: 5px; } #my-window .content .content-log { height: 120px; width: 280px; overflow: auto; border: 1px solid gray; border-radius: 5px; padding: 5px; margin-top: 5px; } #my-window .content .content-set { height: 130px; width: 280px; overflow: auto; border: 1px solid gray; border-radius: 5px; padding: 5px; margin-top: 5px; display: flex; justify-content: center; flex-wrap: wrap; } #my-window .content .content-set .content-set-content { width: 280px; display: flex; justify-content: space-between; } #my-window .content .content-set .content-set-content #email-input { width: 200px; border-radius: 5px; border: 1px solid gray; } #my-window .content .content-set #save-btn { color: gray; width: 100%; margin-top: 10px; border-radius: 5px; border: 1px solid gray; } #save-btn:hover { background-color: #e3e3e3!important; } #my-window .resizer { position: absolute; bottom: 0; right: 0; width: 20px; height: 20px; background-color: #2196f3; cursor: se-resize; border-radius: 0px; z-index: 1; } #hide-btn { height: 25px; width: auto; float: right; margin-right: 10px; background-color: #fff; border: 1px solid gray; border-radius: 5px; font-size: 12px; padding: 0 5px; font-family: 'fangsong'; } #hide-btn:active { background-color: #4497fa; } ` // 页面Html var popHtml = `
';
// 点击链接显示弹窗
document.getElementById('Qcode').addEventListener('click', function() {
showCustomPopup(htmlContent, 500, 500);
});
// 获取头部元素
const header = myWindow.querySelector('.header');
// 获取调整大小元素
const resizer = myWindow.querySelector('.resizer');
// 处理调整大小事件
resizer.addEventListener('mousedown', function (e) {
e.preventDefault();
const { left, top, width, height } = myWindow.getBoundingClientRect();
const startX = e.clientX;
const startY = e.clientY;
function onMouseMove(e) {
const newWidth = Math.max(200, width + (e.clientX - startX));
const newHeight = Math.max(100, height + (e.clientY - startY));
myWindow.style.width = newWidth + 'px';
myWindow.style.height = newHeight + 'px';
}
function onMouseUp() {
window.removeEventListener('mousemove', onMouseMove);
window.removeEventListener('mouseup', onMouseUp);
}
window.addEventListener('mousemove', onMouseMove);
window.addEventListener('mouseup', onMouseUp);
});
// 处理移动事件
let isDragging = false;
let mouseX = 0;
let mouseY = 0;
header.addEventListener('mousedown', function (e) {
e.preventDefault();
isDragging = true;
mouseX = e.clientX;
mouseY = e.clientY;
});
document.addEventListener('mousemove', function (e) {
if (isDragging) {
const deltaX = e.clientX - mouseX;
const deltaY = e.clientY - mouseY;
const newLeft = myWindow.offsetLeft + deltaX;
const newTop = myWindow.offsetTop + deltaY;
myWindow.style.left = newLeft + 'px';
myWindow.style.top = newTop + 'px';
mouseX = e.clientX;
mouseY = e.clientY;
}
});
document.addEventListener('mouseup', function (e) {
isDragging = false;
});
}
// 隐藏窗口函数
function hideWindow() {
var myWindowContent = document.getElementById("my-window-content");
var showPop = myWindowContent.style.display
if (showPop == '' || showPop == 'block') {
myWindowContent.style.display = "none";
} else {
myWindowContent.style.display = "block";
}
}
// 获取当前页面章节小节的所有分栏
function getSubChapter() {
try {
if(location.pathname == '/mycourse/studentstudy') {
var subChapter = window.top.document.querySelector('#prev_tab');
if(subChapter) {
currentChapterTabArr = subChapter.querySelectorAll('li');
// console.log('currentChapterTabArr:::+ ', currentChapterTabArr)
currentChapterTabArr.forEach(function(item) {
if(item.className === 'active') {
currentChapterTabName = item.innerText
}
})
// console.log('currentChapterTabName:::+ ', currentChapterTabName)
}
}
} catch (error) {
console.error('An error occurred:', error);
// location.reload(); // 刷新页面
}
}
// 获取课程所有章节节点数据
function getChapterCodeInfo() {
// console.log('location.pathname:::+ ', location.pathname)
if(location.pathname === '/mooc-ans/knowledge/cards') {
var chapter = window.top.document.querySelectorAll('.posCatalog_select')
chapterInfo = chapter
allChapterName=[]
// console.log('chapterInfo:::+ ', chapterInfo)
chapterInfo.forEach(function(item) {
// console.log(item);
allChapterName.push({
id: item.id,
title: item.innerText,
active: item.classList.contains('posCatalog_active') ? 1 : 0,
ifTitle: item.classList.contains('firstLayer') ? 1 : 0,
status: item.childNodes[3]?.className == 'icon_Completed prevTips' ? 1 : 0
})
if (item.classList.contains('posCatalog_active')) {
currentChapterId = item.id
GM_setValue("currentChapterId", currentChapterId);
currentChapterName = item.innerText
GM_setValue("currentChapterName", currentChapterName);
}
});
// console.log('allChapterName:::+ ', allChapterName)
GM_setValue("chapterInfo", JSON.parse(JSON.stringify(allChapterName)));
// console.log('currentChapterId:::+ ', currentChapterId)
// console.log('currentChapterName:::+ ', currentChapterName)
// console.log('allChapterName:::+ ', allChapterName)
addlog('当前章节为' + currentChapterName, 'green')
}
}
// 获取公告数据
function getBoard() {
fetch('https://www.sweek.online/api/board')
.then(response => response.json())
.then(data => {
// 在这里处理接收到的数据
// console.log(data);
var notice = document.querySelector('#content-notice');
notice.innerHTML = data.text
})
.catch(error => {
// 在这里处理错误
console.error('Error:', error);
});
}
// 同步课程数据至数据库
function syncCourseData() {
const url = 'https://www.sweek.online/api/insertOrUpdateCourse';
const email = GM_getValue("savedEmail")
const course_name = GM_getValue("courseName")
const current_chapter_id = GM_getValue("currentChapterId")
const current_chapter_name = GM_getValue("currentChapterName")
const course_id = GM_getValue("courseId")
const process = document.querySelector('#content-process').innerHTML
const chapter_info = GM_getValue("chapterInfo")
var chapter = window.top.document.querySelectorAll('.posCatalog_select')
allChapterName = []
chapter.forEach(function(item) {
// console.log(item);
allChapterName.push({
id: item.id,
title: item.innerText,
active: item.classList.contains('posCatalog_active') ? 1 : 0,
ifTitle: item.classList.contains('firstLayer') ? 1 : 0,
status: item.childNodes[3]?.className == 'icon_Completed prevTips' ? 1 : 0
})
if (item.classList.contains('posCatalog_active')) {
currentChapterId = item.id
GM_setValue("currentChapterId", currentChapterId);
currentChapterName = item.innerText
GM_setValue("currentChapterName", currentChapterName);
}
});
// console.log('chapter_info:::+ ', chapter_info)
const data = {
email,
course_id: course_id || '',
course_name: course_name || '测试',
chapter: JSON.stringify(allChapterName),
current_chapter: current_chapter_id + ',' + current_chapter_name,
process
};
if(email && process) {
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json', // 声明请求主体的内容类型为 JSON
},
body: JSON.stringify(data), // 将数据对象转换为 JSON 字符串并作为请求主体
}).then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // 解析 JSON 响应数据
}).then(data => {
// console.log('Response:', data);
addlog('同步课程信息成功')
}).catch(error => {
console.error('Error:', error);
});
}
}
// 设置播放进度
function setVideoProcess(val1, val2, val3) {
var _process = window.top.document.querySelector('#content-process');
var _time = new Date().toLocaleTimeString()
var newContent = '[' + _time + ']' + '
' + '播放进度:' + val1 + '
' + '视频长度:' + val2 + 's' + '/' +val3 + 's' + '
'; _process.innerHTML = newContent; } // 页面弹窗显示 function showCustomPopup(htmlContent, width, height) { // 创建弹窗容器 var popupContainer = document.createElement('div'); popupContainer.className = 'custom-popup-container'; // 设置弹窗容器样式 popupContainer.style.position = 'fixed'; popupContainer.style.top = '50px'; popupContainer.style.left = '0'; popupContainer.style.width = '100%'; popupContainer.style.height = 'calc(100% - 50px)'; popupContainer.style.display = 'flex'; popupContainer.style.justifyContent = 'center'; popupContainer.style.alignItems = 'center'; popupContainer.style.zIndex = '999999'; // 创建弹窗内容容器 var popupContent = document.createElement('div'); popupContent.className = 'custom-popup-content'; // 设置弹窗内容样式 popupContent.style.width = width + 'px'; popupContent.style.height = height + 'px'; popupContent.style.backgroundColor = '#fff'; popupContent.style.border = '1px solid #ccc'; popupContent.style.borderRadius = '5px'; popupContent.style.position = 'relative'; // 创建关闭按钮 var closeButton = document.createElement('button'); closeButton.innerHTML = '关闭'; closeButton.style.position = 'absolute'; closeButton.style.top = '5px'; closeButton.style.right = '5px'; closeButton.style.padding = '5px 10px'; closeButton.style.backgroundColor = '#ccc'; closeButton.style.border = 'none'; closeButton.style.borderRadius = '3px'; closeButton.style.cursor = 'pointer'; closeButton.style.fontFamily = 'Arial, sans-serif'; // 关闭按钮点击事件处理 closeButton.addEventListener('click', function() { popupContainer.remove(); }); // 设置弹窗内容 popupContent.innerHTML = htmlContent; // 将关闭按钮和弹窗内容添加到弹窗容器中 popupContent.appendChild(closeButton); popupContainer.appendChild(popupContent); // 将弹窗容器添加到页面中 document.body.appendChild(popupContainer); } // 页面通知提示 function notify(text, time) { // 创建通知元素 var notification = document.createElement('div'); notification.className = 'notification'; // 设置通知内容 notification.innerHTML = '' + text + '
[' + _time + ']' + str + '