// ==UserScript== // @name WJX filler // @namespace https://blog.csdn.net/SundaySmarty // @version 1.0.12 // @description Make filling wjx easier // @author SundaySmarty // @match https://*.wjx.top/vm/*.aspx // @match https://*.wjx.cn/vm/*.aspx // @match https://*.wjx.top/vj/*.aspx // @match https://*.wjx.cn/vj/*.aspx // @icon https://www.wjx.cn/images/commonImgPC/logo@2x.png // @grant none // @license MIT // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Cancel restriction of copy & paste document.oncontextmenu = document.onselectstart = null; // Change path let path = location.pathname; let path1 = path.substring(0, path.substring(1).indexOf('/') + 1); let path2 = path.substring(path.substring(1).indexOf('/') + 1); if(path1 == "/vj") location.href = "https://" + location.host + "/vm" + path2; // Basic structure let fillerButton = document.createElement("button"); fillerButton.textContent = "WJX filler"; fillerButton.style.paddingLeft = "20px"; fillerButton.style.paddingRight = "20px"; fillerButton.style.height = "30px"; fillerButton.style.textAlign = "center"; fillerButton.style.background = "thistle"; fillerButton.style.color = "white"; fillerButton.style.border = "1px solid thistle"; fillerButton.style.borderRadius = "4px"; fillerButton.style.position = "fixed"; fillerButton.style.top = "0"; fillerButton.style.right = "0"; fillerButton.style.zIndex = "2000"; fillerButton.addEventListener("click", clickFillerButton); let filler = document.createElement("div"); filler.style.width = "40%"; filler.style.height = "100%"; filler.style.background = "white"; filler.style.position = "fixed"; filler.style.top = "0"; filler.style.right = "0"; filler.style.display = "none"; filler.style.zIndex = "1000"; let fillerContainer = document.createElement("div"); fillerContainer.style.width = "100%"; fillerContainer.style.height = "100%"; fillerContainer.style.padding = "10%"; fillerContainer.style.overflowY = "auto"; fillerContainer.style.overflowX = "hidden"; let fillerHeaderContainer = document.createElement("div"); fillerHeaderContainer.style.width = "90%"; fillerHeaderContainer.style.textAlign = "center"; fillerHeaderContainer.style.margin = "5%"; let fillerHeader = document.createElement("p"); fillerHeader.innerHTML = "WJX filler"; fillerHeader.style.fontSize = "24px"; fillerHeader.style.fontWeight = "bold"; 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 scrollToTopButton = document.createElement("button"); scrollToTopButton.textContent = "Top"; scrollToTopButton.style.paddingLeft = "20px"; scrollToTopButton.style.paddingRight = "20px"; scrollToTopButton.style.height = "30px"; scrollToTopButton.style.textAlign = "center"; scrollToTopButton.style.background = "thistle"; scrollToTopButton.style.color = "white"; scrollToTopButton.style.border = "1px solid thistle"; scrollToTopButton.style.borderRadius = "4px"; scrollToTopButton.style.position = "fixed"; scrollToTopButton.style.bottom = "0"; scrollToTopButton.style.zIndex = "2000"; scrollToTopButton.addEventListener("click", clickScrollToTopButton); let scrollToBottomButton = document.createElement("button"); scrollToBottomButton.textContent = "Bottom"; scrollToBottomButton.style.paddingLeft = "20px"; scrollToBottomButton.style.paddingRight = "20px"; scrollToBottomButton.style.height = "30px"; scrollToBottomButton.style.textAlign = "center"; scrollToBottomButton.style.background = "thistle"; scrollToBottomButton.style.color = "white"; scrollToBottomButton.style.border = "1px solid thistle"; scrollToBottomButton.style.borderRadius = "4px"; scrollToBottomButton.style.position = "fixed"; scrollToBottomButton.style.bottom = "0"; scrollToBottomButton.style.right = "0"; scrollToBottomButton.style.zIndex = "2000"; scrollToBottomButton.addEventListener("click", clickScrollToBottomButton); 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 = "100%"; usageContainer.style.height = "100%"; 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 filler usage"; usageHeader.style.fontSize = "24px"; usageHeader.style.fontWeight = "bold"; let usageContentContainer = document.createElement("div"); usageContentContainer.style.width = "100%"; document.body.appendChild(fillerButton); document.body.appendChild(filler); filler.appendChild(fillerContainer); fillerContainer.appendChild(fillerHeaderContainer); fillerHeaderContainer.appendChild(fillerHeader); fillerContainer.appendChild(contentContainer); filler.appendChild(usageButton); filler.appendChild(scrollToTopButton); filler.appendChild(scrollToBottomButton); filler.appendChild(usage); usage.appendChild(usageContainer); usageContainer.appendChild(usageHeaderContainer); usageHeaderContainer.appendChild(usageHeader); usageContainer.appendChild(usageContentContainer); writePInUsage("WJX filler can only detect multiple choice and rating questions."); writePInUsage("For multiple choice, you need to enter your answer into the textbox and WJX filler will automatically click your answer of each multiple choice."); writePInUsage("For example, if you enter AB in the textbox under 1~2, then choice A will be clicked for question 1 and choice B will be clicked for question 2."); writePInUsage("Enter * if you want to leave that question blank."); writeImgInUsage("https://s6.imgcdn.dev/r1P6T.png"); writePInUsage("For rating questions, if you enter n (a positive integer) in the textbox, then the nth choice would be clicked for all rating questions."); writeImgInUsage("https://s6.imgcdn.dev/r15Lt.png"); writePInUsage("Plus, top button is for scrolling to top and bottom button is for scrolling to bottom."); let canFocus = false; function clickFillerButton() { if(filler.style.display == "none") { filler.style.display = "block"; fillerButton.textContent = "Close"; if(canFocus) { MCInputList[0].focus(); } } else { filler.style.display = "none"; fillerButton.textContent = "WJX filler"; } } function clickUsageButton() { if(usage.style.display == "none") { usage.style.display = "block"; usageButton.textContent = "Close"; fillerButton.style.display = "none"; } else { usage.style.display = "none"; usageButton.textContent = "Usage"; fillerButton.style.display = "block"; } } function clickScrollToTopButton() { scrollTo({ top: 0, behavior: "smooth" }); } function clickScrollToBottomButton() { scrollTo({ top: document.documentElement.scrollHeight, behavior: "smooth" }); } function writePInUsage(text) { let p = document.createElement("p"); p.style.width = "90%"; p.style.margin = "5%"; 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); } // Find continuous multiple choice let field = document.getElementsByClassName("field ui-field-contain"); let nameField; let rating = false; let continuousMC = []; let numOfMC = 0; let firstMC = true; let firstMCPos = 0; let nAtALine = 15; for(let i = 0; i < field.length; i++) { // Name if(field[i].getAttribute("type") == 1 && field[i].children[1].children[0].getAttribute("verify") == "姓名") { nameField = field[i]; } // Multiple Choice if(field[i].getAttribute("type") == 3) { numOfMC++; if(firstMC) { firstMC = false; firstMCPos = i; } if(numOfMC % nAtALine == 0) { continuousMC.push([firstMCPos, numOfMC]); firstMC = true; numOfMC = 0; } } else { if(numOfMC != 0 && numOfMC % nAtALine != 0) continuousMC.push([firstMCPos, numOfMC]); firstMC = true; numOfMC = 0; } // Rating if(field[i].getAttribute("type") == 6 && field[i].getAttribute("ischeck") === null) { console.log(field[i].getAttribute("ischeck")); rating = true; } } if(numOfMC != 0 && numOfMC % nAtALine != 0) continuousMC.push([firstMCPos, numOfMC]); if(continuousMC.length != 0) { 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"; contentContainer.appendChild(MCHeaderContainer); MCHeaderContainer.appendChild(MCHeader); } if(rating) { let ratingHeaderContainer = document.createElement("div"); ratingHeaderContainer.style.width = "90%"; ratingHeaderContainer.style.margin = "5%"; let ratingHeader = document.createElement("p"); ratingHeader.innerHTML = "Rating"; ratingHeader.style.fontWeight = "bold"; ratingHeader.style.fontSize = "20px"; contentContainer.appendChild(ratingHeaderContainer); ratingHeaderContainer.appendChild(ratingHeader); let ratingInputContainer = document.createElement("div"); ratingInputContainer.style.width = "90%"; ratingInputContainer.style.margin = "5%"; var ratingInput = document.createElement("input"); ratingInput.setAttribute("type", "text"); ratingInput.style.width = "100%"; ratingInput.style.height = "30px"; ratingInput.style.fontSize = "20px"; contentContainer.appendChild(ratingInputContainer); ratingInputContainer.appendChild(ratingInput); } //NameAutoSet if(nameField != null || typeof(nameField) != "undefined") { checkCookie(); nameField.children[1].children[0].addEventListener("input", nameAutoSet); } function nameAutoSet() { let username = nameField.children[1].children[0].value; if (username != "" && username != null){ setCookie("username", username, 365 * 100); } else document.cookie = "username=; expires=Mon, 01 Jan 2018 00:00:00 GMT"; } function setCookie(para, cvalue, exdays){ let date = new Date(); date.setTime(date.getTime() + (exdays * 24 * 60 * 60 * 1000)); let expires = "expires=" + date.toGMTString(); document.cookie = para + "=" + cvalue + "; " + expires; } function getCookie(para){ let name = para + "="; let ca = document.cookie.split(';'); for(let i = 0; i < ca.length; i++) { let c = ca[i].trim(); if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } function checkCookie(){ let username = getCookie("username"); if (username != ""){ nameField.children[1].children[0].value = username; } } // Show MCInput let MCInputList = []; for(let i = 0; i < continuousMC.length; i++) { let MCTitleContainer = document.createElement("div"); MCTitleContainer.style.width = "90%"; MCTitleContainer.style.margin = "5%"; let MCTitle = document.createElement("p"); if(continuousMC[i][1] != 1) MCTitle.innerHTML = getSN(field[continuousMC[i][0]].children[0].innerText.split('\n')[0]) + '~' + getSN(field[continuousMC[i][0] + continuousMC[i][1] - 1].children[0].innerText.split('\n')[0]); else MCTitle.innerHTML = getSN(field[continuousMC[i][0]].children[0].innerText.split('\n')[0]); 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.appendChild(MCTitleContainer); MCTitleContainer.appendChild(MCTitle); contentContainer.appendChild(MCInputContainer); MCInputContainer.appendChild(MCInput); MCInputList.push(MCInput); } for(let i = 0; i < MCInputList.length; i++) { let prev = i - 1; let next = i + 1; if(prev < 0) prev += MCInputList.length; if(next == MCInputList.length) next = 0; MCInputList[i].addEventListener("keydown", function(e) { if(e.keyCode === 38) { MCInputList[prev].focus(); } else if(e.keyCode === 40) { MCInputList[next].focus(); } }); } function getSN(str) { let SN = ""; let pos = 0; while(pos < str.length) { if(!isNaN(parseFloat(str[pos])) && isFinite(str[pos])) { SN += str[pos]; } else break; pos++; } if(SN.length != 0) return SN; else return str; } //SubmitButton if(continuousMC.length != 0 || rating) { canFocus = true; let submitButtonContainer = document.createElement("div"); submitButtonContainer.style.width = "90%"; submitButtonContainer.style.margin = "5%"; submitButtonContainer.style.textAlign = "center"; let 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); filler.addEventListener("keydown", function(e) { if(e.keyCode === 13) {clickConfirmButton();} }); } function clickConfirmButton() { for(let i = 0; i < MCInputList.length; i++) { MCInputList[i].value = MCInputList[i].value.replace(/\s*/g,""); MCInputList[i].value = MCInputList[i].value.toUpperCase(); if(MCInputList[i].value.length != continuousMC[i][1]) { window.alert("Wrong input length!\nError position: Multiple Choice Line " + (i + 1)); break; } else { for(let j = 0; j < MCInputList[i].value.length; j++) { let correctChoice = false; for(let k = 0; k < field[continuousMC[i][0] + j].children[1].children.length; k++) { if(MCInputList[i].value[j] == "*") { correctChoice = true; continue; } if((field[continuousMC[i][0] + j].children[1].children[k].children[1].innerText.length == 1 && field[continuousMC[i][0] + j].children[1].children[k].children[1].innerText[0].toUpperCase() == MCInputList[i].value[j]) || String.fromCharCode(65 + k) == MCInputList[i].value[j]) { field[continuousMC[i][0] + j].children[1].children[k].children[0].children[1].click(); correctChoice = true; } } if(!correctChoice) { window.alert("Match choice failed!\nError position: Multiple Choice Line" + (i + 1) + " " + field[continuousMC[i][0] + j].children[0].innerText.split('\n')[0]); break; } } } } if(rating) { let ratingChoice = document.getElementsByClassName("rate-off rate-offlarge"); let ratingMatch = false; for(let i = 0; i < ratingChoice.length; i++) { if(ratingChoice[i].getAttribute("dval") == ratingInput.value) { ratingChoice[i].click(); ratingMatch = true; } } if(!ratingMatch) window.alert("Match choice failed!\nError position: Rating"); } } })();