Просмотр исходного кода

fix(ZHKU): 优化校区选择逻辑,处理校区自动检测失败的情况;进一步清理教室信息中的无意义字样 (#204)

* fix(ZHKU): 优化校区选择逻辑,处理校区自动检测失败的情况;进一步清理教室信息中的无意义字样

* fix(ZHKU): 更新教室信息清洗逻辑,修改“实验室”字样匹配逻辑

* fix(ZHKU): 结合学校实验室名称列表优化教室信息清洗逻辑
LC 1 месяц назад
Родитель
Сommit
98c797adde
1 измененных файлов с 20 добавлено и 12 удалено
  1. 20 12
      resources/ZHKU/zhku_lc6464.js

+ 20 - 12
resources/ZHKU/zhku_lc6464.js

@@ -144,17 +144,16 @@ async function chooseCampus() {
 	}
 
 	const labels = CAMPUS_OPTIONS.map((item) => item.label);
-	const defaultIndex = 1; // 默认白云校区
 
-	const selectedIndex = await window.AndroidBridgePromise.showSingleSelection(
-		"请选择校区",
-		JSON.stringify(labels),
-		defaultIndex
-	);
+	let selectedIndex = null;
+	do {
+		selectedIndex = await window.AndroidBridgePromise.showSingleSelection(
+			"校区检测失败,请选择校区",
+			JSON.stringify(labels),
+			-1
+		);
+	} while (selectedIndex == null || selectedIndex < 0 || selectedIndex >= CAMPUS_OPTIONS.length);
 
-	if (selectedIndex == null || selectedIndex < 0 || selectedIndex >= CAMPUS_OPTIONS.length) {
-		return "baiyun";
-	}
 	return CAMPUS_OPTIONS[selectedIndex].id;
 }
 
@@ -332,9 +331,6 @@ function parseCoursesFromIframeDocument(iframeDoc) {
 			const teacher = cleanText(teacherFont?.textContent ?? "");
 			let position = cleanText(locationFont?.textContent ?? "");
 
-			// 移除教室中的“(白)”“(白云)”“(白)实”等字样,该信息对于学生而言无意义
-			position = position.replace(/[((]白云?[))]实?/g, "");
-
 			// 过滤空课程名、网络课和不存在的虚拟位置
 			if (courseName === ""
 				|| position.includes("网络学时,不排时间教室")
@@ -343,6 +339,18 @@ function parseCoursesFromIframeDocument(iframeDoc) {
 				return;
 			}
 
+			// 移除教室中的“(白)”“(白云)”“(白)实”等字样,该信息对于学生而言无意义
+			position = position.replace(/[((]白云?[))](?:实(?![A-Za-z]))?/g, "");
+
+			// 移除教室末尾的“xxxx实验室”字样,这个信息对于学生而言无意义
+			position = position.replace(/(?:(?<=\d|\d[A-Za-z])(?:[^A-Za-z\d))]|(?<!\d)[A-Za-z])*实验室(?:[((]?[\d一二三四五六七八九十甲乙丙丁]+[))]?|(物理实验室)|(机房))*)+$/, "");
+
+			// 补全开头的“英东楼”
+			position = position.replace(/^英\s*(\d{3,4})/, "英东楼$1");
+
+			// 移除掉生科楼的“实”
+			position = position.replace(/(?<=生科[AB])实/, "");
+
 			const parsed = parseWeeksAndSections(weekText);
 
 			// 查重