From 2f7558510b670282c7c68be72393d78249c4c8e8 Mon Sep 17 00:00:00 2001 From: Masaki Kobayashi Date: Thu, 1 Dec 2022 19:10:58 +0900 Subject: [PATCH 1/2] Revert "refactor: duplication" This reverts commit 914b2333a9f5e51d2391a3771bcbd885c7017620. --- src/methods/filterCourses.ts | 83 +++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 35 deletions(-) diff --git a/src/methods/filterCourses.ts b/src/methods/filterCourses.ts index d1de3fedd..2ce1e5b49 100644 --- a/src/methods/filterCourses.ts +++ b/src/methods/filterCourses.ts @@ -7,19 +7,6 @@ import { checkLang } from "./checkLang" let lang: checkLang.langCode -const translations = { - ja: { - spring: "春", - autumn: "秋", - allModules: "すべてのモジュール", - }, - en: { - spring: "Spring", - autumn: "Autumn", - allModules: "All modules", - }, -} - export const filterCourses = (): void => { lang = checkLang() @@ -69,8 +56,28 @@ const parseModuleCode = ( * @param {string} seasonCode "spring" or "autumn" * @return {string} "春", "Spring", etc... */ -const seasonCodeToText = (lang: checkLang.langCode, seasonCode: SeasonCode) => - translations[lang][seasonCode] +const seasonCodeToText = (seasonCode: SeasonCode) => { + switch (seasonCode) { + case "spring": { + if (lang === "ja") { + return "春" + } else if (lang === "en") { + return "Spring" + } else { + return "" + } + } + case "autumn": { + if (lang === "ja") { + return "秋" + } else if (lang === "en") { + return "Autumn" + } else { + return "" + } + } + } +} const createModuleSelector = () => { const selectorsContainer = document.querySelector( @@ -91,10 +98,17 @@ const createModuleSelector = () => { ] const moduleCodeToText = (moduleCode: ModuleCode) => { - if (moduleCode === "all") return translations[lang].allModules + if (moduleCode === "all") { + if (lang === "ja") { + return "すべてのモジュール" + } else if (lang === "en") { + return "All modules" + } + } const parsedModuleCode = parseModuleCode(moduleCode) - const season = seasonCodeToText(lang, parsedModuleCode.season) + + const season = seasonCodeToText(parsedModuleCode.season) return `${season}${parsedModuleCode.module.toUpperCase()}` } @@ -121,18 +135,27 @@ const createModuleSelector = () => { } const applyFilter = (moduleCode: ModuleCode): void => { - const coursesListContainer = - document.querySelector(".courselist tbody") - const coursesThumbnailContainer = document.querySelector( + let viewMode: "list" | "thumbnail" + let courses: HTMLElement[] + + const coursesListContainer = document.querySelector(".courselist tbody") + const coursesThumbnailContainer = document.querySelector( ".mycourses-body .section" ) - const coursesContainer = coursesListContainer ?? coursesThumbnailContainer - if (!coursesContainer || (coursesListContainer && coursesThumbnailContainer)) - return + if (coursesListContainer) { + viewMode = "list" + + courses = Array.from(coursesListContainer.children) as HTMLElement[] + courses.shift() + } else if (coursesThumbnailContainer) { + viewMode = "thumbnail" - const viewMode = coursesListContainer ? "list" : "thumbnail" - const courses = getCourses(coursesContainer, viewMode) + courses = Array.from(coursesThumbnailContainer.children) as HTMLElement[] + courses.pop() + } else { + throw "invalid viewMode" + } /** * Parse course info string on the UI @@ -259,13 +282,3 @@ const applyFilter = (moduleCode: ModuleCode): void => { }) } } - -const getCourses = (coursesContainer: HTMLElement, viewMode: string) => - (Array.from(coursesContainer.children) as HTMLElement[]).filter( - (_, i) => - i !== - rowIndexToBeExcluded(viewMode, coursesContainer.childElementCount - 1) - ) - -const rowIndexToBeExcluded = (viewMode: string, lastIndex: number) => - viewMode === "list" ? 0 : lastIndex From d1763fadd5b1d4934df5d988e4be44d98e553ca1 Mon Sep 17 00:00:00 2001 From: Masaki Kobayashi Date: Thu, 1 Dec 2022 19:24:48 +0900 Subject: [PATCH 2/2] v3.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0230b4cae..328ab12c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "manaba-enhanced-for-tsukuba", - "version": "3.3.0", + "version": "3.3.1", "description": "Make your manaba a little bit more comfortable", "private": true, "devDependencies": {