feat: select school terms and smooth refractive Dock motion

This commit is contained in:
Codex
2026-10-13 19:08:36 +08:00
parent 3e2d8864af
commit 50fcc70e8e
33 changed files with 1245 additions and 94 deletions
@@ -1,5 +1,6 @@
import 'dart:convert';
import '../../domain/school_term.dart';
import 'school_navigation_policy.dart';
/// Only serialize recognized table fragments, never a login document.
@@ -14,7 +15,7 @@ const schoolPageProbeScript = r'''(() => {
} catch (_) { return false; }
};
const topUrl = location.href;
const result = {topUrl, authenticated: false, pages: []};
const result = {topUrl, authenticated: false, pages: [], terms: []};
if (!trusted(topUrl) || document.querySelector('input[type="password"]')) {
return JSON.stringify(result);
}
@@ -34,6 +35,13 @@ const schoolPageProbeScript = r'''(() => {
['timetable', '#tbl', '#drpxq'], ['exams', '#sample-table-1', '#xqbh']
]) {
const table = doc.querySelector(tableId), term = doc.querySelector(termId);
if (term && term.options && term.options.length <= 146) {
for (const option of Array.from(term.options)) {
const id = Number(option.value);
if (/^[1-9]\d*$/.test(option.value) && id <= 9999 &&
!result.terms.includes(id) && result.terms.length < 146) result.terms.push(id);
}
}
if (!table || !term || !term.options || term.selectedIndex < 0) continue;
const selected = term.cloneNode(true);
Array.from(selected.options).forEach((option, index) => {
@@ -59,9 +67,14 @@ class SchoolTableFragment {
}
class SchoolPageEvidence {
const SchoolPageEvidence(this.authenticated, this.pages);
const SchoolPageEvidence(
this.authenticated,
this.pages, {
this.terms = const [],
});
final bool authenticated;
final List<SchoolTableFragment> pages;
final List<SchoolTerm> terms;
static SchoolPageEvidence decode(Object raw, Uri current) {
dynamic value = raw;
@@ -92,6 +105,22 @@ class SchoolPageEvidence {
pages.add(SchoolTableFragment(page['kind'] as String, uri, content));
}
}
return SchoolPageEvidence(value['authenticated'] == true, pages);
final terms = <SchoolTerm>[];
final candidatesTerms = value['terms'];
if (candidatesTerms is List && candidatesTerms.length <= 146) {
final ids =
candidatesTerms
.whereType<int>()
.where((id) => id >= 1 && id <= 9999)
.toSet()
.toList()
..sort((a, b) => b.compareTo(a));
terms.addAll(ids.map(SchoolTerm.new));
}
return SchoolPageEvidence(
value['authenticated'] == true,
pages,
terms: terms,
);
}
}