Dò Đáp Án LMS 360 (UPDATE VER)

Dò đáp án đúng...

当前为 2024-10-20 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Dò Đáp Án LMS 360 (UPDATE VER)
// @namespace    http://tampermonkey.net/
// @version      4.3
// @description  Dò đáp án đúng...
// @author       V Quan Người đã test: H Nam, K Ngoc, ...
// @match        https://lms360.edu.vn/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let hasCopied = false; // Biến kiểm tra xem đã dò đáp án chưa
    let currentQuestion = ""; // Biến để lưu câu hỏi hiện tại
    let isPanelOpen = true; // Biến kiểm soát mở/đóng bảng
    let autoCheckEnabled = false; // Biến kiểm soát tự động dò đáp án

// Hàm để lấy tên người dùng
function getUserName() {
    const userNameElement = document.querySelector("#root > div > div.gradient-9.fixed.top-0.iw-full.z-full > div.hidden.lg\\:block.iw-full > div > div.grow.flex.justify-between.items-center.ipr-30.ipy-12 > div.flex.items-center.gap-2 > div.relative.nav-user > div.relative > div.flex.flex-column.items-start.justify-content-center.ih-45.ibg-0d6.itext-13.itext-light.ipy-9.ipx-30.rounded-tr-20.rounded-br-20 > span.text-light.font-bold");

    // Kiểm tra xem phần tử có chứa chữ không
    return userNameElement && userNameElement.innerText.trim() ? userNameElement.innerText.trim() : 'Người dùng';
}

// Tạo ô thông báo tên
const greetingBox = document.createElement('div');
greetingBox.style.position = 'fixed';
greetingBox.style.left = '50%'; // Đặt ở giữa ngang
greetingBox.style.bottom = '60px'; // Cách đáy 60px để có chỗ cho ô gradient
greetingBox.style.transform = 'translateX(-50%)'; // Giữa theo chiều ngang
greetingBox.style.padding = '10px 20px'; // Thêm padding cho ô
greetingBox.style.background = 'green'; // Nền màu xanh
greetingBox.style.borderRadius = '5px';
greetingBox.style.display = 'flex';
greetingBox.style.alignItems = 'center';
greetingBox.style.boxShadow = '0 2px 10px rgba(0,0,0,0.1)';
greetingBox.style.zIndex = '9999';
greetingBox.style.transition = 'bottom 0.5s ease, opacity 0.5s ease'; // Hiệu ứng cho bottom và opacity
greetingBox.style.opacity = '1';

// Thêm nội dung thông báo tên
const userName = getUserName();
const greetingText = document.createElement('span');
greetingText.innerHTML = `<strong>Xin chào bạn ${userName}!</strong>`; // Sử dụng thẻ strong để in đậm
greetingText.style.color = 'white'; // Màu chữ đen

// Thêm phần tử vào ô thông báo tên
greetingBox.appendChild(greetingText);

// Thêm ô thông báo vào body tên
document.body.appendChild(greetingBox);

// Hiệu ứng mở đầu: trượt ra
setTimeout(() => {
    greetingBox.style.bottom = '70px'; // Đưa ô vào vị trí hiển thị
}, 1000); // Thời gian chờ trước khi mở

// Tự động ẩn ô thông báo sau 3 giây
setTimeout(() => {
    greetingBox.style.opacity = '0'; // Giảm độ mờ
    greetingBox.style.bottom = '-100px'; // Trượt vào
    setTimeout(() => {
        document.body.removeChild(greetingBox);
    }, 500); // Thời gian để ẩn
}, 3000);


// Tạo ô thông báo thành công
const notificationBox = document.createElement('div');
notificationBox.style.position = 'fixed';
notificationBox.style.bottom = '10px';
notificationBox.style.left = '-300px'; // Bắt đầu ngoài màn hình bên trái
notificationBox.style.padding = '10px';
notificationBox.style.backgroundColor = 'white';
notificationBox.style.border = '1px solid #ccc';
notificationBox.style.borderRadius = '5px';
notificationBox.style.display = 'flex';
notificationBox.style.alignItems = 'center';
notificationBox.style.boxShadow = '0 2px 10px rgba(0,0,0,0.1)';
notificationBox.style.zIndex = '9999';
notificationBox.style.transition = 'left 0.5s ease, opacity 0.5s ease'; // Hiệu ứng cho left và opacity
notificationBox.style.opacity = '1';

// Thêm biểu tượng tick
const icon = document.createElement('img');
icon.src = 'https://img.icons8.com/ios-filled/50/28a745/checkmark.png';
icon.style.width = '20px';
icon.style.height = '20px';
icon.style.marginRight = '10px';

// Thêm nội dung thông báo
const notificationText = document.createElement('span');
notificationText.innerHTML = `<strong>Tải thành công!</strong>`;
notificationText.style.color = 'green';

// Thêm phần tử vào ô thông báo
notificationBox.appendChild(icon);
notificationBox.appendChild(notificationText);

// Thêm ô thông báo vào body
document.body.appendChild(notificationBox);

// Hiệu ứng mở đầu: trượt vào
setTimeout(() => {
    notificationBox.style.left = '10px'; // Đưa ô vào vị trí hiển thị
}, 100);

// Tự động ẩn ô thông báo sau 3 giây
setTimeout(() => {
    notificationBox.style.opacity = '0'; // Giảm độ mờ
    notificationBox.style.left = '-300px'; // Trượt ra
    setTimeout(() => {
        document.body.removeChild(notificationBox);
    }, 500);
}, 3000);


    // Hàm tạo tên ngẫu nhiên với tối đa 10 ký tự
    function generateRandomName() {
        const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
        let name = '';
        for (let i = 0; i < 10; i++) {
            name += chars.charAt(Math.floor(Math.random() * chars.length));
        }
        return name;
    }

    // Lấy tên ngẫu nhiên
    const nameText = generateRandomName();

// Tạo bảng thông báo
const infoBox = document.createElement('div');
infoBox.style.position = 'fixed';
infoBox.style.top = '50px';
infoBox.style.right = '10px';
infoBox.style.padding = '10px';
infoBox.style.backgroundColor = 'white';
infoBox.style.border = '2px solid #003366'; // Viền màu xanh dương đậm
infoBox.style.borderRadius = '10px'; // Bo tròn góc
infoBox.style.zIndex = '9999';
infoBox.style.cursor = 'move'; // Để có thể di chuyển bảng
infoBox.style.width = '250px'; // Đặt kích thước cố định cho bảng
infoBox.style.transition = 'max-height 0.5s ease-in-out, opacity 0.5s ease-in-out'; // Hiệu ứng đóng mở mượt mà cho cả chiều cao và độ mờ
infoBox.style.maxHeight = '500px'; // Mở rộng khi hiển thị
infoBox.style.overflow = 'hidden'; // Ẩn nội dung khi đóng
infoBox.style.opacity = '1'; // Đảm bảo bảng được hiển thị ban đầu

    // Tạo tiêu đề cho bảng với tên người dùng
    const titleBar = document.createElement('div');
    titleBar.style.fontWeight = 'bold';
    titleBar.style.marginBottom = '10px';
    titleBar.innerHTML = `Dò Đáp Án (<span style="color: black; font-weight: bold;">${nameText}</span>)`; // Chèn tên ngẫu nhiên màu đen vào

    // Tạo nút Dò và hiển thị đáp án cạnh nhau
    const checkButtonContainer = document.createElement('div');
    checkButtonContainer.style.display = 'flex'; // Bố trí theo hàng ngang
// Nút dò
const checkButton = document.createElement('button');
checkButton.innerText = 'Dò';
checkButton.style.marginTop = '10px';
checkButton.style.padding = '5px 10px';
checkButton.style.cursor = 'pointer';
checkButton.style.border = '2px solid #003366'; // Viền màu xanh dương đậm
checkButton.style.borderRadius = '5px'; // Bo tròn góc
checkButton.style.backgroundColor = 'white'; // Nền trắng
checkButton.style.transition = 'border-color 0.3s, background-color 0.3s'; // Hiệu ứng chuyển màu viền và nền

// Hàm để đổi màu viền RGB
let hue = 0;
function changeBorderColor() {
    hue = (hue + 1) % 360; // Giới hạn giá trị hue từ 0 đến 360
    checkButton.style.borderColor = `hsl(${hue}, 100%, 50%)`; // Thiết lập màu viền
}

// Bắt đầu đổi màu viền liên tục
setInterval(changeBorderColor, 100); // Đổi màu viền mỗi 100ms

// Thêm hiệu ứng hover cho nút
checkButton.onmouseover = () => {
    checkButton.style.backgroundColor = '#f0f0f0'; // Màu nền khi hover
};

checkButton.onmouseout = () => {
    checkButton.style.backgroundColor = 'white'; // Màu nền lại khi không hover
};

// Thêm nút vào document
infoBox.appendChild(checkButton); // Giả sử bạn đã tạo infoBox trước đó


    const answerDisplay = document.createElement('div');
    answerDisplay.style.marginLeft = '10px'; // Khoảng cách giữa nút Dò và đáp án
    answerDisplay.style.fontWeight = 'bold';
    answerDisplay.style.color = 'green';

    checkButtonContainer.appendChild(checkButton);
    checkButtonContainer.appendChild(answerDisplay);

// Tạo nút mở/đóng nằm bên ngoài bảng
const externalToggleButton = document.createElement('button');
externalToggleButton.innerText = 'Mở/Đóng Dò Đáp Án';
externalToggleButton.style.position = 'fixed';
externalToggleButton.style.top = '10px';
externalToggleButton.style.right = '10px';
externalToggleButton.style.padding = '5px 10px';
externalToggleButton.style.cursor = 'pointer';
externalToggleButton.style.zIndex = '10000';
externalToggleButton.style.border = '2px solid #003366'; // Viền màu xanh dương đậm
externalToggleButton.style.borderRadius = '5px'; // Bo tròn góc cho nút
externalToggleButton.style.backgroundColor = 'white'; // Nền trắng cho nút
externalToggleButton.style.transition = 'background-color 0.3s'; // Hiệu ứng chuyển màu nền khi hover
    // Thêm hiệu ứng hover cho nút
externalToggleButton.onmouseover = () => {
    externalToggleButton.style.backgroundColor = '#f0f0f0'; // Màu nền khi hover
};
externalToggleButton.onmouseout = () => {
    externalToggleButton.style.backgroundColor = 'white'; // Màu nền lại khi không hover
};

    // Tạo checkbox tùy chọn tự động dò đáp án
    const autoCheckLabel = document.createElement('label');
    autoCheckLabel.style.display = 'block';
    autoCheckLabel.style.marginTop = '10px';
    autoCheckLabel.innerHTML = 'Tự động dò đáp án + AUTO'; // Thêm " + AUTO"

    const autoCheckBox = document.createElement('input');
    autoCheckBox.type = 'checkbox';
    autoCheckBox.style.marginLeft = '5px';

    autoCheckLabel.appendChild(autoCheckBox);

    // Hàm kiểm tra câu hỏi hiện tại để reset khi thay đổi
    function checkCurrentQuestion(iframeDoc) {
        const questionElement = iframeDoc.querySelector(".h5p-question-content");
        if (questionElement) {
            const newQuestion = questionElement.innerText || ""; // Lấy nội dung câu hỏi hiện tại
            if (newQuestion !== currentQuestion) {
                currentQuestion = newQuestion;
                hasCopied = false; // Reset biến khi câu hỏi thay đổi
                answerDisplay.innerHTML = ""; // Xóa nội dung hiển thị đáp án
            }
        }
    }

function findCorrectAnswer() {
    const iframe = document.querySelector('iframe'); // Select the first iframe on the page
    if (!iframe) {
        answerDisplay.innerHTML = 'Không tìm thấy iframe.'; // If iframe not found, show an error
        return;
    }

    const iframeDoc = iframe.contentDocument || iframe.contentWindow.document; // Access the iframe's content

    checkCurrentQuestion(iframeDoc); // Check if the question has changed

    if (hasCopied) return; // Prevent rechecking if the answer has already been found

    // Function to periodically check for the correct answer
    function periodicCheck() {
        let correctAnswer = iframeDoc.querySelector(
            "body > div > div > div > div.h5p-column-content.h5p-question.h5p-single-choice-set > div.h5p-question-content > div > div.h5p-sc-set.h5p-sc-animate > div.h5p-sc-slide.h5p-sc.h5p-sc-current-slide > ul > li.h5p-sc-alternative.h5p-sc-is-correct"
        );

        if (!correctAnswer) {
            // If the correct answer is not found, keep checking with other known paths
            correctAnswer = iframeDoc.querySelector(
                "body > div > div > div.h5p-question-content > div > div.h5p-sc-set.h5p-sc-animate > div.h5p-sc-slide.h5p-sc.h5p-sc-current-slide > ul > li.h5p-sc-alternative.h5p-sc-is-correct"
            );
        }

        if (!correctAnswer) {
            correctAnswer = iframeDoc.querySelector(
                "body > div > div > div.h5p-video-wrapper.h5p-video.hardware-accelerated > div > div > div > div > div.h5p-question-content > div > div.h5p-sc-set.h5p-sc-animate > div.h5p-sc-slide.h5p-sc.h5p-sc-current-slide > ul > li.h5p-sc-alternative.h5p-sc-is-correct"
            );
        }

        if (!correctAnswer) {
            correctAnswer = iframeDoc.querySelector(
                "body > div > div > div > div.h5p-column-content.h5p-question.h5p-single-choice-set > div.h5p-question-content > div > div.h5p-sc-set.h5p-sc-animate > div.h5p-sc-slide.h5p-sc.h5p-sc-current-slide > ul > li.h5p-sc-alternative.h5p-sc-is-correct"
            );
        }

        if (correctAnswer) {
            const answerText = correctAnswer.querySelector('.h5p-sc-label p').innerText; // Get the correct answer text

            if (autoCheckEnabled) {
                correctAnswer.click(); // Auto-select the correct answer if the auto-check is enabled
            }

            // Check if there's an image associated with the answer
            const imgElement = correctAnswer.querySelector('img');
            if (imgElement) {
                const imgSrc = imgElement.src;

                if (imgSrc.startsWith('data:image/svg+xml')) {
                    const svgImage = document.createElement('img');
                    svgImage.src = imgSrc;
                    svgImage.style.maxWidth = '50px'; // Adjust the max width of the image
                    svgImage.style.marginLeft = '10px'; // Add some margin between the text and image

                    const textNode = document.createTextNode(`Đáp án: ${answerText} - Hình ảnh: `);
                    answerDisplay.appendChild(textNode);
                    answerDisplay.appendChild(svgImage);
                } else {
                    answerDisplay.innerHTML = `Đáp án: ${answerText} - Ảnh không phải SVG.`;
                }
            } else {
                answerDisplay.innerHTML = `Đáp án: ${answerText}`; // Display the correct answer
            }

            hasCopied = true; // Mark as answer found
        } else {
            answerDisplay.innerHTML = 'Không tìm thấy đáp án. Tiếp tục dò...'; // Display that it's still searching
            setTimeout(periodicCheck, 1000); // Retry after 1 second if the answer isn't found
        }
    }

    // Start checking for the correct answer periodically
    periodicCheck();
}



    // Khi nhấn nút Dò, thực hiện tìm kiếm đáp án
    checkButton.onclick = findCorrectAnswer;

    // Khi nhấn nút mở/đóng bảng
    externalToggleButton.onclick = function() {
        isPanelOpen = !isPanelOpen;
        if (isPanelOpen) {
            infoBox.style.maxHeight = '500px'; // Mở bảng
            infoBox.style.opacity = '1';
        } else {
            infoBox.style.maxHeight = '0'; // Đóng bảng
            infoBox.style.opacity = '0';
        }
    };

// Khi nhấn checkbox tự động dò đáp án
autoCheckBox.onchange = function() {
    autoCheckEnabled = autoCheckBox.checked; // Cập nhật trạng thái tự động dò
    if (autoCheckEnabled) {
        // Tự động dò nếu tùy chọn được bật
        const autoCheckInterval = setInterval(findCorrectAnswer, 1000); // Dò lại sau mỗi giây

        // Dừng tự động dò khi tắt checkbox
        autoCheckBox.onchange = function() {
            autoCheckEnabled = autoCheckBox.checked; // Cập nhật trạng thái tự động dò
            if (!autoCheckEnabled) {
                clearInterval(autoCheckInterval); // Dừng việc dò
            }
        };
    }
};

    // Cho phép di chuyển bảng bằng chuột
    let offsetX = 0, offsetY = 0, isDragging = false;

    titleBar.onmousedown = function(e) {
        isDragging = true;
        offsetX = e.clientX - infoBox.getBoundingClientRect().left;
        offsetY = e.clientY - infoBox.getBoundingClientRect().top;
    };

    document.onmousemove = function(e) {
        if (isDragging) {
            infoBox.style.left = `${e.clientX - offsetX}px`;
            infoBox.style.top = `${e.clientY - offsetY}px`;
        }
    };

    document.onmouseup = function() {
        isDragging = false;
    };

    // Thêm các phần tử vào trang
    infoBox.appendChild(titleBar);
    infoBox.appendChild(checkButtonContainer);
    infoBox.appendChild(autoCheckLabel);
    document.body.appendChild(infoBox);
    document.body.appendChild(externalToggleButton);
})();