Auto Fill Fudan Course Evaluation Questionnaire

Automatically fills the questionnaire with "Strongly Agree" for most questions, "Strongly Disagree" for reverse-scored ones, "无" for open-ended, and first option for the last dynamic question.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Auto Fill Fudan Course Evaluation Questionnaire
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Automatically fills the questionnaire with "Strongly Agree" for most questions, "Strongly Disagree" for reverse-scored ones, "无" for open-ended, and first option for the last dynamic question.
// @author       Grok
// @match        https://ce.fudan.edu.cn/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function autoFill() {
        // Check if the form is loaded by looking for the submit button or questions
        const submitButton = document.querySelector('.index__submit--jiKIA');
        if (!submitButton) {
            // If not loaded, retry after 1 second
            setTimeout(autoFill, 1000);
            return;
        }

        // Get all question containers
        const questions = document.querySelectorAll('.index__subjectItem--XWS1b');

        questions.forEach((question, idx) => {
            // Get the question title text to identify reverse-scored
            const titleElem = question.querySelector('.index__title--aRIbI');
            if (!titleElem) return;

            const titleText = titleElem.innerText.trim();

            // Handle radio buttons (Likert scales)
            const radios = question.querySelectorAll('input[type="radio"]');
            if (radios.length > 0) {
                if (titleText.includes('反向评分')) {
                    // Select the last option (Strongly Disagree) for reverse-scored
                    radios[radios.length - 1].click();
                } else {
                    // Select the first option (Strongly Agree or equivalent) for others
                    radios[0].click();
                }
            }

            // Handle open-ended textareas (fill with "无")
            const textareas = question.querySelectorAll('textarea');
            textareas.forEach(ta => {
                ta.value = '无';
            });
        });

        // Handle the last dynamic multi-select question (checkboxes)
        const checkboxes = document.querySelectorAll('.ant-checkbox-input');
        if (checkboxes.length > 0) {
            // Select the first checkbox
            checkboxes[0].click();

            // Wait briefly for any conditional textarea to appear and fill it
            setTimeout(() => {
                const allTextareas = document.querySelectorAll('textarea');
                if (allTextareas.length > 0) {
                    // Fill the last one or any new one with "无"
                    allTextareas.forEach(ta => {
                        if (ta.value === '') ta.value = '无';
                    });
                }
            }, 500);  // Short delay to allow DOM update
        }

        // Optional: Auto-submit if desired (uncomment if needed)
        // submitButton.click();
    }

    // Run the function after page load, and retry if needed
    window.addEventListener('load', () => {
        setTimeout(autoFill, 2000);  // Initial delay for React to render
    });
})();