/***欢迎使用网页自动获取题目匹配题库答案填充(原创1.0)**
1.可手动添加本地题库,
一键复制,
无序key自动匹配,
2.通过调试可获取相应div类下的值/元素
3.遍历实现多选,可在console中执行
4.不足指出还请海涵与指点,谢谢
---------------------调试块----------------------------
1.43行,题库
2.72行,get题目答案,{"key":"value"}
3.104行,get答题类
***/
var setting = [];
var minimum = [];
minimum.div = $(
'<div style="padding: 5px;border: 1px dashed rgb(0, 85, 68); position: fixed; top: 8px; right: 5px; z-index: 99999; background-color: rgba(184, 247, 255, 0.2); overflow-x: auto;display:block;">最大化' + '</div>'
).appendTo('body').click(function () {
$(setting.div).css('display', 'block');
$(minimum.div).css('display', 'none');
});
var ad = "To learn for happy with our flock";
setting.div = $(
'<div style="border: 1px dashed rgb(0, 85, 68); width: 330px; position: fixed; top: 8px; right: 5px; z-index: 99999; background-color: rgba(184, 247, 255, 0.9);display:none;">' +
'<span style="font-size: medium;"></span>' +
'<div style="display: inline-block;box-sizing: border-box;top:0;right:0;"><minimize style="position:absolute;top:5px;right:6px;width:5%;font-size:16px;line-height: 12px;font-weight: bold; cursor:context-menu; user-select:none;">一</minimize></div>' +
'<div id="cx-notice" style="font-size:18px;color:red;font-family: Times New Roman;text-align: center;height:24px;border-top: 0px solid #000;border-bottom: 1px solid #000;margin: 1px 0px;overflow: hidden;">' + ad + '</div>' +
'<input id="timu01" type="text" placeholder="题目答案类" style="width:100px;margin-left: 10px;">' + '<input id="da01" type="text" placeholder="题目答案类" style="width:100px;margin-left: 10px;">' +
'<button id="timuda" style="width:25%;margin: 4px 8px;background-color: rgba(184, 247, 255, 0.4);">一键获取' + '</button>' +
'<button id="mc" style="height:30px;width:70%;margin: 2px 49px;background-color: rgba(184, 247, 255, 0.4);">复制(手动添加arr)</button>' +
'<input id="exam" type="text" placeholder="考试题目类" style="width:35%;margin:3px 20px;">' +'<input id="examda" type="text" placeholder="考试答案类" style="width:35%;margin:3px 20px;">'+
'<button id="examing" style="height:30px;width:70%;background-color: rgba(184, 247, 255, 0.4);margin: 2px 49px;">开始答题(选择)</button>' +
'<div id="vi_con" style="width:99%;display: inline-block;OVERFLOW-Y: auto; padding-top: 3px;padding-left: 3px;padding-bottom: 0px;FONT-SIZE: 10pt;OVERFLOW: auto;LINE-HEIGHT: 100%; FONT-FAMILY: 宋体; HEIGHT:93px; TEXT-ALIGN: left;"></div>' +
'</div>'
).appendTo('body');
$('minimize').click(function () {
$(setting.div).css('display', 'none');
$(minimum.div).css('display', 'block');
});
var err = 0;
var arr = {
// 题库需手动添加,格式可借助IDE,快速排版~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"世界()": "D",
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
var timuda = document.getElementById('timuda');
timuda.addEventListener("click", mfGettimuda, false);
function mfGettimuda() {
var timu = document.getElementById('timu01').value, da = document.getElementById('da01').value;
var items = document.getElementsByClassName(timu).length;
if (err == 0) {
alert('答案题目不显示,调试:\ndocument.getElementsByClassName(timu/da)[0].children[0].innerText.slice(10,-8)');
err += 1;
}
if (timu.length <= 0) {
alert("1号输入框不能为空");
} else if (da.length <= 0) {
alert("2号输入框不能为空");
} else {
for (var i = 0; i <= items; i++) {
// 可调式区~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var gett = document.getElementsByClassName(timu)[i].children[0].innerText.slice(10, -8);
var getd = document.getElementsByClassName(da)[i].children[3].innerText.slice(5);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
document.getElementById('vi_con').append('"' + gett + '":"' + getd + '",');
}
}
};
var mc = document.getElementById('mc');
mc.addEventListener("click", mfCopy, false);
function mfCopy() {
var copyTest = document.getElementById("vi_con").innerText;
var inputTest = document.createElement('input');
inputTest.value = copyTest;
document.body.appendChild(inputTest);
inputTest.select();
document.execCommand("Copy");
inputTest.className = 'oInput';
inputTest.style.display = 'none';
alert('复制成功');
// textarea标签的复制粘贴,主要是文本格式跟自己设计显示的SAme------
// var copyTest = document.getElementById("vi_con").value;
// var save = function (e) {
// e.clipboardData.setData('text/plain', copyTest);
// e.preventDefault(); //阻止默认行为
// }
// document.addEventListener('copy', save);
// document.execCommand("copy"); //使文档处于可编辑状态,否则无效
// var inputTest = document.createElement('input');
// inputTest.value = copyTest;
// document.body.appendChild(inputTest);
// inputTest.select();
// document.execCommand("Copy");
// inputTest.className = 'oInput';
// inputTest.style.display = 'none';
}
var examing = document.getElementById('examing');
examing.addEventListener("click", mfExam, false);
function mfExam() {
// 可调式区~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
var examVa = document.getElementById('exam').value
var examDa = document.getElementById('examda').value
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (examVa.length <= 0) {
alert('缺少考试题目 div class 父类');
}else if(examDa.length <= 0) {
alert('缺少答案题目 div class 父类');
}else {
if (err == 0) {
alert('操作无效,调试获取考试题目与答案类');
err += 1;
}
var items = document.getElementsByClassName(examVa).length;
var i = 0;
for (i; i <= items; i++) {
var item = document.getElementsByClassName(examVa)[i].children[0].innerText.slice(10, -8);
var vs = arr[item];
// vs = "ABC"
if (vs == null) {
alert('arr题库中没有,请手动更新' + item);
document.getElementById('vi_con').append(item + ",,,");
i += 1;
//break;
} else {
var aRlen = vs.length;
// 不同条件筛选 实现的方法之一,多选可遍历选择答案
for (var j = 0; j <= aRlen; j++) {
var getAnRadio = vs[j];
switch (getAnRadio) {
case "A":
document.getElementsByClassName(examDa)[i].children[0].click();
break;
case "B":
document.getElementsByClassName(examDa)[i].children[2].click();
break;
case "C":
document.getElementsByClassName(examDa)[i].children[4].click();
break;
case "D":
document.getElementsByClassName(examDa)[i].children[6].click();
break;
}
}
}
}
}
}
IDE数据处理
版权声明:本文为sugarbew原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。