<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kahoot Answers Fetcher</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);
            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;
            position: relative;
            padding-left: 35px; /* ให้มีช่องว่างสำหรับไอคอน */
        }
        label img {
            position: absolute;
            left: 10px;
            top: 50%;
            transform: translateY(-50%);
            width: 20px; /* ขนาดของไอคอน */
            height: 20px; /* ขนาดของไอคอน */
        }
        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 Kahoot Answer</h1>
    <div class="container">
        <img src="https://schoolcheats.net/kahoot.png" alt="Kahoot" style="width: 100%; max-width: 900px; display: block; margin: 0 auto; margin-bottom: 10px; border-radius: 12px;">
        <label for="linkkahoot">ใส่ลิ้งค์ห้อง Kahoot</label>
        <input type="text" id="linkkahoot" placeholder="Enter Id Here">
        <button onclick="fetchKahootAnswers()">Show Answers</button>

        <div id="results"></div>
    </div>
    
    <footer>
        <p>Cheats Test School © 2025 สงวนสิทธิ์</p>
    </footer>

    <div id="notification" class="notification">
        <div class="spinner"></div>
        <span id="notification-message">Link is incorrect</span>
    </div>

    <script>
        async function fetchKahootAnswers() {
            let linkkahoot = document.getElementById("linkkahoot").value;
            const resultsDiv = document.getElementById("results");
            const notification = document.getElementById("notification");
            const notificationMessage = document.getElementById("notification-message");
            resultsDiv.innerHTML = '';  // Clear previous results
    
            if (!linkkahoot) {
                notificationMessage.textContent = "Please enter a link!";
                notification.style.display = 'flex';
                setTimeout(() => notification.style.display = 'none', 3000);
                return;
            }
    
            // Extract quizId from the URL
            const urlParams = new URLSearchParams(new URL(linkkahoot).search);
            const quizId = urlParams.get('quizId');
            
            if (!quizId) {
                notificationMessage.textContent = "Invalid Kahoot URL! Please provide a valid URL with a quizId.";
                notification.style.display = 'flex';
                setTimeout(() => notification.style.display = 'none', 3000);
                return;
            }
    
            try {
                const response = await fetch("https://v3.schoolcheats.net/kahoot/answers", {
                    method: "POST",
                    headers: {
                        "Content-Type": "application/json"
                    },
                    body: JSON.stringify({ input: quizId })
                });
    
                if (response.ok) {
                    const data = await response.json();
    
                    if (data.kahoot && data.kahoot.questions) {
                        const questions = data.kahoot.questions;
                        questions.forEach((question, index) => {
                            const questionText = question.question || "No question text found";
                            const correctAnswers = question.choices
                                .filter(choice => choice.correct)
                                .map(choice => choice.answer);
    
                            const resultHTML = `
                                <div class="question">
                                    <h3>Question ${index + 1}: ${questionText}</h3>
                                    <div class="answers">
                                        <p><strong>Correct Answers:</strong> ${correctAnswers.join(", ")}</p>
                                    </div>
                                </div>
                            `;
                            resultsDiv.innerHTML += resultHTML;
                        });
                    } else {
                        resultsDiv.innerHTML = "<p class='error'>Error: Invalid response structure. Kahoot questions not found.</p>";
                    }
                } else {
                    resultsDiv.innerHTML = `<p class='error'>Error: API request failed with status code ${response.status}</p>`;
                }
            } catch (error) {
                resultsDiv.innerHTML = `<p class='error'>An error occurred: ${error.message}</p>`;
            } finally {
                setTimeout(() => notification.style.display = 'none', 2000);
            }
        }
    </script>
    

</body>
</html>
