diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..1a32399 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +indent_style = space +indent_size = 4 +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true +end_of_line = lf +max_line_length = off diff --git a/main.js b/extension/main.js similarity index 67% rename from main.js rename to extension/main.js index bc31163..c067427 100644 --- a/main.js +++ b/extension/main.js @@ -1,5 +1,3 @@ - - // Returns the ISO week of the date. Date.prototype.getWeek = function () { var date = new Date(this.getTime()); @@ -13,25 +11,11 @@ Date.prototype.getWeek = function () { - 3 + (week1.getDay() + 6) % 7) / 7); } -const getCoursePage = (course) => { - return fetch(`https://www.fit.vut.cz/study/course/${course}/.cs`) - .then(response => response.text()) - .then(html => { - const parser = new DOMParser(); - const doc = parser.parseFromString(html, 'text/html'); - return doc; - }) -} - const getLectureTitles = (course) => { - return getCoursePage(course) - .then(page => { - const planList = page.querySelectorAll('.b-detail__content ol li') - let lectureTitles = [] - planList.forEach(planElement => { - lectureTitles.push(planElement.innerText); - }) - return lectureTitles; + return fetch(`https://fitscrap.herokuapp.com/lecture-titles/${course}`) + .then(response => response.json()) + .catch(e => { + console.error(e); }) } @@ -56,10 +40,10 @@ const getDateFromLectureString = (str) => { } const insertLectureNumbering = async (course) => { + const lectureTitles = await getLectureTitles(course) || []; - const lectureTitles = await getLectureTitles(course); - - const lectureList = document.querySelector("ul"); + // get the last