WJX filler

Make filling wjx easier

目前為 2023-04-09 提交的版本,檢視 最新版本

// ==UserScript==
// @name         WJX filler
// @namespace    https://blog.csdn.net/SundaySmarty
// @version      1.0.5
// @description  Make filling wjx easier
// @author       SundaySmarty
// @match        https://ks.wjx.top/vm/*.aspx
// @match        https://www.wjx.cn/vm/*.aspx
// @icon         https://www.wjx.cn/images/commonImgPC/[email protected]
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // 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 = "10000";
    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 fillerHeader = document.createElement("div");
    fillerHeader.style.width = "90%";
    fillerHeader.style.textAlign = "center";
    fillerHeader.style.margin = "5%";

    let header = document.createElement("p");
    header.innerHTML = "WJX filler";
    header.style.fontSize = "24px";
    header.style.fontWeight = "bold";

    let contentContainer = document.createElement("div");
    contentContainer.style.width = "100%";

    document.body.appendChild(fillerButton);
    document.body.appendChild(filler);
    filler.appendChild(fillerContainer);
    fillerContainer.appendChild(fillerHeader);
    fillerHeader.appendChild(header);
    fillerContainer.appendChild(contentContainer);

    function clickFillerButton() {
        if(filler.style.display == "none") {
            filler.style.display = "block";
            fillerButton.textContent = "Close";
        }
        else {
            filler.style.display = "none";
            fillerButton.textContent = "WJX filler";
        }
    }

    // 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 && judgeSingleLetter(field[i])) {
            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;
        }
        if(field[i].getAttribute("type") == 6) {
            rating = true;
        }
    }
    if(numOfMC != 0 && numOfMC % nAtALine != 0) continuousMC.push([firstMCPos, numOfMC]);
    // if(continuousMC.length == 0) window.alert("No continuous multiple choice (single-letter answer) detected!");
    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);
    }

    function judgeSingleLetter(a) {
        for(let i = 0; i < a.children[1].children.length; i++) {
            if(a.children[1].children[i].children[1].innerText.length != 1) {
                return false;
            }
        }
        return true;
    }

    //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);
    	}
    }

    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 = field[continuousMC[i][0]].children[0].innerText.split('\n')[0] + '~' + field[continuousMC[i][0] + continuousMC[i][1] - 1].children[0].innerText.split('\n')[0];
        else MCTitle.innerHTML = 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);
    }

    //SubmitButton
    if(continuousMC.length != 0 || rating) {
        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);
    }

    function clickConfirmButton() {
        for(let i = 0; i < MCInputList.length; i++) {
            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(field[continuousMC[i][0] + j].children[1].children[k].children[1].innerText == MCInputList[i].value[j].toUpperCase() || field[continuousMC[i][0] + j].children[1].children[k].children[1].innerText == MCInputList[i].value[j].toLowerCase()) {
                            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");
        }
    }

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址