File size: 7,376 Bytes
79b3d18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
755e60a
79b3d18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d0d98c
79b3d18
 
 
 
 
 
 
 
 
755e60a
 
 
 
 
 
 
 
 
 
 
 
79b3d18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Exam Chapter Viewer</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
            background-color: #f0f2f5;
            color: #333;
            display: flex;
            justify-content: center;
            align-items: flex-start;
            min-height: 100vh;
            margin: 0;
            padding: 40px;
        }
        .container {
            width: 90%;
            max-width: 600px;
            background-color: #ffffff;
            padding: 30px;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        h1 {
            text-align: center;
            color: #1c1e21;
            margin-bottom: 30px;
        }
        .controls {
            display: flex;
            gap: 20px;
            margin-bottom: 30px;
        }
        select {
            width: 100%;
            padding: 12px;
            font-size: 16px;
            border: 1px solid #dddfe2;
            border-radius: 6px;
            cursor: pointer;
        }
        select:disabled {
            background-color: #e4e6eb;
            cursor: not-allowed;
        }
        #chapter-links a {
            display: block;
            padding: 12px;
            margin-bottom: 8px;
            background-color: #e7f3ff;
            color: #1877f2;
            text-decoration: none;
            border-radius: 6px;
            transition: background-color 0.2s, transform 0.2s;
        }
        #chapter-links a:hover {
            background-color: #d0e7ff;
            transform: translateY(-2px);
        }
    </style>
</head>
<body>

    <div class="container">
        <h1>📚 Lakshita's Learning App - Class 8</h1>
        <div class="controls">
            <select id="exam-select">
                <option value="">-- Select Exam --</option>
            </select>
            <select id="subject-select" disabled>
                <option value="">-- Select Subject --</option>
            </select>
        </div>
        <div id="chapter-links"></div>

        <div style="margin-top: 40px; padding: 20px; border-top: 2px solid #eee; text-align: center;">
            <h2>✨ How to Use This Magic Study Machine! ✨</h2>
            <p>Tired of searching for notes? Just follow this super-easy recipe for success!</p>
            <ol style="list-style: none; padding: 0;">
                <li style="font-size: 18px; margin-bottom: 10px;"><b>Step 1️⃣:</b> Pick your exam (like FA2 or SA1) from the first box.</li>
                <li style="font-size: 18px; margin-bottom: 10px;"><b>Step 2️⃣:</b> Choose your subject... are you a Biology brainiac 🧠 or a Physics pro ⚛️?</li>
                <li style="font-size: 18px;"><b>Step 3️⃣:</b> BAM! 🚀 All the chapters will appear below. Just click to open!</li>
            </ol>
            <p style="font-weight: bold; margin-top: 20px;">Happy studying! You've got this! 😎</p>
        </div>

    </div>

    <script>
        document.addEventListener('DOMContentLoaded', () => {
            const examSelect = document.getElementById('exam-select');
            const subjectSelect = document.getElementById('subject-select');
            const chapterLinksDiv = document.getElementById('chapter-links');

            let fileData = {}; // To store parsed data like { "FA2": { "BIO": [...] } }

            // 1. Fetch the list of files
            fetch('filelist.json')
                .then(response => {
                    if (!response.ok) {
                        throw new Error("Could not find filelist.json. Please run the python script first.");
                    }
                    return response.json();
                })
                .then(filenames => {
                    // 2. Parse filenames and structure the data
                    filenames.forEach(name => {
                        const parts = name.replace('.html', '').split('_');
                        if (parts.length < 3) return;

                        const exam = parts[0];
                        const subject = parts[1];

                        if (!fileData[exam]) {
                            fileData[exam] = {};
                        }
                        if (!fileData[exam][subject]) {
                            fileData[exam][subject] = [];
                        }
                        fileData[exam][subject].push(name);
                    });

                    // 3. Populate the first dropdown (Exams)
                    const exams = Object.keys(fileData).sort();
                    exams.forEach(exam => {
                        const option = document.createElement('option');
                        option.value = exam;
                        option.textContent = exam;
                        examSelect.appendChild(option);
                    });
                })
                .catch(error => {
                    chapterLinksDiv.innerHTML = `<p style="color:red;"><b>Error:</b> ${error.message}</p>`;
                    console.error(error);
                });

            // 4. Handle Exam selection change
            examSelect.addEventListener('change', () => {
                const selectedExam = examSelect.value;
                
                // Reset subject dropdown and links
                subjectSelect.innerHTML = '<option value="">-- Select Subject --</option>';
                subjectSelect.disabled = true;
                chapterLinksDiv.innerHTML = '';

                if (selectedExam && fileData[selectedExam]) {
                    const subjects = Object.keys(fileData[selectedExam]).sort();
                    subjects.forEach(subject => {
                        const option = document.createElement('option');
                        option.value = subject;
                        option.textContent = subject;
                        subjectSelect.appendChild(option);
                    });
                    subjectSelect.disabled = false;
                }
            });

            // 5. Handle Subject selection change
            subjectSelect.addEventListener('change', () => {
                const selectedExam = examSelect.value;
                const selectedSubject = subjectSelect.value;

                chapterLinksDiv.innerHTML = ''; // Clear previous links

                if (selectedExam && selectedSubject && fileData[selectedExam][selectedSubject]) {
                    const files = fileData[selectedExam][selectedSubject].sort();
                    files.forEach(filename => {
                        const chapterPart = filename.replace('.html', '').split('_').slice(2).join(' ');
                        const displayName = chapterPart.replace("CH", "Chapter").trim();

                        const link = document.createElement('a');
                        link.href = `data/${filename}`;
                        link.textContent = displayName;
                        link.target = '_blank'; // Open link in a new tab
                        chapterLinksDiv.appendChild(link);
                    });
                }
            });
        });
    </script>
</body>
</html>