Skip to content

Instantly share code, notes, and snippets.

@lynzrand
Created October 9, 2021 11:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lynzrand/b91e1067092d0e7c2144b1617c4467be to your computer and use it in GitHub Desktop.
Save lynzrand/b91e1067092d0e7c2144b1617c4467be to your computer and use it in GitHub Desktop.
yuketang
// ==UserScript==
// @name 学堂云/雨课堂(是雨课堂4.0,非雨课堂,题库自动搜集)
// @namespace dandanmuaa@gmail.com
// @version 1.2
// @description 雨课堂脚本
// @author sea of flowers
// @match *://*.yuketang.cn/*
// @match *://*.edu.cn/*
// @connect huan.fm210.cn
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @grant GM_addStyle
// @grant GM_getResourceText
// @require https://unpkg.com/sweetalert/dist/sweetalert.min.js
// @resource cs1 https://www.layuicdn.com/layui/css/layui.css
// @run-at document-end
// @antifeature ads
// @antifeature menbership
// ==/UserScript==
(function() {
'use strict';
// 设置修改后,需要刷新或重新打开网课页面才会生效
var setting = {
passVideo:1,
passWork:1,
passExam:1,
runTimeOut:3000,
doTimeOut:6000,
};
var window = unsafeWindow;
var url = window.location.href;
var lastQuestion = "";
GM_addStyle(GM_getResourceText("cs1"));
function fillAnswer(type,answer){
if(type.match("单选题")){
var optionNum = document.getElementsByClassName("radioText").length;
for (let i=0;i<optionNum;i++){
let content = document.getElementsByClassName("radioText")[i].textContent.replace(/[\r\n]| /g, "");
if (content == answer[0].replace(/[\r\n]| /g, "")){
setTimeout(function(){
document.getElementsByClassName("radioInput")[i].click();}, 1000);
console.log("匹配成功");
}
else{
console.log("匹配失败")
}
}
}
else if(type.match("多选题")){
var checkBoxNum = document.getElementsByClassName("checkboxText").length;
for (let i=0;i<checkBoxNum;i++){
let content = document.getElementsByClassName("checkboxText")[i].textContent.replace(/[\r\n]/g, "");
for (let j=0;j<answer.length;j++){
// console.log("content", content);
// console.log("answer", answer[j].replace(/[\r\n]| /g, ""));
if (content == answer[j].replace(/[\r\n]| /g, "")){
setTimeout(function() {
document.getElementsByClassName("checkboxInput")[i].click();},1000);
console.log("匹配成功",i)
break;
}
else{
// console.log("匹配失败")
}
}
}
}
else if(type.match("判断题")){
if (answer[0].match(/(^|,)(正确|是|对|√|T|ri|right|true)(,|$)/)) {
document.getElementsByClassName("radioInput")[0].click();
}
else if (answer[0].match(/(^|,)(错误|否|错|×|F|wr|wrong|false)(,|$)/)) {
document.getElementsByClassName("radioInput")[1].click();
}
else{
console.log("匹配失败");
}
}
// setTimeout(function() {
// document.getElementsByClassName("el-button el-button--text")[1].click();},1000);
}
function findAnswer(question,type){
GM_xmlhttpRequest({
method: 'GET',
url: 'https://huan.fm210.cn/api/answer?keyword=' + encodeURIComponent(question.replace(/[\r\n]/g, "")),
headers: {
'Content-type': 'application/x-www-form-urlencoded'
},
timeout: setting.doTimeOut,
onload: function(xhr) {
if (xhr.status == 200) {
var obj = JSON.parse(xhr.responseText) || {};
var value = document.getElementsByClassName("el-button el-button--text is-disabled")
var number = document.getElementsByClassName("item-type")[0].textContent.replace(/[\r\n]| /g, "")
var content = document.getElementsByClassName("layui-card-body")[1]
// document.getElementsByClassName("layui-card-body")[0].innerHTML = obj.msg;
if (obj.code==1) {
var answer = obj._source.da.split("#");
content.innerHTML = number +"<br/>"+ answer.join("<br/>");
if(document.getElementsByClassName("el-button el-button--primary el-button--medium").length==1){
fillAnswer(type,answer);
}
// else{
// document.getElementsByClassName("el-button el-button--text")[1].click();
// };
}
else{
content.innerHTML += number +",答案:暂未收录<br>"
//document.getElementsByClassName("el-button el-button--text")[1].click();
};
if(value.length==1&&value[0].textContent=="下一题"){
// setTimeout(function(){
// swal({
// title: "搜题已完成",
// text: "本脚本不保证答案最终准确率,请用户自行检查并提交。\n感谢配合",
// icon: "success",
// button: "收到",
// });},1000);
clearInterval(setting.loop);
};
}
}
});
}
function pass_video(){
if(setting.passVideo){
document.getElementsByClassName("xt_video_bit_play_btn")[0].click();
}
}
function pass_homework(){
if(setting.passWork){
var question = document.getElementsByClassName("problem-body")[0].textContent;
var type = document.getElementsByClassName("item-type")[0].textContent;
if (question != lastQuestion) {
lastQuestion = question;
findAnswer(question,type);
}
}
}
if (url.match("cn/courselist|cn/v2/web/index")){
swal({
title: "欢迎使用雨课堂脚本",
text: "选择“已接受”或使用该脚本的任何功能,即为遵守使用协议。\n使用协议后续更新不再另行通知。\n脚本协议/使用教程见脚本首页",
icon: "warning",
button: "我接受",
});
};
if (url.match("/video")){
console.log("I'm video");
setTimeout(pass_video,setting.runTimeOut);
};
if (url.match("/homework|/exercise")){
var h=document.createElement("div");
h.setAttribute("class","layui-panel");
h.setAttribute("style","width: 300px; height:200px; background-color: #eee;position: fixed;right: 40px;top: 40px;z-index: 99999999;overflow-x: auto;");
var title=document.createElement("div");
title.setAttribute("class","layui-card-body");
h.appendChild(title);
var answer=document.createElement("div");
answer.setAttribute("class","layui-card-body");
h.appendChild(answer);
document.body.appendChild(h);
// document.getElementsByClassName("layui-card-body")[0].innerHTML = "脚本初始化中,请耐心等待5秒";
console.log("I'm homework");
var num = 0;
setting.loop = setInterval(pass_homework,setting.runTimeOut);
};
if (url.match("/exam")){
setTimeout(function(){
console.log("I'm exam");
document.getElementsByClassName("title")[1].innerHTML =
"考试题库可以微信扫描该二维码下载搜索~<img src='https://www.chitus.com/ewm/create?config=%7B%22content%22%3A%22https%3A%2F%2Fwww.fenbi.com%2Fdepot%2Ffenbi-search-question%2Findex.html%3Fapp%3Dsouti%26signVendor%3D8DFD180AC8706F9A519739C0F9F42CA6%22%7D' width='150px'>";
},1000);
swal({
title: "考试界面",
text: "考试功能暂不提供,但可扫描二维码下载APP搜题",
icon: "warning",
button: "OK",
});
};
if (url.match("/graph")){
setTimeout(function(){
swal({
title: "图文章节",
text: "课件阅读阅读已完成",
icon: "success",
button: "OK",
});
},1000);
};
})();
@zhuanvgui
Copy link

zhuanvgui commented Nov 30, 2021

@lynzrand
Copy link
Author

对不起,我不是脚本的作者……

@zhuanvgui
Copy link

zhuanvgui commented Nov 30, 2021 via email

@lynzrand
Copy link
Author

第 88 行开始的那个 findAnswer 函数吧,如果你能找到相关题目的合适的来源的话

@zhuanvgui
Copy link

也就是说现在用的题库答案是91行那个url地址吗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment