<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Quizizz Answer</title>
    <link rel="icon" href="https://cdn.discordapp.com/attachments/1274715030390308876/1330038565211476060/QUIZIZZ.png?ex=67946f70&is=67931df0&hm=ba4da7ce1d517474728176752eb260fad5d65660c32912cf03d6fde8f1803586&" type="image/png">

    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-image: url('https://cdn.discordapp.com/attachments/1274715030390308876/1332319889112698941/gif.gif?ex=6794d316&is=67938196&hm=4914a6be073489570bd18b10fc66396d75b79f7aa293502985d3381799315e1e&');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            background-attachment: fixed;
            height: 100%;
            min-height: 100vh;
            color: white;
        }
        html, body {
            height: 100%; /* ทำให้พื้นหลังครอบคลุมทั้งหน้า */
        }
        h1 {
            text-align: center;
            color: #fff;
            margin-bottom: 20px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.7);
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            background-color: rgba(255, 255, 255, 0.8); /* ความโปร่งใส 80% */
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
            color: #333;
        }
        label {
            font-size: 16px;
            margin-bottom: 10px;
            display: block;
        }
        input[type="text"] {
            width: 100%;
            padding: 12px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
            margin-bottom: 20px;
        }
        button {
            background-color: #4CAF50;
            color: white;
            font-size: 16px;
            padding: 12px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            width: 100%;
            margin-bottom: 20px; /* เพิ่มเว้นระยะด้านล่าง */
        }
        button:hover {
            background-color: #45a049;
        }
        .question {
            margin-bottom: 20px;
            padding: 15px;
            background-color: #f9f9f9;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .question h3 {
            margin: 0;
            color: #333;
        }
        .answers {
            margin-top: 10px;
            color: #333;
        }
        .answers p {
            font-size: 16px;
            margin: 0;
        }
        .error {
            color: red;
            font-weight: bold;
            text-align: center;
        }

        /* Message Notification Style */
        .notification {
            position: fixed;
            top: 20px;
            right: 20px;
            background-color: #ff0000;
            color: white;
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            display: none;
            align-items: center;
            font-size: 16px;
            z-index: 999;
            min-width: 200px;
        }
        .notification .spinner {
            border: 4px solid #f3f3f3;
            border-top: 4px solid #fff;
            border-radius: 50%;
            width: 20px;
            height: 20px;
            margin-right: 10px;
            animation: spin 2s linear infinite;
        }

        .notification .check {
            font-size: 18px;
            margin-right: 10px;
            color: #fff;
        }
        footer {
            position: fixed; /* ทำให้ footer อยู่ติดขอบล่าง */
            bottom: 0; /* ตำแหน่งล่างสุด */
            left: 0; /* เริ่มจากขอบซ้าย */
            width: 100%; /* กว้างเต็มหน้าจอ */
            color: #fff;
            text-align: center;
            padding: 10px 0;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>

    <h1>Cheats Test School Quizizz Answer</h1>
    <div class="container">
        <img src="https://media.discordapp.net/attachments/1274715030390308876/1332358380173394022/image.png?ex=6794f6ef&is=6793a56f&hm=476bc02b3e5d030db713eadcf697e98a3e3a9bb226207c1d020fe6a688838291&=&format=webp&quality=lossless&width=1121&height=57" style="width: 100%; max-width: 900px; display: block; margin: 0 auto; margin-bottom: 10px; border-radius: 12px;">
        <label for="quizLink">ใส่ลิ้งค์ห้อง Quizizz</label>
        <input type="text" id="quizLink" placeholder="https://quizizz.com/join/game/U2FsdGVkX1%252FtCczVPbJ%252FpR%252ByutDpX6sbbUMWScqLR6XkmafOsxHrYrwbjuBOvNzM%252Bq%252Bm02YFaFJm9sr4GHaGcQ%253D%253D">
        <button onclick="fetchQuizData()">Show Answers</button>

        <div id="output"></div>
    </div>

    <footer>
        <p>Cheats Test School © 2025 สงวนสิทธิ์</p>
    </footer>

    <!-- Notification -->
    <div id="notification" class="notification">
        <div class="error spinner"></div>
        <span id="notification-message">ลิ้งไม่ถูกต้อง</span>
    </div>

    <script>
        document.addEventListener('keydown', function(e) {
            if (e.ctrlKey && e.key === 's') {
                e.preventDefault();
                alert("มันเปิดไม่ได้หรอก");
            }
            if (e.key === 'F12') {
                e.preventDefault();
                alert("มันเปิดไม่ได้หรอก");
            }
            if (e.altKey && e.shiftKey && e.key === 'I') {
                e.preventDefault();
                alert("มันเปิดไม่ได้หรอก");
            }
        });
    </script>

    <script>
        async function fetchQuizData() {
            const quizLink = document.getElementById("quizLink").value;
            const notification = document.getElementById("notification");
            const notificationMessage = document.getElementById("notification-message");
            const notificationIcon = notification.querySelector('.spinner');

            if (!quizLink) {
                notificationMessage.textContent = "คุณยังไม่ได้ใส่ลิ้ง";
                notification.style.display = 'flex';

                setTimeout(() => {
                    notification.style.display = 'none';
                }, 3000);
                return;
            }

            try {
                const response = await fetch('https://v3.schoolcheats.net/quizizz/answers', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({ input: quizLink })
                });

                if (!response.ok) {
                    throw new Error(`Error: ${response.status} - ${response.statusText}`);
                }

                const data = await response.json();
                const questions = data.questions;

                if (!questions || questions.length === 0) {
                    document.getElementById("output").innerHTML = "<p class='error'>No Room found.</p>";
                    return;
                }

                let output = '';
                questions.forEach((question, idx) => {
                    const queryText = cleanText(question.structure.query.text);
                    const options = question.structure.options.map(opt => cleanText(opt.text));
                    const correctIndices = question.structure.answer;
                
                    let correctAnswers = [];
                    if (Array.isArray(correctIndices)) {
                        correctAnswers = correctIndices.map(index => options[index]).filter(answer => answer);
                    } else if (typeof correctIndices === 'number' && correctIndices < options.length) {
                        correctAnswers.push(options[correctIndices]);
                    }
                
                    const formattedAnswers = correctAnswers.length > 0 ? correctAnswers.join(', ') : "No correct answer";
                
                    output += `
                        <div class="question">
                            <h3>${idx + 1}: ${queryText}</h3>
                            <div class="answers">
                                <p><strong>คำตอบ :</strong> ${formattedAnswers}</p>
                            </div>
                        </div>
                    `;
                });

                document.getElementById("output").innerHTML = output;

            } catch (error) {
                document.getElementById("output").innerHTML = `<p class='error'>Error: ${error.message}</p>`;
            } finally {
                setTimeout(() => {
                    notification.style.display = 'none';
                }, 2000);
            }
        }

        function cleanText(text) {
            const div = document.createElement("div");
            div.innerHTML = text;
            text = div.textContent || div.innerText || '';
            text = text.replace(/<.*?>/g, ''); // remove HTML tags
            return text.trim();
        }
    </script>

</body>
</html>
