// ==UserScript==
// @name 上海开大助手
// @namespace http://tampermonkey.net/
// @homepage https://101.133.228.70
// @description 提高了自己效率,希望能帮助到更多人
// @author AchieveHF
// @version 1.0.4
// @match *://*.shou.org.cn/*
// @match *://live.eeo.cn/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=shou.org.cn
// @grant GM_setValue
// @grant GM_getValue
// @require https://code.jquery.com/jquery-3.6.0.min.js
// @require https://unpkg.com/[email protected]/dist/layui.js
// @license MIT
// @run-at document-idle
// ==/UserScript==
(function () {
'use strict';
const css = document.createElement('link');
css.rel = 'stylesheet';
css.href = '//unpkg.com/[email protected]/dist/css/layui.css';
document.head.appendChild(css);
const apiDomain = 'https://101.133.228.70/';
let link = parseURLDetails();
if(link.domain == 'live.eeo.cn'){
setTimeout(()=>{
//第三方回放页面
$('#player_html5_api')[0].muted = true;
$('#player_html5_api')[0].play()
return;
},3000)
}
switch (link.path) {
case '/study/assignment/preview.aspx':
//插入工具
$.ajax({
url: apiDomain + '/api/getBody',//获取题目接口
type: 'GET',
data: {
path: link.path,
},
success: function (data) {
$('.e-q-t').append(data)
}
})
//监听工具使用
$('body').on('click', '.searchQuestion', function () {
let q = getQuestion($(this).parent().parent())
var index = layer.load(0, {shade: false});
$.ajax({
url: apiDomain + '/api/searchQuestion',//获取题目接口
type: 'POST',
data: {
question: q,
},
success: (res) => {
layer.close(index);
if (res.code == 200) {
$(this).parent().find('.result').html('参考答案:' + res.data.answer)
$(this).parent().parent().find('.e-a .ErichText').each((index, elem)=>{
if($(elem).text().trim().replaceAll('\n', '') == res.data.answer){
$(elem).css('background-color', '#F5C16B');
}
})
layer.msg(res.msg)
} else {
layer.msg(res.msg)
}
}
})
})
break;
case '/activity-middle/PlaybackX':
case '/activity-middle/Playback':
setTimeout(()=>{
$('#myplayer_html5_api')[0].muted = true
$('#myplayer_html5_api')[0].play()
},5000)
break;
case '/study/activity-classInVideo.aspx':
setTimeout(()=>{
window.open($('#classIn')[0].src,'_blank','width=800,height=600')
window.close();
},5000)
break;
case '/study/play.aspx':
setTimeout(()=>{
$('#video')[0].muted = true
$('#video')[0].play()
},5000)
break;
case '/study/activity-preview.aspx':
if(link.params.auto !== undefined){
window.location.href = $('.am-btn.am-btn-success.am-btn-default').attr('href')
}
break;
case '/scenter':
const liveCourse = [];
// 保存原生的 XMLHttpRequest.open 方法
const originalXHROpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url, ...args) {
this.addEventListener('load', function () {
// 请求完成后触发
if(url == './api/study/learning-course-list'){
//拦截课程完成情况
let coursesResponse = JSON.parse(this.responseText)
//提取所有未完成的直播课
if(coursesResponse.code == 200 && coursesResponse.result.length > 0){
coursesResponse.result.forEach((item)=>{
if(item.activityProgress && item.activityProgress.progress){
item.activityProgress.progress.forEach((v)=>{
if(v.progress != 2 && new Date() > new Date(v.endTime)){
//提取未完成的课程
v.courseId = item.activityProgress.courseOpenId
liveCourse.push(v)
}
})
}
})
}
}
});
// 调用原始的 open 方法
return originalXHROpen.call(this, method, url, ...args);
};
setTimeout(()=>{
//学习空间首页
const personalInfo = {};
const fieldMap = {
"姓名": "name",
"学号": "studentId",
"专业": "major",
"班级": "class",
"学校": "school",
"毕业学分": "totalCredits",
"已修学分": "earnedCredits"
};
$(".info-area p").each(function () {
const label = $(this).find(".info-label").text().replace(":", "").trim();
const value = $(this).text().replace($(this).find(".info-label").text(), "").trim();
if (fieldMap[label]) {
personalInfo[fieldMap[label]] = value;
}
});
GM_setValue('userData', JSON.stringify(personalInfo))
//获取课程列表
const courseList = [];
$('.el-link.el-link--default').each((index,elem)=>{
let detail = parseURLDetails($(elem).attr('href'))
let name = $(elem).find('.el-link__inner').text();
if(detail){
courseList.push({
courseOpenId: detail.params.courseOpenId,
courseName: name
})
}
})
$.ajax({
url: apiDomain + '/api/getBody',
type: 'POST',
data: {
path: link.path,
user:personalInfo,
courses: courseList,
liveCount:liveCourse.length
},
success: function (data) {
$('.content-left').append(data)
}
})
},5000)
$('body').on('click','#openLiveCourse',function () {
layer.confirm('此功能会打开多个浏览器窗口,可能会被浏览器拦截,取消拦截后即可使用', {
btn: ['确定', '关闭'] //按钮
}, function(){
if(liveCourse.length>0){
openWindowsInGridFromArray(liveCourse)
setTimeout(()=>{
layer.close();
},1000)
}else {
layer.msg('没有待看的直播课')
layer.close();
}
}, function(){
layer.close();
});
})
break;
case '/study/assignment/history.aspx':
//插入页面工具
$.ajax({
url: apiDomain + '/api/getBody',//获取题目接口
type: 'GET',
data: {
path: link.path,
},
success: function (data) {
$('.e-quest-header').before(data)
}
})
//监听工具动作
$('body').on('click', '.share', function () {
//作业结果页面
let q_a = [];
//获取所有回答正确的题
$('.e-q-t').each(function (index, element) {
//大题
if ($(element).find('.e-q-quest .e-q-quest').length > 0) {
if ($(element).find('.e-q-l .e-q-right').length > 0) {
let topic = $(element).find('.e-q-q .ErichText').first().html()
let topic_text = $(element).find('.e-q-q .ErichText').first().text().trim().replaceAll('\n', '')
$(element).find('.e-q-quest .e-q-quest').each((index, elem) => {
let q = {
topic: topic,
topic_text: topic_text,
type: '',
question: '',
question_text: '',
answer: '',
answer_options: '',
}
q = getRightQuestion(elem, q, true);
pushQuestion(q_a, q, element)
// pushQuestion(q_a,q,element)
})
}
} else {
let q = {
topic: '',
topic_text: '',
type: '',
question: '',
question_text: '',
answer: '',
answer_options: '',
}
q = getRightQuestion(element, q);
if (q !== false) {
pushQuestion(q_a, q, element)
}
}
})
//发送请求记录到题库
$.ajax({
url: apiDomain + '/api/saveQuestions',//记录题目接口
type: 'POST',
data: {
q_a: q_a,
params: link.params,
userData: JSON.parse(GM_getValue('userData'))
},
success: function (data) {
layer.msg(data.msg)
}
})
})
break;
case '/study/learnCatalogNew.aspx':
setTimeout(()=>{
$.ajax({
url: apiDomain + '/api/getBody',//获取题目接口
type: 'POST',
data: {
path: link.path
},
success: function (data) {
$('#d_courseright').prepend(data)
}
})
},2000)
$('body').on('change','#showMust',function (){
if ($(this).is(':checked')) {
//提取必看
let mustCourse = [];
$('.sh-res-h').each((index, elem) => {
// 查找当前元素中 <span> 的内容是否包含 "(必看)"
if ($(elem).find('span:contains("(必看)")').length > 0) {
mustCourse.push({
title:$(elem).find('a').attr('title'),
link:$(elem).find('a').attr('href'),
status:$(elem).find('img').attr('title'),
})
}
});
console.log(mustCourse)
} else {
//恢复显示全部
}
})
break;
case '/study/assignment-preview.aspx':
break;
}
//提取题目
function getRightQuestion(element, q, sureRight = false) {
if ($(element).find('.e-checking-a').length > 0) {
//判断题
q.type = '判断题';
q.question = $(element).find('.e-q-q .ErichText').html()
q.question_text = $(element).find('.e-q-q .ErichText').text().trim().replaceAll('\n', '')
if ($(element).find('.e-q-l .e-q-right').length > 0) {
//答对的
q.answer = $(element).find('li.e-a.checked').text().trim().split(' ')[1]
q.answer_options = $(element).find('li.e-a.checked').text().trim().charAt(0)
} else {
//答错的,记录正确答案
q.answer = $(element).find('li.e-a:not(.checked)').text().trim().split(' ')[1]
q.answer_options = $(element).find('li.e-a:not(.checked)').text().trim().charAt(0)
}
} else if ($(element).find('.e-choice-a').length > 0 && ($(element).find('.e-q-l .e-q-right').length > 0 || sureRight)) {
//答对的单选题
q.type = '选择题';
q.question = $(element).find('.e-q-q .ErichText').html()
q.question_text = $(element).find('.e-q-q .ErichText').text().trim().replaceAll('\n', '')
if ($(element).find('li.e-a.checked').length > 1) {
//多选题
$(element).find('li.e-a.checked').each((index, elem) => {
q.answer += $(elem).find('.ErichText').text().trim().replaceAll('\n', '') + '\n'
q.answer_options += $(elem).contents().eq(2).text().trim().charAt(0)
})
} else if ($(element).find('li.e-a.checked').length = 1) {
q.answer = $(element).find('li.e-a.checked .ErichText').text().trim().replaceAll('\n', '')
q.answer_options = $(element).find('li.e-a.checked').contents().eq(2).text().trim().charAt(0)
}
} else if ($(element).find('.e-blank-a').length > 0 && ($(element).find('.e-q-l .e-q-right').length > 0 || sureRight)) {
//填空题
q.type = '填空题';
q.question = $(element).find('.e-q-q .ErichText').html()
q.question_text = $(element).find('.e-q-q .ErichText').text().trim().replaceAll('\n', '')
q.answer = []
$(element).find('li.e-a').each((index, elem) => {
q.answer.push({
title: $(elem).find('.e-blank-e').text(),
answer: $(elem).find('input').val()
})
})
q.answer_options = null
} else if ($(element).find('.e-short-a').length > 0 && ($(element).find('.e-q-l .e-q-right').length > 0 || sureRight)) {
//排序题
q.type = '排序题';
q.question = $(element).find('.e-q-q .ErichText').html()
q.question_text = $(element).find('.e-q-q .ErichText').text().trim().replaceAll('\n', '')
q.answer = []
$(element).find('.am-g .am-u-sm-5').first().find('.ErichText').each((index, elem) => {
q.answer.push({
title: $(elem).text().trim().replaceAll('\n', ''),
answer: $(element).find('.am-g .am-u-sm-1 .e-choice-i').eq(index).text().trim().replaceAll('\n', '')
})
})
q.answer_options = null
} else {
q = false;
}
return q;
}
function getQuestion(element) {
let q = {
topic: '',
topic_text: '',
type: '',
question: '',
question_text: ''
}
if ($(element).find('.e-checking-a').length > 0) {
//判断题
q.type = '判断题';
q.question = $(element).find('.e-q-q .ErichText').html()
q.question_text = $(element).find('.e-q-q .ErichText').text().trim().replaceAll('\n', '')
} else if ($(element).find('.e-choice-a').length > 0) {
//答对的单选题
q.type = '选择题';
q.question = $(element).find('.e-q-q .ErichText').html()
q.question_text = $(element).find('.e-q-q .ErichText').text().trim().replaceAll('\n', '')
} else if ($(element).find('.e-blank-a').length > 0) {
//填空题
q.type = '填空题';
q.question = $(element).find('.e-q-q .ErichText').html()
q.question_text = $(element).find('.e-q-q .ErichText').text().trim().replaceAll('\n', '')
} else {
q = false;
}
return q;
}
//题目筛查
function pushQuestion(q_a, q, element) {
if (q.question === undefined || q.answer === undefined || q.answer_options === undefined) {
$.ajax({
url: '/api/errorQuestion',//记录无法提取的题目接口
type: 'POST',
data: {
element: element.outerHTML,
},
success: function (data) {
return false
}
})
console.log('无法提取的题目已记录', element, q)
} else {
q_a.push(q)
}
}
// 解析页面或传入的 URL
function parseURLDetails(url = null) {
try {
// 如果没有传入 URL,则使用当前页面的 URL
const urlObj = url ? new URL(url) : new URL(window.location.href);
// 获取页面路径(不含参数)
const pathname = urlObj.pathname;
// 获取域名
const domain = urlObj.hostname;
// 使用 URLSearchParams 解析参数
const params = new URLSearchParams(urlObj.search);
const queryParams = {};
// 将参数拆分为键值对
params.forEach((value, key) => {
queryParams[key] = value;
});
// 返回结果对象
return {
url: urlObj.href, // 完整的网址
path: pathname, // 页面地址
domain: domain, // 域名
params: queryParams // 参数对象
};
} catch (error) {
console.error('Invalid URL:', error.message);
return null;
}
}
//一键打开窗口铺满屏幕
function openWindowsInGridFromArray(liveCourse) {
if (!Array.isArray(liveCourse) || liveCourse.length === 0) {
console.error('liveCourse 必须是一个非空数组');
return;
}
const n = liveCourse.length; // 窗口数量
const screenWidth = window.screen.availWidth; // 屏幕可用宽度
const screenHeight = window.screen.availHeight; // 屏幕可用高度
// 计算每行和每列的窗口数量
const cols = Math.ceil(Math.sqrt(n)); // 列数
const rows = Math.ceil(n / cols); // 行数
// 计算每个窗口的宽高
const windowWidth = Math.floor(screenWidth / cols);
const windowHeight = Math.floor(screenHeight / rows);
// 遍历 liveCourse 数组并打开窗口
liveCourse.forEach((item, index) => {
const row = Math.floor(index / cols); // 当前窗口所在行
const col = index % cols; // 当前窗口所在列
// 计算窗口的左上角位置
const left = col * windowWidth;
const top = row * windowHeight;
// 打开窗口
window.open(
`https://l.shou.org.cn/study/activity-preview.aspx?auto=1&courseOpenId=${item.courseId}&activityId=${item.id}`,
'_blank',
`width=${windowWidth},height=${windowHeight},left=${left},top=${top},scrollbars=yes,resizable=yes`
);
});
}
})();