From 7ebbd9ec828cfe79497cc1107e580b1e07660132 Mon Sep 17 00:00:00 2001 From: casca <8927157+casca@users.noreply.github.com> Date: Tue, 16 Jun 2020 19:57:01 +0200 Subject: [PATCH] Zero-pad the number in lecture files and chapter folders --- assets/js/app.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/assets/js/app.js b/assets/js/app.js index efcfe4d0..bd70c3c8 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -627,7 +627,8 @@ function initDownload($course, coursedata, subtitle = false) { function downloadChapter(chapterindex, lectureindex) { var num_lectures = coursedata["chapters"][chapterindex]["lectures"].length; var chapter_name = sanitize( - chapterindex + 1 + ". " + coursedata["chapters"][chapterindex]["name"] + zeroPad(chapterindex + 1, coursedata["chapters"].length) + + ". " + coursedata["chapters"][chapterindex]["name"] ); mkdirp( download_directory + "/" + course_name + "/" + chapter_name, @@ -776,8 +777,8 @@ function initDownload($course, coursedata, subtitle = false) { chapter_name + "/" + sanitize( - lectureindex + - 1 + + zeroPad(lectureindex + 1, + coursedata["chapters"][chapterindex]["lectures"].length) + "." + (index + 1) + " " + @@ -807,8 +808,8 @@ function initDownload($course, coursedata, subtitle = false) { ); } else { var lecture_name = sanitize( - lectureindex + - 1 + + zeroPad(lectureindex + 1, + coursedata["chapters"][chapterindex]["lectures"].length) + "." + (index + 1) + " " + @@ -974,8 +975,8 @@ function initDownload($course, coursedata, subtitle = false) { .addClass(qualityColorMap["Subtitle"] || "grey"); $download_speed_value.html(0); var lecture_name = sanitize( - lectureindex + - 1 + + zeroPad(lectureindex + 1, + coursedata["chapters"][chapterindex]["lectures"].length) + ". " + coursedata["chapters"][chapterindex]["lectures"][lectureindex][ "name" @@ -1098,8 +1099,8 @@ function initDownload($course, coursedata, subtitle = false) { chapter_name + "/" + sanitize( - lectureindex + - 1 + + zeroPad(lectureindex + 1, + coursedata["chapters"][chapterindex]["lectures"].length) + ". " + coursedata["chapters"][chapterindex]["lectures"][lectureindex][ "name" @@ -1133,8 +1134,8 @@ function initDownload($course, coursedata, subtitle = false) { ); } else { var lecture_name = sanitize( - lectureindex + - 1 + + zeroPad(lectureindex + 1, + coursedata["chapters"][chapterindex]["lectures"].length) + ". " + coursedata["chapters"][chapterindex]["lectures"][lectureindex][ "name" @@ -1802,3 +1803,7 @@ function resetToLogin() { $(".ui.login.grid").slideDown("fast"); $(".ui.dashboard").fadeOut("fast"); } + +function zeroPad(num, max) { + return num.toString().padStart(Math.floor(Math.log10(max) + 1), '0'); +} \ No newline at end of file