Greasy Fork is available in English.

Auto Survey UIT

Tự động đánh giá môn học UIT (LimeSurvey)

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Auto Survey UIT
// @namespace    http://tampermonkey.net/
// @version      1.0
 // @license MIT
// @description  Tự động đánh giá môn học UIT (LimeSurvey)
// @author       NaruZeno
// @match        *://survey.uit.edu.vn/*
// @grant        window.close
// ==/UserScript==

(function() {
    'use strict';

    // Đặt độ trễ 1 giây (1000ms) để đảm bảo trang và các script mặc định đã load xong
    setTimeout(function() {

        // Xác định xem có nút Next hay Submit trên trang không
        let nextBtn = document.getElementById('movenextbtn');
        let submitBtn = document.getElementById('movesubmitbtn');
        let groupNameEl = document.querySelector('.group-name');
        // KIỂM TRA TRANG HOÀN THÀNH
        // Nếu trang không có nút Tiếp theo, không có nút Gửi, và không có tiêu đề nhóm câu hỏi
        // -> Rất có thể đây là trang thông báo hoàn thành khảo sát
        if (!nextBtn && !submitBtn && !groupNameEl) {
            console.log('Đã hoàn thành khảo sát. Tự động đóng tab sau 2 giây...');
            setTimeout(() => {
                window.close(); // Đóng tab
            }, 1000); // Delay 2s để bạn kịp nhìn thấy thông báo thành công (có thể chỉnh xuống 0 nếu muốn đóng ngay)
            return;
        }
        // BƯỚC 1, 2, 3: Trang Welcome / Không có nhóm câu hỏi -> Chỉ ấn Next
        if (!groupNameEl) {
            if (nextBtn) {
                console.log('Đang ở trang chào mừng, tự động ấn Tiếp theo...');
                nextBtn.click();
            }
            return;
        }

        let groupName = groupNameEl.innerText.trim();

        // BƯỚC 4: Trang "THÔNG TIN CHUNG"
        if (groupName === 'THÔNG TIN CHUNG') {
            console.log('Đang ở bước 4: Chọn >80% và Trên 90%');

            // Tìm và click vào các label chứa text tương ứng
            let labels = document.querySelectorAll('label.answertext');
            labels.forEach(label => {
                if (label.innerText.includes('>80%') || label.innerText.includes('Trên 90%')) {
                    let inputId = label.getAttribute('for');
                    let input = document.getElementById(inputId);
                    if (input && !input.checked) {
                        input.click(); // Click để kích hoạt sự kiện checkconditions của LimeSurvey
                    }
                }
            });

            // Chờ 0.5s rồi ấn Tiếp theo
            if (nextBtn) setTimeout(() => nextBtn.click(), 500);
        }

        // BƯỚC 5: Trang "ĐÁNH GIÁ VỀ HOẠT ĐỘNG GIẢNG DẠY"
      else if (groupName === 'ĐÁNH GIÁ VỀ HOẠT ĐỘNG GIẢNG DẠY') {
            console.log('Đang ở bước 5: Random giữa mức 3 và 4');

            // Lấy từng hàng câu hỏi
            let rows = document.querySelectorAll('tr.answers-list');
            rows.forEach(row => {
                // Lọc ra các lựa chọn có title là "3" hoặc "4" trong hàng đó
                // Nếu form có 5 mức, bạn đổi "3", "4" thành "4", "5" ở dòng dưới
                let options = row.querySelectorAll('input[type="radio"][title="3"], input[type="radio"][title="4"]');

                if (options.length > 0) {
                    // Random 1 số nguyên từ 0 đến (số lượng option - 1)
                    let randomIndex = Math.floor(Math.random() * options.length);
                    let selectedOption = options[randomIndex];

                    if (!selectedOption.checked) {
                        selectedOption.click();
                    }
                }
            });

            if (nextBtn) setTimeout(() => nextBtn.click(), 500);
        }
        // BƯỚC 6: Trang "Ý KIẾN KHÁC"
        else if (groupName === 'Ý KIẾN KHÁC') {
            console.log('Đang ở bước 6: Tự động ấn Gửi');

            // Nếu có nút Gửi, tiến hành submit
            if (submitBtn) {
                setTimeout(() => submitBtn.click(), 500);
            }
        }

    }, 1000);
})();