From 3d0ccfba34d6371b41e877189b78599ae7b2f98a Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Sat, 16 Mar 2024 17:48:01 +0700 Subject: new branch! decided to revive this old project. lessons now support markdown, rebrand? --- scripts/lesson.js | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 scripts/lesson.js (limited to 'scripts/lesson.js') diff --git a/scripts/lesson.js b/scripts/lesson.js new file mode 100644 index 0000000..0036fde --- /dev/null +++ b/scripts/lesson.js @@ -0,0 +1,145 @@ +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}

+
+ ` + + var lessonLength = data.subjects[id].chapters[i].lessons.length; + + if (lessonLength > 1) { + chapterContainer += ` + + ${(data.subjects[id].chapters[i].lessons[0].type == "lesson") ? '📚' :'✏️' } + ${data.subjects[id].chapters[i].lessons[0].titleEn} + + ` + for (var j = 1; j < lessonLength - 1; j++) { + chapterContainer += ` + + ${(data.subjects[id].chapters[i].lessons[j].type == "lesson") ? '📚' :'✏️' } + ${data.subjects[id].chapters[i].lessons[j].titleEn} + + ` + } + chapterContainer += ` + + ${(data.subjects[id].chapters[i].lessons[lessonLength - 1].type == "lesson") ? '📚' :'✏️' } + ${data.subjects[id].chapters[i].lessons[lessonLength - 1].titleEn} + + ` + } else { + + } + + chapterContainer += `\n
` + + 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 = ` +
+ + + +

${data.subjects[i].titleEn}

+
+
+ `; + + container.innerHTML += card; + } + } + ); +} -- cgit v1.2.3