全国青少年普法网自动答题、自动考试、批量导入账号脚本
全国青少年普法网,每年都有,提供给有需要的人。
全国学生“学宪法 讲宪法”活动自动答题脚本
首先装好油猴,然后将你的账号信息设置如下格式保存:
全国青少年普法网自动答题、自动考试、批量导入账号脚本
这个插件相对于其他的插件来说,多了一个批量导入账号的功能。
可以按照插件页面的图片指示来操作
然后安装这个脚本:
地址:https://greasyfork.org/
代码:
// ==UserScript==
// @name 普法网(宪法小卫士)批量导入、课后练习、考试自动答题
// @namespace Ne-7
// @version 1.0.0
// @description 全国学生“学宪法 讲宪法”活动自动答题脚本
// @author guan
// @match *://static.qspfw.moe.gov.cn/*
// @run-at document-end
// @grant unsafeWindow
// @license MIT
// @require https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js
// ==/UserScript==
var _self = unsafeWindow,
$ = _self.jQuery || top.jQuery,
Swal = Swal || window.Swal,
columnId = getQueryVariable("columnId"),
answer_list = [],
exam_list = [],
time = 5e3, // 答题间隔时间,最好为5秒
num = {"A": 1,"B": 2, "C": 3, "D": 4};
(function() {
if (window.location.pathname.indexOf('learn_exam.html') != -1) {
getExam();
let t = setInterval( function() {
doExam(t)
},time / 2);
} else if (window.location.pathname.indexOf('learn-practice.html') != -1) {
setTimeout(function function_name(argument) {
if ($(".inside-pages-title:contains('课后练习')") != null) {
getAnswer(columnId);
let t = setInterval( function() {
doQuestion(t)
},time / 2);
}
}, time / 2);
} else if (window.location.pathname.indexOf('learn_practice_list.html') != -1) {
setTimeout( function() {$(".red").click();},time / 2);
} else if (window.location.pathname.indexOf('/user/') != -1) {
setTimeout(function() {
setInterval(function() {
var stu = $("button:contains('开始学习')");
if (stu != null) {
$("button:contains('开始学习')").click();
}
}, time / 2)
createFileInput();
readFile();
readAndWriteStudentInfo();
}, time / 2);
} else if (window.location.pathname.indexOf('learning-page.html') != -1) {
setTimeout(function function_name(argument) {
if ($(".inside-pages-title:contains('课程学习')") != null) {
$("#afterClassPractice").click();
}
}, time / 2);
} else if (window.location.pathname.indexOf('evaluation.html') != -1) {
window.location.href="https://static.qspfw.moe.gov.cn/user/#/user/login?redirect=%2Factivity";
}
})();
function createFileInput() {
var courseGradeDetail = document.querySelector(".main");
var fileInputHTML = '<div><input type="file" id="file-input" accept=".xls,.xlsx"></div>';
courseGradeDetail.insertAdjacentHTML("afterbegin", fileInputHTML);
var clearButton = document.createElement("button");
clearButton.textContent = "清除缓存";
clearButton.addEventListener("click", function() {
localStorage.removeItem("students");
});
var file = document.querySelector("#file-input");
file.parentNode.appendChild(clearButton);
}
function readFile() {
var fileInput = document.getElementById("file-input");
fileInput.addEventListener("change", function() {
var file = fileInput.files[0];
var reader = new FileReader();
reader.onload = function(e) {
var data = e.target.result;
parseExcelData(data);
};
reader.readAsBinaryString(file);
});
}
function parseExcelData(data) {
var workbook = XLSX.read(data, {type: "binary"});
var sheetName = workbook.SheetNames[0];
var sheet = workbook.Sheets[sheetName];
var json = XLSX.utils.sheet_to_json(sheet, {header: 1});
var students = {};
for (var i = 1; i < json.length; i++) {
var row = json[i];
var id = row[0];
var name = row[1];
var password = row[2];
if (students[id]) {
continue;
}
students[id] = {name: name, password: password};
}
var studentsString = JSON.stringify(students);
localStorage.setItem("students", studentsString);
}
function readAndWriteStudentInfo() {
var students = JSON.parse(localStorage.getItem("students") || "{}");
var keys = Object.keys(students || []);
if (keys.length == 0) {
return;
}
var id = keys[0];
var name = students[id].name;
var paw = students[id].password;
copy_text = id;
var loginInfo = document.getElementById("formLogin_loginInfo");
var userName = document.getElementById("formLogin_userName");
var password = document.getElementById("formLogin_password");
var captcha = document.getElementById("formLogin_captcha");
$(".ant-radio-input").click();
loginInfo.onfocus = async function() {
await navigator.clipboard.writeText(id);
};
userName.onfocus = async function() {
await navigator.clipboard.writeText(name);
};
password.onfocus = async function() {
await navigator.clipboard.writeText(paw);
};
delete students[id];
localStorage.setItem("students", JSON.stringify(students));
}
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
};
function getAnswer(columnId) {
$.ajax({
url: _self.config.practice.host + _self.config.practice.practice + "?columnId="+ columnId + "&taskId=" + _self.config.taskId,
headers: _self.config.apiConfig.header,
async: false,
success: function (res) {
const { data, status } = res;
if (status === "0") {
var question_data = res.data
var questionBankList = data.questionBankList
answer_list = questionBankList;
// 从localStorage中获取已经缓存的答案数组,如果没有则使用一个空数组
var cached_answers = JSON.parse(localStorage.getItem("answers")) || [];
// 遍历每个答案,检查是否已经存在相同id属性的答案
for (var i = 0; i < answer_list.length; i++) {
var answer = answer_list[i];
// 使用find方法或some方法来检查缓存数组中是否已经存在相同id属性的答案
var found_answer = cached_answers.some(function(cached_answer) {
return cached_answer.id == answer.id;
});
// 如果不存在相同id属性的答案,将它追加到缓存数组中
if (!found_answer) {
cached_answers.push(answer);
}
}
// 将更新后的缓存数组重新保存到localStorage中
localStorage.setItem("answers", JSON.stringify(cached_answers));
} else if (status === "1") {
alert("请先学习当前模块");
window.history.go(-1);
} else if (status === "-2") {
alert("请重新登陆");
} else {
}
},
error: function (err) {
}
});
}
// 答题操作
function doQuestion(t) {
var cur_topic = $('#currentTopic').text(),
tol_topic = $('#totalTopic').text(),
answer = answer_list[cur_topic - 1].answer;
$('#exam_answer > div:nth-child(' + num[answer] + ')').click();
if (cur_topic == tol_topic) {
// 清除Interval的定时器
clearInterval(t);
//setTimeout(function(){Swal.fire('宪法小助手提示','答题完成','info')},time / 2);
if ($("#next_exam").css("display") != 'none') {
nextExam();
} else {
toEvaluation();
}
} else{
setTimeout(function(){$('#next_question').click()},time / 5);
};
}
// 获取考试题目
function getExam(){
$.ajax({
url: _self.config.wexam.host + _self.config.wexam.getPaper + "?taskId=" + _self.config.taskId,
headers: _self.config.apiConfig.header,
async: false,
success: function (res) {
const { data, status, message } = res;
if (status === "0") {
var question_data = res.data;
var paper = question_data.paper;
var paperInfo = paper.paperInfo;
exam_list = paperInfo;
} else {
alert('获取考试题目失败!')
}
},
error: function (err) {
}
});
}
// 考试答题操作
function doExam(t){
$('#ne21ans')[0] ? $('#ne21ans').html('<p style="color: red;">正在搜索答案~</p>') : $('#exam_question').append('<div id="ne21ans"><p style="color: red;">正在搜索答案~</p></div>')
var cur_topic = $('#currentTopic').text(),
tol_topic = $('#totalTopic').text(),
questionInfo = exam_list[cur_topic - 1];
// 从localStorage中获取已经缓存的答案数组,如果没有则使用一个空数组
var cached_answers = JSON.parse(localStorage.getItem("answers")) || [];
// 从缓存数组中查找与题目id相同的答案
var cached_answer = cached_answers.find(function(answer) {
return answer.content.replace(/\s+/g, '') == questionInfo.content.replace(/\s+/g, '');
});
if (cached_answer) {
// 如果找到了匹配的答案,直接显示并选择
$('#ne21ans').html('<p style="color: red;">参考答案:'+ cached_answer.answer + '</p>')
$('#exam_answer > div:nth-child(' + num[cached_answer.answer] + ')').click();
} else {
// 如果没有找到匹配的答案,提示用户自己作答或者使用其他方法获取答案
$('#ne21ans').html('<p style="color: red;">没有找到该题目的答案,请自己作答或者尝试刷新页面</p>')
}
if (cur_topic == tol_topic) {
// 清除Interval的定时器
clearInterval(t);
saveResult();
setTimeout(function(){$("button:contains('返回综合评价')").click();},time / 2);
} else{
setTimeout(function(){$('#next_question').click()},time / 5);
};
}