function loadSubject(id) {
fetch("/lessons/index.json")
.then((response) => response.json())
.then((data) => {
var title = document.getElementById("title-banner");
var subtitle = document.getElementById("subtitle");
var container = document.getElementById("container")
console.log(data.subjects[id]);
title.innerHTML = data.subjects[id].titleEn;
subtitle.innerHTML = data.subjects[id].splash;
container.innerHTML = "";
var chapterLength = data.subjects[id].chapters.length;
for (var i = 0; i < chapterLength; i++) {
var chapterContainer = `
Chapter ${i + 1}: ${data.subjects[id].chapters[i].titleEn}
`
container.innerHTML += chapterContainer;
}
// return data.subjects[id];
}
);
}
// DEPENDENCIES:
// * /scripts/toc.js
// * markdown-it
function loadLesson(subject, chapter, lesson) {
fetch("/lessons/index.json")
.then((response) => response.json())
.then((data) => {
var title = document.getElementById("title-banner");
var subtitle = document.getElementById("subtitle");
var container = document.getElementById("container")
var chipStatus = document.getElementById("chip-status");
var chipAuthor = document.getElementById("chip-author");
var chipGrade = document.getElementById("chip-grade");
var lessonData = data.subjects[subject].chapters[chapter].lessons[lesson];
console.log(lessonData);
title.innerHTML = lessonData.titleEn;
subtitle.innerHTML = `Chapter ${parseInt(chapter) + 1}`;
container.innerHTML = "";
chipGrade.innerHTML = "Grade " + lessonData.grade;
if (lessonData.authors.length == 1) {
chipAuthor.innerHTML = "Written by " + lessonData.authors[0];
} else {
chipAuthor.innerHTML = "Written by ";
for (var i = 0; i < lessonData.authors.length - 1; i++) {
chipAuthor.innerHTML += lessonData.authors[i] + ", ";
}
chipAuthor.innerHTML += "and " + lessonData.authors[lessonData.authors.length - 1];
}
// why the heck switch case not working
// guess i'm too stupid for a switch case.
// no i'm not yandev
if (lessonData.status == 0) {
chipStatus.innerHTML = "❓ Not Verified";
} else if (lessonData.status == 1) {
chipStatus.innerHTML = "✅ Verified";
} else if (lessonData.status == 2) {
chipStatus.innerHTML = "⚠️ Contains Wrong Information";
}
fetch(lessonData.pathEn)
.then((response) => response.text())
.then((data) => {
const md = markdownit();
container.innerHTML = md.render(data);
}).then(() => {
MathJax.typeset();
});
}
).then(() => {
toc();
});
console.log(subject);
console.log(chapter);
console.log(lesson);
}
function loadQuiz(subject, chapter, lesson) {
}
function listSubjects() {
fetch("/lessons/index.json")
.then((response) => response.json())
.then((data) => {
var container = document.getElementById("subject-container");
for (var i = 0; i < data.subjects.length; i++) {
var card = `
`;
container.innerHTML += card;
}
}
);
}