[new] new project

This commit is contained in:
2026-09-20 13:33:09 +08:00
commit ca6a52fb2d
997 changed files with 140250 additions and 0 deletions
@@ -0,0 +1,17 @@
# resources/HNSF/adapters.yaml
adapters:
- adapter_id: "HNSF_01"
adapter_name: "河南师范大学适配教务"
category: "BACHELOR_AND_ASSOCIATE"
asset_js_path: "hnsf_01.js"
import_url: "https://jwc.htu.edu.cn/"
maintainer: "星河欲转"
description: "河南师范大学适配教务,添加双季作息,非本校开发者适配如果有误建议提交issues"
- adapter_id: "HNSF_02"
adapter_name: "河南师范大学适配教务"
category: "BACHELOR_AND_ASSOCIATE"
asset_js_path: "hnsf_02.js"
import_url: "https://jwc.htu.edu.cn/"
maintainer: "一颗"
description: "该作者没有添加说明"
@@ -0,0 +1,328 @@
// 河南师范大学(htu.edu.cn) 拾光课程表适配脚本
// 非该大学开发者适配,开发者无法及时发现问题
// 出现问题请提联系开发者或者提交pr更改,这更加快速
function parseWeeks(weekStr) {
if (!weekStr) return [];
// 假设新接口的 'zc' 字段已经是逗号分隔的周次数字字符串
const weeks = weekStr.split(',')
.map(w => Number(w.trim())) // 转换为数字
.filter(w => !isNaN(w) && w > 0); // 过滤掉无效数字
// 去重并排序
return [...new Set(weeks)].sort((a, b) => a - b);
}
function parseJsonData(jsonData) {
console.log("JS: parseJsonData 正在解析 JSON 数据...");
// 检查JSON结构
if (!jsonData || jsonData.code !== 0 || !Array.isArray(jsonData.data)) {
console.warn("JS: JSON 数据结构错误或code不为0。");
return [];
}
const rawCourseList = jsonData.data;
const finalCourseList = [];
for (const rawCourse of rawCourseList) {
// 关键字段检查
if (!rawCourse.kcmc || !rawCourse.teaxms || !rawCourse.jxcdmc ||
!rawCourse.xq || !rawCourse.ps || !rawCourse.pe || !rawCourse.zc) {
// console.warn("JS: 发现缺少关键字段的课程记录,跳过。", rawCourse);
continue;
}
const weeksArray = parseWeeks(rawCourse.zc);
// 周次有效性检查
if (weeksArray.length === 0) {
// console.warn(`JS: 课程 ${rawCourse.kcmc} 周次解析失败或为空,跳过。`);
continue;
}
const day = Number(rawCourse.xq); // xq: 星期几 (周一为1)
const startSection = Number(rawCourse.ps);
const endSection = Number(rawCourse.pe);
// 数字有效性检查
if (isNaN(day) || isNaN(startSection) || isNaN(endSection) || day < 1 || day > 7 || startSection > endSection) {
// console.warn(`JS: 课程 ${rawCourse.kcmc} 星期或节次数据无效,跳过。`);
continue;
}
finalCourseList.push({
name: rawCourse.kcmc.trim(),
teacher: rawCourse.teaxms.trim(),
position: rawCourse.jxcdmc.trim(),
day: day,
startSection: startSection,
endSection: endSection,
weeks: weeksArray
});
}
finalCourseList.sort((a, b) =>
a.day - b.day ||
a.startSection - b.startSection ||
a.name.localeCompare(b.name)
);
console.log(`JS: JSON 数据解析完成,共找到 ${finalCourseList.length} 门课程。`);
return finalCourseList;
}
function isLoginPage() {
const url = window.location.href;
const expectedBaseUrl = 'https://jwc.htu.edu.cn';
const cleanUrl = url.endsWith('/') ? url.slice(0, -1) : url;
const isRootLogin = cleanUrl === expectedBaseUrl;
const isKeywordLogin = url.includes('login') || url.includes('cas');
return url.includes('htu.edu.cn') && (isRootLogin || isKeywordLogin);
}
function validateYearInput(input) {
    console.log("JS: validateYearInput 被调用,输入: " + input);
    if (/^[0-9]{4}$/.test(input)) {
        console.log("JS: validateYearInput 验证通过。");
        return false;
    } else {
        console.log("JS: validateYearInput 验证失败。");
        return "请输入四位数字的学年!";
    }
}
async function promptUserToStart() {
    console.log("JS: 流程开始:显示公告。");
    return await window.shiguangBridgePromise.showAlert(
        "教务系统课表导入",
        "导入前请确保您已在浏览器中成功登录教务系统",
        "好的,开始导入"
    );
}
async function getAcademicYear() {
    const currentYear = new Date().getFullYear().toString();
    console.log("JS: 提示用户输入学年。");
    return await window.shiguangBridgePromise.showPrompt(
        "选择学年",
        "请输入要导入课程的起始学年(例如 2025-2026 应输入2025):",
        currentYear,
        "validateYearInput"
    );
}
async function selectSemester() {
    const semesters = ["第一学期 (01)", "第二学期 (02)"];
    console.log("JS: 提示用户选择学期。");
    const semesterIndex = await window.shiguangBridgePromise.showSingleSelection(
        "选择学期",
        JSON.stringify(semesters),
        0
    );
    return semesterIndex;
}
async function fetchAndParseCourses(academicYear, semesterIndex) {
window.shiguangBridge.showToast("正在请求课表数据...");
// 学年学期代码组合:202501 (第一学期), 202502 (第二学期)
// semesterIndex 0 对应 01, 1 对应 02
const semesterCode = semesterIndex === 0 ? "01" : "02";
const xnxqdmBody = `xnxqdm=${academicYear}${semesterCode}`;
const url = "https://jwc.htu.edu.cn/new/student/xsgrkb/getCalendarWeekDatas";
console.log(`JS: 发送请求到 ${url}, body: ${xnxqdmBody}`);
const requestOptions = {
"headers": {
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
},
"body": xnxqdmBody,
"method": "POST",
"credentials": "include"
};
try {
const response = await fetch(url, requestOptions);
if (!response.ok) {
throw new Error(`网络请求失败。状态码: ${response.status} (${response.statusText})`);
}
const jsonText = await response.text();
let jsonData;
try {
jsonData = JSON.parse(jsonText);
} catch (e) {
console.error('JS: JSON 解析失败:', e);
window.shiguangBridge.showToast("数据返回格式错误,可能是您未成功登录或会话已过期。");
return null;
}
const courses = parseJsonData(jsonData);
if (courses.length === 0) {
window.shiguangBridge.showToast("未找到任何课程数据,请检查所选学年学期是否正确或本学期无课。");
return null;
}
console.log(`JS: 课程数据解析成功,共找到 ${courses.length} 门课程。`);
return { courses: courses };
} catch (error) {
window.shiguangBridge.showToast(`请求或解析失败: ${error.message}`);
console.error('JS: Fetch/Parse Error:', error);
return null;
}
}
async function saveCourses(parsedCourses) {
    window.shiguangBridge.showToast(`正在保存 ${parsedCourses.length} 门课程...`);
    console.log(`JS: 尝试保存 ${parsedCourses.length} 门课程...`);
    try {
        await window.shiguangBridgePromise.saveImportedCourses(JSON.stringify(parsedCourses, null, 2));
        console.log("JS: 课程保存成功!");
        return true;
    } catch (error) {
        window.shiguangBridge.showToast(`课程保存失败: ${error.message}`);
        console.error('JS: Save Courses Error:', error);
        return false;
    }
}
const Non_summerTimeSlots = [
    { number: 1, startTime: "08:00", endTime: "08:45" },
    { number: 2, startTime: "08:55", endTime: "09:40" },
    { number: 3, startTime: "10:10", endTime: "10:55" },
    { number: 4, startTime: "11:05", endTime: "11:50" },
    { number: 5, startTime: "14:30", endTime: "15:15" },
    { number: 6, startTime: "15:25", endTime: "16:10" },
    { number: 7, startTime: "16:40", endTime: "17:25" },
    { number: 8, startTime: "17:35", "endTime": "18:20" },
    { number: 9, startTime: "19:30", "endTime": "20:15" },
    { number: 10, startTime: "20:25", "endTime": "21:10" }
];
const SummerTimeSlots = [
    { number: 1, startTime: "08:00", endTime: "08:45" },
    { number: 2, startTime: "08:55", endTime: "09:40" },
    { number: 3, startTime: "10:10", endTime: "10:55" },
    { number: 4, startTime: "11:05", endTime: "11:50" },
    { number: 5, startTime: "15:00", endTime: "15:45" },
    { number: 6, startTime: "15:55", endTime: "16:40" },
    { number: 7, startTime: "17:10", endTime: "17:55" },
    { number: 8, startTime: "18:05", "endTime": "18:50" },
    { number: 9, startTime: "20:00", "endTime": "20:45" },
    { number: 10, startTime: "20:55", "endTime": "21:40" }
];
async function selectTimeSlotsType() {
    const timeSlotsOptions = ["非夏季作息", "夏季作息"];
    console.log("JS: 提示用户选择作息时间类型。");
    const selectedIndex = await window.shiguangBridgePromise.showSingleSelection(
        "选择作息时间",
        JSON.stringify(timeSlotsOptions),
        0
    );
    return selectedIndex;
}
async function importPresetTimeSlots(timeSlots) {
    console.log(`JS: 准备导入 ${timeSlots.length} 个预设时间段。`);
    if (timeSlots.length > 0) {
        window.shiguangBridge.showToast(`正在导入 ${timeSlots.length} 个预设时间段...`);
        try {
            await window.shiguangBridgePromise.savePresetTimeSlots(JSON.stringify(timeSlots));
            window.shiguangBridge.showToast("预设时间段导入成功!");
            console.log("JS: 预设时间段导入成功。");
        } catch (error) {
            window.shiguangBridge.showToast("导入时间段失败: " + error.message);
            console.error('JS: Save Time Slots Error:', error);
        }
    } else {
        window.shiguangBridge.showToast("警告:时间段为空,未导入时间段信息。");
        console.warn("JS: 警告:传入时间段为空,未导入时间段信息。");
    }
}
async function runImportFlow() {
    if (isLoginPage()) {
        window.shiguangBridge.showToast("导入失败:请先登录教务系统!");
        console.log("JS: 检测到当前在登录页面,终止导入。");
        return;
    }
    // 1. 公告和前置检查。
    const alertConfirmed = await promptUserToStart();
    if (!alertConfirmed) {
        window.shiguangBridge.showToast("用户取消了导入。");
        console.log("JS: 用户取消了导入流程。");
        return;
    }
    const academicYear = await getAcademicYear();
    if (academicYear === null) {
        window.shiguangBridge.showToast("导入已取消。");
        console.log("JS: 获取学年失败/取消,流程终止。");
        return;
    }
    console.log(`JS: 已选择学年: ${academicYear}`);
    const semesterIndex = await selectSemester();
    if (semesterIndex === null || semesterIndex === -1) {
        window.shiguangBridge.showToast("导入已取消。");
        console.log("JS: 选择学期失败/取消,流程终止。");
        return;
    }
    console.log(`JS: 已选择学期索引: ${semesterIndex}`);
    // 2. 获取并解析课程
    const result = await fetchAndParseCourses(academicYear, semesterIndex);
    if (result === null) {
        console.log("JS: 课程获取或解析失败,流程终止。");
        return;
    }
    const { courses } = result;
    // 3. 课程数据保存。
    const saveResult = await saveCourses(courses);
    if (!saveResult) {
        console.log("JS: 课程保存失败,流程终止。");
        return;
    }
    // 4. 作息时间选择与导入
    const timeSlotsIndex = await selectTimeSlotsType();
    let selectedTimeSlots = [];
    if (timeSlotsIndex === 0) {
        // 0: 非夏季作息
        selectedTimeSlots = Non_summerTimeSlots;
        console.log("JS: 已选择非夏季作息。");
    } else if (timeSlotsIndex === 1) {
        // 1: 夏季作息
        selectedTimeSlots = SummerTimeSlots;
        console.log("JS: 已选择夏季作息。");
    } else {
        selectedTimeSlots = Non_summerTimeSlots;
        console.warn("JS: 作息时间选择失败/取消,使用非夏季作息作为默认值。");
    }
    await importPresetTimeSlots(selectedTimeSlots);
    window.shiguangBridge.showToast(`课程导入成功,共导入 ${courses.length} 门课程!`);
    console.log("JS: 整个导入流程执行完毕并成功。");
    window.shiguangBridge.notifyTaskCompletion();
}
runImportFlow();
@@ -0,0 +1,319 @@
// ====================== 工具函数 ======================
/**
* 检查用户是否已登录。
* 如果当前URL包含登录关键字,说明用户未登录,返回false。
* 如果不包含登录关键字,说明用户已登录,返回true。
*/
function isUserLoggedIn() {
const url = window.location.href;
const loginKeywords = [
"https://jwc.htu.edu.cn/xtgl/login_slogin.html"
];
// 检查URL是否包含登录关键字
for (const keyword of loginKeywords) {
if (url.includes(keyword)) {
return false; // 包含登录关键字,说明用户未登录
}
}
// 不包含登录关键字,说明用户已登录
return true;
}
// 展开 weeks 字符串 -> 数字数组
function parseWeeks(weeksStr) {
const weeks = new Set();
if (!weeksStr) return [];
const parts = weeksStr.split(",");
for (const part of parts) {
if (part.includes("-")) {
const [start, end] = part.split("-").map(n => parseInt(n));
for (let i = start; i <= end && i <= 20; i++) {
weeks.add(i);
}
} else {
const n = parseInt(part);
if (n >= 1 && n <= 20) weeks.add(n);
}
}
return Array.from(weeks).sort((a, b) => a - b);
}
// 合并重复课程
function mergeDuplicateCourses(courses) {
const merged = [];
const keyMap = {}; // key = name+day+startSection+endSection+position
for (const c of courses) {
const key = `${c.name}|${c.day}|${c.startSection}|${c.endSection}|${c.position}`;
if (!keyMap[key]) {
keyMap[key] = { ...c, weeks: [...c.weeks] };
} else {
keyMap[key].weeks = Array.from(new Set([...keyMap[key].weeks, ...c.weeks]));
}
}
for (const k in keyMap) merged.push(keyMap[k]);
return merged;
}
// ====================== 选择月份 ======================
async function selectMonth() {
try {
// 生成月份选项
const months = [];
const currentYear = new Date().getFullYear();
// 生成当前学年(9月到次年6月)的月份选项
for (let month = 9; month <= 12; month++) {
months.push(`${currentYear}年${month}月`);
}
for (let month = 1; month <= 6; month++) {
months.push(`${currentYear + 1}年${month}月`);
}
const selectedIndex = await window.shiguangBridgePromise.showSingleSelection(
"请选择要获取课程的月份",
JSON.stringify(months),
0
);
if (selectedIndex === null) return null;
const selectedMonth = months[selectedIndex];
const year = parseInt(selectedMonth.split('年')[0]);
const month = parseInt(selectedMonth.split('年')[1].split('月')[0]);
// 计算该月的开始和结束日期
const startDate = new Date(year, month - 1, 1);
const endDate = new Date(year, month, 0); // 该月最后一天
return {
startDate: startDate,
endDate: endDate,
year: year,
month: month
};
} catch (err) {
console.error("选择月份失败:", err);
return null;
}
}
// ====================== 异步获取课程数据 ======================
async function fetchCoursesData() {
try {
// 让用户选择月份
const monthSelection = await selectMonth();
if (!monthSelection) {
window.shiguangBridge.showToast("用户取消选择月份!");
return null;
}
// 格式化日期为API需要的格式
const formatDate = (date) => {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
return `${year}-${month}-${day}+00%3A00%3A00`;
};
const d1 = formatDate(monthSelection.startDate);
const d2 = formatDate(monthSelection.endDate);
const res = await fetch("https://jwc.htu.edu.cn/new/desktop/getCalendar", {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `d1=${d1}&d2=${d2}`
});
const json = await res.json();
return json; // 直接返回课程数据数组
} catch (err) {
console.error("获取课程数据失败:", err);
window.shiguangBridge.showToast("获取课程数据失败:" + err.message);
return null;
}
}
// ====================== 处理新格式的课程数据 ======================
async function processCoursesData(coursesData) {
if (!coursesData || !Array.isArray(coursesData)) {
return null;
}
const allCourses = [];
coursesData.forEach((course) => {
// 解析节次代码 (如 "0910" -> 第9节到第10节)
const jcdm = course.jcdm || "";
if (!jcdm || jcdm.length < 4) {
return;
}
const startSection = parseInt(jcdm.substring(0, 2));
const endSection = parseInt(jcdm.substring(2, 4));
// 解析周次 (如 "10" -> [10])
const weeks = parseWeeks(course.zc || "");
if (!weeks.length) {
return;
}
// 解析星期 (如 "3" -> 星期三)
const day = parseInt(course.xq || "1");
if (day < 1 || day > 7) {
return;
}
// 处理地点格式,按照 [校本部]西校区新联楼0303 的格式
let position = course.jxcdmc || "";
const xqmc = course.xqmc || "校本部";
if (position && !position.startsWith("[")) {
position = `[${xqmc}]${position}`;
}
const processedCourse = {
name: course.kcmc || "",
teacher: course.teaxms || "",
position: position,
day: day,
startSection: startSection,
endSection: endSection,
weeks: weeks
};
allCourses.push(processedCourse);
});
const mergedCourses = mergeDuplicateCourses(allCourses);
return mergedCourses.length ? mergedCourses : null;
}
// ====================== 保存课程 ======================
async function saveCourses(courses) {
try {
const result = await window.shiguangBridgePromise.saveImportedCourses(JSON.stringify(courses));
if (result === true) {
window.shiguangBridge.showToast("课程导入成功!");
return true;
} else {
window.shiguangBridge.showToast("课程导入失败,请查看日志!");
return false;
}
} catch (err) {
console.error("保存课程失败:", err);
window.shiguangBridge.showToast("保存课程失败:" + err.message);
return false;
}
}
// ====================== 导入预设时间段(一天5节大课,10节小课) ======================
async function importPresetTimeSlots() {
// 一天5节大课,10节小课的时间安排
const presetTimeSlots = [
{ number: 1, startTime: "08:00", endTime: "08:45" }, // 第1节
{ number: 2, startTime: "08:45", endTime: "09:30" }, // 第2节
{ number: 3, startTime: "09:50", endTime: "10:35" }, // 第3节
{ number: 4, startTime: "10:35", endTime: "11:20" }, // 第4节
{ number: 5, startTime: "14:00", endTime: "14:45" }, // 第5节
{ number: 6, startTime: "14:45", endTime: "15:30" }, // 第6节
{ number: 7, startTime: "15:50", endTime: "16:35" }, // 第7节
{ number: 8, startTime: "16:35", endTime: "17:20" }, // 第8节
{ number: 9, startTime: "19:00", endTime: "19:45" }, // 第9节
{ number: 10, startTime: "19:45", endTime: "20:30" } // 第10节
];
try {
const result = await window.shiguangBridgePromise.savePresetTimeSlots(JSON.stringify(presetTimeSlots));
if (result === true) {
window.shiguangBridge.showToast("时间段导入成功!");
} else {
window.shiguangBridge.showToast("时间段导入失败,请查看日志!");
}
} catch (err) {
console.error("时间段导入失败:", err);
window.shiguangBridge.showToast("时间段导入失败:" + err.message);
}
}
// ====================== 显示公告 ======================
async function showAnnouncement() {
try {
const announcement = `
课程导入工具使用说明:
1. 本工具用于从教务系统获取课程数据
2. 请确保已登录教务系统
3. 选择要获取课程的月份
4. 工具会自动下载原始数据和处理后的数据
5. 支持一天10节课的时间安排
6. 自动合并重复课程
使用前请确认网络连接正常!
`.trim();
await window.shiguangBridgePromise.showAlert(
"课程导入工具公告",
announcement
);
} catch (err) {
console.error("显示公告失败:", err);
// 如果弹窗失败,使用Toast提示
window.shiguangBridge.showToast("课程导入工具启动中...");
}
}
// ====================== 主流程 ======================
async function runImportFlow() {
// 检查用户是否已登录
if (!isUserLoggedIn()) {
window.shiguangBridge.showToast("检测到未登录状态,请先登录后再使用课程导入功能!");
return;
}
// 显示公告
await showAnnouncement();
window.shiguangBridge.showToast("课程导入流程即将开始...");
// 1️⃣ 获取课程数据
const coursesData = await fetchCoursesData();
if (!coursesData) {
return;
}
// 2️⃣ 处理课程数据
const courses = await processCoursesData(coursesData);
if (!courses) {
window.shiguangBridge.showToast("没有找到有效的课程数据!");
return;
}
// 3️⃣ 保存课程
const saveResult = await saveCourses(courses);
if (!saveResult) {
return;
}
// 4️⃣ 导入预设时间段
await importPresetTimeSlots();
// ✅ 只有所有步骤都成功完成,才通知任务完成
window.shiguangBridge.showToast(`课程导入成功,共导入 ${courses.length} 门课程!`);
console.log("JS:整个导入流程执行完毕并成功。");
window.shiguangBridge.notifyTaskCompletion();
}
// 启动流程
runImportFlow();