// ==UserScript==
// @name WJX producer
// @namespace https://blog.csdn.net/SundaySmarty
// @version 1.0.0
// @description Make producing wjx easier
// @author SundaySmarty
// @match https://www.wjx.cn/mysojump/questionnairemng/designnew.aspx*
// @icon https://www.wjx.cn/images/commonImgPC/[email protected]
// @grant none
// @license MIT
// ==/UserScript==
(function() {
'use strict';
function sleep(time){
return new Promise(resolve => setTimeout(resolve, time));
}
// Basic structure
let producerButton = document.createElement("button");
producerButton.textContent = "WJX producer";
producerButton.style.paddingLeft = "20px";
producerButton.style.paddingRight = "20px";
producerButton.style.height = "30px";
producerButton.style.textAlign = "center";
producerButton.style.background = "thistle";
producerButton.style.color = "white";
producerButton.style.border = "1px solid thistle";
producerButton.style.borderRadius = "4px";
producerButton.style.position = "fixed";
producerButton.style.top = "0";
producerButton.style.right = "0";
producerButton.style.zIndex = "2000";
producerButton.addEventListener("click", clickProducerButton);
let producer = document.createElement("div");
producer.style.width = "40%";
producer.style.height = "100%";
producer.style.background = "white";
producer.style.position = "fixed";
producer.style.top = "0";
producer.style.right = "0";
producer.style.display = "none";
producer.style.zIndex = "1000";
let producerContainer = document.createElement("div");
producerContainer.style.width = "80%";
producerContainer.style.height = "80%";
producerContainer.style.padding = "10%";
producerContainer.style.overflowY = "auto";
producerContainer.style.overflowX = "hidden";
let producerHeaderContainer = document.createElement("div");
producerHeaderContainer.style.width = "90%";
producerHeaderContainer.style.textAlign = "center";
producerHeaderContainer.style.margin = "5%";
let producerHeader = document.createElement("p");
producerHeader.innerHTML = "WJX producer";
producerHeader.style.fontSize = "24px";
producerHeader.style.fontWeight = "bold";
producerHeader.style.color = "black";
let contentContainer = document.createElement("div");
contentContainer.style.width = "100%";
let usageButton = document.createElement("button");
usageButton.textContent = "Usage";
usageButton.style.paddingLeft = "20px";
usageButton.style.paddingRight = "20px";
usageButton.style.height = "30px";
usageButton.style.textAlign = "center";
usageButton.style.background = "thistle";
usageButton.style.color = "white";
usageButton.style.border = "1px solid thistle";
usageButton.style.borderRadius = "4px";
usageButton.style.position = "fixed";
usageButton.style.top = "0";
usageButton.style.zIndex = "3000";
usageButton.addEventListener("click", clickUsageButton);
let usage = document.createElement("div");
usage.style.width = "40%";
usage.style.height = "100%";
usage.style.background = "white";
usage.style.position = "fixed";
usage.style.top = "0";
usage.style.right = "0";
usage.style.display = "none";
usage.style.zIndex = "2500";
let usageContainer = document.createElement("div");
usageContainer.style.width = "80%";
usageContainer.style.height = "80%";
usageContainer.style.padding = "10%";
usageContainer.style.overflowY = "auto";
usageContainer.style.overflowX = "hidden";
let usageHeaderContainer = document.createElement("div");
usageHeaderContainer.style.width = "90%";
usageHeaderContainer.style.textAlign = "center";
usageHeaderContainer.style.margin = "5%";
let usageHeader = document.createElement("p");
usageHeader.innerHTML = "WJX producer usage";
usageHeader.style.fontSize = "24px";
usageHeader.style.fontWeight = "bold";
usageHeader.style.color = "black";
let usageContentContainer = document.createElement("div");
usageContentContainer.style.width = "100%";
document.body.appendChild(producerButton);
document.body.appendChild(producer);
producer.appendChild(producerContainer);
producerContainer.appendChild(producerHeaderContainer);
producerHeaderContainer.appendChild(producerHeader);
producerContainer.appendChild(contentContainer);
producer.appendChild(usageButton);
producer.appendChild(usage);
usage.appendChild(usageContainer);
usageContainer.appendChild(usageHeaderContainer);
usageHeaderContainer.appendChild(usageHeader);
usageContainer.appendChild(usageContentContainer);
writePInUsage('A textbox will appear when you enter WJX Producer.');
writePInUsage('The format of your input in this textbox is "S/N of your question; number of choices; score of each question; available choices"(no quotation marks).');
writePInUsage('For example, if you enter "1~2,5;4;1;ABCDEFGH", then Question 1, 2 and 5 will be produced. Each of the three questions will have 4 choices and a score of 1. The available choices of question 1 and 5 will be ABCD and the available choices of question 2 will be EFGH.');
writeImgInUsage("https://s6.imgcdn.dev/rSdRe.png");
writePInUsage('After clicking Confirm Button, you can set answers for each of your questions as shown below.');
writeImgInUsage("https://s6.imgcdn.dev/rSWUC.png");
function clickProducerButton() {
if(producer.style.display == "none") {
producer.style.display = "block";
producerButton.textContent = "Close";
}
else {
producer.style.display = "none";
producerButton.textContent = "WJX producer";
}
}
function clickUsageButton() {
if(usage.style.display == "none") {
usage.style.display = "block";
usageButton.textContent = "Close";
producerButton.style.display = "none";
}
else {
usage.style.display = "none";
usageButton.textContent = "Usage";
producerButton.style.display = "block";
}
}
function writePInUsage(text) {
let p = document.createElement("p");
p.style.width = "90%";
p.style.margin = "5%";
p.style.fontSize = "18px";
p.style.color = "black";
p.style.wordBreak = "normal";
p.innerHTML = text;
usageContentContainer.appendChild(p);
}
function writeImgInUsage(imgURL) {
let imgContainer = document.createElement("div");
imgContainer.style.textAlign = "center";
let img = document.createElement("img");
img.setAttribute("src", imgURL);
img.style.width = "80%";
usageContentContainer.appendChild(imgContainer);
imgContainer.appendChild(img);
}
let testQuestionBar = document.getElementById("divKaoShiT");
if(testQuestionBar.style.display != "none") {
let MCHeaderContainer = document.createElement("div");
MCHeaderContainer.style.width = "90%";
MCHeaderContainer.style.margin = "5%";
let MCHeader = document.createElement("p");
MCHeader.innerHTML = "Multiple Choice";
MCHeader.style.fontWeight = "bold";
MCHeader.style.fontSize = "20px";
MCHeader.style.color = "black";
contentContainer.appendChild(MCHeaderContainer);
MCHeaderContainer.appendChild(MCHeader);
let MCNumInputContainer = document.createElement("div");
MCNumInputContainer.style.width = "90%";
MCNumInputContainer.style.margin = "5%";
var MCNumInput = document.createElement("input");
MCNumInput.setAttribute("type", "text");
MCNumInput.style.width = "100%";
MCNumInput.style.height = "30px";
MCNumInput.style.fontSize = "20px";
contentContainer.appendChild(MCNumInputContainer);
MCNumInputContainer.appendChild(MCNumInput);
var submitButtonContainer = document.createElement("div");
submitButtonContainer.style.width = "90%";
submitButtonContainer.style.margin = "5%";
submitButtonContainer.style.textAlign = "center";
var confirmButton = document.createElement("button");
confirmButton.style.paddingLeft = "20px";
confirmButton.style.paddingRight = "20px";
confirmButton.style.height = "30px";
confirmButton.textContent = "Confirm";
confirmButton.addEventListener("click", clickConfirmButton);
contentContainer.appendChild(submitButtonContainer);
submitButtonContainer.appendChild(confirmButton);
var covering = document.createElement("div");
covering.style.width = "100%";
covering.style.height = "100%";
covering.style.background = "grey";
covering.style.opacity = "0.4";
covering.style.position = "fixed";
covering.style.top = "0";
covering.style.left = "0";
covering.style.display = "none";
covering.style.zIndex = "1000";
document.body.appendChild(covering);
}
let pos = 0;
let numOfChoice = 0;
let score = 0;
let startChoice = [];
let MCInputList = [];
let continuousMC = [];
let scoreAvailable = [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 60, 70, 80, 90, 100];
function clickConfirmButton() {
if(pos == 0) {
let stop = false;
MCNumInput.value = MCNumInput.value.replace(/\s*/g,"");
let input = MCNumInput.value.split(";");
if(input.length != 4) window.alert("Wrong Input!");
else {
for(let i = 0; i < input.length; i++) {
if(input[i] == "") {
stop = true;
window.alert("Wrong Input!");
break;
}
}
if(!stop) {
if(isNaN(Number(input[1])) || isNaN(Number(input[2])) || !(Number(input[1]) >= 2) || !(Number.isInteger(Number(input[1]))) || !(scoreAvailable.indexOf(Number(input[2])) >= 0) || !(/^[a-zA-Z]+$/.test(input[3]))) {
stop = true;
window.alert("Wrong Input!");
}
else {
numOfChoice = Number(input[1]);
score = Number(input[2]);
input[3] = input[3].toUpperCase();
startChoice = input[3].split("");
if(startChoice.length % numOfChoice != 0) {
stop = true;
window.alert("Wrong Input!");
}
if(!stop) {
let MCNumSection = input[0].split(',');
for(let i = 0; i < MCNumSection.length; i++) {
if(MCNumSection[i] == "") {
stop = true;
window.alert("Wrong Input!");
break;
}
}
if(!stop) {
continuousMC = [];
let checkOverlap = true;
let checkOverlapList = [];
for(let i = 0; i < MCNumSection.length; i++) {
let range = MCNumSection[i].split('~');
if(range.length == 1) {
if(range[0] == "" || isNaN(Number(range[0])) || !(Number.isInteger(Number(range[0])))) {
stop = true;
window.alert("Wrong Input!");
break;
}
else {
if(!checkOverlapList.includes(Number(range[0]))) checkOverlapList.push(Number(range[0]));
else {
stop = true;
window.alert("Wrong Input!");
break;
}
continuousMC.push([Number(range[0]), 1]);
}
}
else if(range.length == 2) {
if(range[0] == "" || range[1] == "" || isNaN(Number(range[0])) || isNaN(Number(range[1])) || !(Number.isInteger(Number(range[0]))) || !(Number.isInteger(Number(range[1]))) || Number(range[1]) < Number(range[0])) {
stop = true;
window.alert("Wrong Input!");
break;
}
else {
for(let j = Number(range[0]); j <= Number(range[1]); j++) {
if(!checkOverlapList.includes(j)) checkOverlapList.push(j);
else {
stop = true;
window.alert("Wrong Input!");
break;
}
}
if(!stop) {
let nAtALine = 15;
let j = Number(range[0]);
while(j + nAtALine - 1 <= Number(range[1])) {
continuousMC.push([j, nAtALine]);
j += nAtALine;
}
if(Number(range[1]) >= j) continuousMC.push([j, Number(range[1]) - j + 1]);
}
}
}
else {
stop = true;
window.alert("Wrong Input!");
break;
}
}
if(!stop) {
pos++;
MCNumInput.style.display = "none";
MCInputList = [];
continuousMC = continuousMC.sort(function(a, b){return a[0] - b[0];});
for(let j = 0; j < continuousMC.length; j++) {
let MCTitleContainer = document.createElement("div");
MCTitleContainer.style.width = "90%";
MCTitleContainer.style.margin = "5%";
let MCTitle = document.createElement("p");
MCTitle.style.color = "black";
MCTitle.style.fontSize = "18px";
if(continuousMC[j][1] == 1) MCTitle.innerHTML = continuousMC[j][0];
else MCTitle.innerHTML = continuousMC[j][0] + '~' + (continuousMC[j][0] + continuousMC[j][1] - 1);
let MCInputContainer = document.createElement("div");
MCInputContainer.style.width = "90%";
MCInputContainer.style.margin = "5%";
let MCInput = document.createElement("input");
MCInput.setAttribute("type", "text");
MCInput.style.width = "100%";
MCInput.style.height = "30px";
MCInput.style.fontSize = "20px";
contentContainer.insertBefore(MCTitleContainer, submitButtonContainer);
MCTitleContainer.appendChild(MCTitle);
contentContainer.insertBefore(MCInputContainer, submitButtonContainer);
MCInputContainer.appendChild(MCInput);
MCInputList.push(MCInput);
}
covering.style.display = "block";
confirmButton.disabled = true;
for(let i = 0; i < MCInputList.length; i++) MCInputList[i].disabled = true;
(async () => {
await clearQuestion();
await addMC(continuousMC[continuousMC.length - 1][0] + continuousMC[continuousMC.length - 1][1] - 1);
await setScoreAndNum(numOfChoice, score, continuousMC);
})()
.then(() => {
covering.style.display = "none";
confirmButton.disabled = false;
for(let i = 0; i < MCInputList.length; i++) MCInputList[i].disabled = false;
})
}
}
}
}
}
}
}
else if(pos == 1) {
let stop = false;
let numOfQuestion = 0;
let choiceNumList = [];
for(let i = 0; i < MCInputList.length; i++) {
MCInputList[i].value = MCInputList[i].value.replace(/\s*/g,"");
if(MCInputList[i].value.length != continuousMC[i][1] || !(/^[a-zA-Z]+$/.test(MCInputList[i].value))) {
stop = true;
window.alert("Wrong Input!");
break;
}
else {
MCInputList[i].value = MCInputList[i].value.toUpperCase();
let tempNumList = [];
for(let j = 0; j < MCInputList[i].value.length; j++) {
let flag = false;
for(let k = 0; k < numOfChoice; k++) {
if(MCInputList[i].value[j] == startChoice[(numOfQuestion % (startChoice.length / numOfChoice)) * numOfChoice + k]) {
flag = true;
tempNumList.push(k);
}
}
if(!flag) {
stop = true;
window.alert("Wrong Input!");
break;
}
numOfQuestion++;
}
choiceNumList.push(tempNumList);
}
}
if(!stop) {
covering.style.display = "block";
setAnswer(continuousMC, choiceNumList);
covering.style.display = "none";
confirmButton.disabled = true;
for(let i = 0; i < MCInputList.length; i++) MCInputList[i].disabled = true;
}
}
}
async function activateQuestion() {
let question = document.getElementsByClassName("div_question");
for(let i = 0; i < question.length; i++) {
if(question[i].getAttribute("title") === null || question[i].getAttribute("title") == "") {
question[i].children[0].dispatchEvent(new MouseEvent("mouseover",{"bubbles": true}));
await sleep(0.1);
question[i].children[0].click();
await sleep(0.1);
question[i].children[0].click();
await sleep(0.1);
question[i].children[0].dispatchEvent(new MouseEvent("mouseout",{"bubbles": true}));
await sleep(0.1);
}
}
}
async function clearQuestion() {
let question = document.getElementsByClassName("div_question");
let i = question.length - 1;
await activateQuestion()
.then(() => {
while(i >= 0) {
if((question[i].getAttribute("title") === null || question[i].getAttribute("title") == "") && question[i].children[0].children[0].children[0].textContent != "") {
question[i].children[0].children[2].children[3].children[0].children[2].dispatchEvent(new MouseEvent("mouseover",{"bubbles": true}));
question[i].children[0].children[2].children[3].children[0].children[2].children[0].dispatchEvent(new MouseEvent("click",{"bubbles": true}));
}
i--;
}
});
}
async function addMC(n) {
let questionTypeList = testQuestionBar.children[1].children[1];
let MC = questionTypeList.children[0].children[0];
for(let i = 0; i < n; i++) {
MC.click();
}
}
async function setScoreAndNum(num, score, MCList) {
let question = document.getElementsByClassName("div_question");
await activateQuestion()
.then(() => {
let k = 0;
let numOfQuestion = 0;
for(let i = 0; i < MCList.length; i++) {
for(let j = MCList[i][0]; j < MCList[i][0] + MCList[i][1]; j++) {
while(true) {
if((question[k].getAttribute("title") === null || question[k].getAttribute("title") == "") && question[k].children[0].children[0].children[0].textContent != "") {
if(question[k].children[0].children[0].children[0].textContent == j) {
question[k].children[0].click();
let scoreSelect = question[k].children[1].children[0].children[1].children[2].children[3].children[0].children[0].children[1];
let choice = question[k].children[1].children[0].children[3].children[1].children[0].children[1].children[0].children[0];
let addChoice = choice.children[1].children[0].children[1];
scoreSelect.value = score;
scoreSelect.dispatchEvent(new Event("change", {"bubbles": true}));
for(let i = 0; i < num - 2; i++) {
addChoice.click();
}
for(let i = 0; i < num; i++) {
let choiceInput = choice.children[i + 1].children[0].children[0];
choiceInput.value = startChoice[(numOfQuestion % (startChoice.length / num)) * num + i];
}
question[k].children[0].click();
numOfQuestion++;
break;
}
}
k++;
}
}
}
if(numOfQuestion == 1) question[k].children[0].click();
});
}
function setAnswer(MCList, choiceNumList) {
let question = document.getElementsByClassName("div_question");
let k = 0;
for(let i = 0; i < MCList.length; i++) {
let numOfQuestion = 0;
for(let j = MCList[i][0]; j < MCList[i][0] + MCList[i][1]; j++) {
while(true) {
if((question[k].getAttribute("title") === null || question[k].getAttribute("title") == "") && question[k].children[0].children[0].children[0].textContent != "") {
if(question[k].children[0].children[0].children[0].textContent == j) {
question[k].children[0].click();
let choice = question[k].children[1].children[0].children[3].children[1].children[0].children[1].children[0].children[0];
if(choiceNumList[i][numOfQuestion] != 0) choice.children[choiceNumList[i][numOfQuestion] + 1].children[5].children[0].children[1].click();
question[k].children[0].click();
numOfQuestion++;
break;
}
}
k++;
}
}
}
}
})();