Skip to content

Commit

Permalink
fix(script): - 优化超星章节测试题目解析
Browse files Browse the repository at this point in the history
- 修复部分超星考试嵌套在其他页面中,导致繁体字无法加载不能考试的BUG
  • Loading branch information
ennnncy committed Apr 10, 2023
1 parent 941c0e9 commit 6b39e40
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ocsjs",
"version": "4.2.18",
"version": "4.2.20",
"description": "ocs - online course script 在线网络课程辅助工具",
"types": "./lib/src/core/index.d.ts",
"main": "./lib/src/core/index.js",
Expand Down
18 changes: 12 additions & 6 deletions packages/scripts/src/projects/cx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,17 +684,23 @@ export function workOrExam(
* @see 参考 https://bbs.tampermonkey.net.cn/thread-2303-1-1.html
*/
async function mappingRecognize(doc: Document = document) {
// @ts-ignore
top.typrMapping = top.typrMapping || (await loadTyprMapping());
let typrMapping = Object.create({});
try {
// @ts-ignore
top.typrMapping = top.typrMapping || (await loadTyprMapping());
// @ts-ignore
typrMapping = top.typrMapping;
} catch {
// 超星考试可能嵌套其他平台中,所以会存在跨域,这里需要处理一下跨域情况,如果是跨域直接在当前页面加载字库
typrMapping = await loadTyprMapping();
}

/** 判断是否有繁体字 */
const fontFaceEl = Array.from(doc.head.querySelectorAll('style')).find((style) =>
style.textContent?.includes('font-cxsecret')
);
// @ts-ignore
const fontMap = top.typrMapping;

if (fontFaceEl) {
const fontMap = typrMapping;
if (fontFaceEl && Object.keys(fontMap).length > 0) {
// 解析font-cxsecret字体
const font = fontFaceEl.textContent?.match(/base64,([\w\W]+?)'/)?.[1];

Expand Down

0 comments on commit 6b39e40

Please sign in to comment.