Skip to content

Commit

Permalink
fix(script): 优化软件同步设置,优化题库状态显示
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Apr 7, 2023
1 parent 7ba565e commit 4e3cc96
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 19 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.15",
"version": "4.2.17",
"description": "ocs - online course script 在线网络课程辅助工具",
"types": "./lib/src/core/index.d.ts",
"main": "./lib/src/core/index.js",
Expand Down
18 changes: 9 additions & 9 deletions packages/core/src/render/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,21 @@ export const RenderScript = new Script({
panel.body.replaceChildren(el('hr'), closeBtn);
},

async onactive({ style, projects }: StartConfig) {
async onactive({ style, projects, defaultPanelName }: StartConfig) {
/** 兼容低版本浏览器 */
handleLowLevelBrowser();

/** 加载自定义元素 */
$.loadCustomElements(definedCustomElements);

/** 默认值 */
const defaults = {
/** 当前页面存在默认页面 */
urls: (urls: string[]) => (urls && urls.length ? urls : [location.href]),
/** 默认面板名 */
panelName: (name: string) => name || defaultPanelName || ''
};

/** 当前匹配到的脚本,并且面板不隐藏 */
const matchedScripts = $.getMatchedScripts(projects, [location.href]).filter((s) => !s.hideInPanel);

Expand Down Expand Up @@ -381,14 +389,6 @@ export const RenderScript = new Script({
}
});

/** 默认值 */
const defaults = {
/** 当前页面存在默认页面 */
urls: (urls: string[]) => (urls && urls.length ? urls : [location.href]),
/** 默认面板名 */
panelName: (name: string) => name || RenderScript.namespace || ''
};

/**
* 创建一个模态框代替原生的 alert, confirm, prompt
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/utils/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export interface StartConfig {
style: string;
/** 项目列表 */
projects: Project[];
/** 默认面板名称 */
defaultPanelName: string;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/scripts/entry.dev.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* eslint-disable no-undef */
/// <reference path="./global.d.ts" />

const { start, definedProjects } = OCS;
const { start, definedProjects, CommonProject } = OCS;

(function () {
'use strict';

// 运行脚本
start({
style: GM_getResourceText('STYLE'),
projects: definedProjects()
projects: definedProjects(),
defaultPanelName: CommonProject.scripts.guide.namespace
});
})();
5 changes: 3 additions & 2 deletions packages/scripts/entry.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* eslint-disable no-undef */
/// <reference path="./global.d.ts" />

const { start, definedProjects } = OCS;
const { start, definedProjects, CommonProject } = OCS;

(function () {
'use strict';

// 运行脚本
start({
style: STYLE,
projects: definedProjects()
projects: definedProjects(),
defaultPanelName: CommonProject.scripts.guide.namespace
});
})();
14 changes: 9 additions & 5 deletions packages/scripts/src/projects/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,21 @@ export const CommonProject = Project.create({
updateState();
};
const tableContainer = el('div');
refresh.style.display = 'none';
tableContainer.style.display = 'none';
panel.body.append(refresh, tableContainer);

// 更新题库状态
const updateState = async () => {
// 清空元素
tableContainer.replaceChildren();
refresh.toggleAttribute('disabled');
refresh.textContent = '🚫正在加载...';

let loadedCount = 0;

if (this.cfg.answererWrappers.length) {
refresh.style.display = 'block';
tableContainer.style.display = 'block';
refresh.textContent = '🚫正在加载...';
refresh.setAttribute('disabled', 'true');
const table = el('table');
table.style.width = '100%';
this.cfg.answererWrappers.forEach(async (item) => {
Expand Down Expand Up @@ -308,13 +311,14 @@ export const CommonProject = Project.create({
if (loadedCount === this.cfg.answererWrappers.length) {
setTimeout(() => {
refresh.textContent = '🔄️刷新题库状态';
refresh.toggleAttribute('disabled');
refresh.removeAttribute('disabled');
}, 3000);
}
});
tableContainer.append(table);
} else {
tableContainer.append(el('div', '暂无任何题库...'));
refresh.style.display = 'none';
tableContainer.style.display = 'none';
}
};

Expand Down

0 comments on commit 4e3cc96

Please sign in to comment.