fix: rename assistant and gate exports behind collapsible switch
This commit is contained in:
+29
-15
@@ -21,7 +21,7 @@
|
||||
const state = {
|
||||
autoAnswer: false, allowCopy: true, role: '', course: '', courses: [],
|
||||
bankTotal: 0, roleCounts: {}, storageMode: 'userscript', pageStatus: '等待识别练习页面',
|
||||
canAnswer: false, canExport: false, metrics: {}, autoExport: true, expanded: false, loading: false
|
||||
canAnswer: false, canExport: false, metrics: {}, exportEnabled: false, expanded: false, loading: false
|
||||
};
|
||||
let destroyed = false;
|
||||
let selectionText = '';
|
||||
@@ -43,7 +43,7 @@
|
||||
visibilityStyle.textContent = '[hidden]{display:none!important}';
|
||||
root.appendChild(visibilityStyle);
|
||||
const panel = el(doc, 'section', 'panel collapsed');
|
||||
panel.setAttribute('aria-label', '谊安学题库助手');
|
||||
panel.setAttribute('aria-label', '谊安学助手 2.0');
|
||||
const header = el(doc, 'div', 'header');
|
||||
const brand = el(doc, 'span', 'brand', '题库助手');
|
||||
const expand = el(doc, 'button', 'toggle', '展开');
|
||||
@@ -76,7 +76,7 @@
|
||||
brand.addEventListener('click', togglePanel);
|
||||
|
||||
const switches = el(doc, 'div', 'switches');
|
||||
function makeSwitch(labelText, callback) {
|
||||
function makeSwitch(labelText, callback, container) {
|
||||
const label = el(doc, 'label', 'switch-row');
|
||||
const text = el(doc, 'span', '', labelText);
|
||||
const input = el(doc, 'input', 'switch');
|
||||
@@ -84,7 +84,7 @@
|
||||
input.setAttribute('role', 'switch');
|
||||
input.setAttribute('aria-label', labelText);
|
||||
label.append(text, input);
|
||||
switches.appendChild(label);
|
||||
(container || switches).appendChild(label);
|
||||
input.addEventListener('change', callback);
|
||||
return { input: input, label: label };
|
||||
}
|
||||
@@ -227,22 +227,35 @@
|
||||
const unprocessedList = el(doc, 'div', 'unprocessed-list');
|
||||
unprocessed.append(unprocessedSummary, unprocessedList);
|
||||
unprocessed.hidden = true;
|
||||
pageSection.append(pageStatus, metrics, unprocessed);
|
||||
body.appendChild(pageSection);
|
||||
|
||||
const exportSection = el(doc, 'section', 'page-section export-section');
|
||||
exportSection.setAttribute('aria-label', '题库导出设置');
|
||||
const exportSwitch = makeSwitch('导出题库', function () {
|
||||
state.exportEnabled = exportSwitch.input.checked;
|
||||
refresh();
|
||||
invoke('onExportEnabledChange', state.exportEnabled);
|
||||
}, exportSection);
|
||||
const exportContent = el(doc, 'div', 'export-content');
|
||||
exportContent.id = 'yian-export-content';
|
||||
exportContent.hidden = true;
|
||||
exportSwitch.input.setAttribute('aria-controls', exportContent.id);
|
||||
exportContent.appendChild(el(doc, 'p', 'hint', '开启后,题目和答案完整时自动导出 CSV;也可点击下方按钮重新导出。关闭后停止后续导出。'));
|
||||
const exportRow = el(doc, 'div', 'exports');
|
||||
const exportButtons = [];
|
||||
['csv', 'json', 'txt'].forEach(function (format) {
|
||||
const button = el(doc, 'button', '', '导出 ' + format.toUpperCase());
|
||||
button.type = 'button';
|
||||
button.addEventListener('click', function () { invoke('onExport', format); });
|
||||
button.addEventListener('click', function () {
|
||||
if (state.exportEnabled && state.canExport) invoke('onExport', format);
|
||||
});
|
||||
exportRow.appendChild(button);
|
||||
exportButtons.push(button);
|
||||
});
|
||||
const autoExportLabel = el(doc, 'label', 'auto-export');
|
||||
const autoExportInput = el(doc, 'input');
|
||||
autoExportInput.type = 'checkbox';
|
||||
autoExportLabel.append(autoExportInput, el(doc, 'span', '', '进入练习时自动导出 CSV'));
|
||||
autoExportInput.addEventListener('change', function () { state.autoExport = autoExportInput.checked; invoke('onAutoExportChange', state.autoExport); });
|
||||
pageSection.append(pageStatus, metrics, unprocessed, exportRow, autoExportLabel);
|
||||
body.appendChild(pageSection);
|
||||
exportContent.appendChild(exportRow);
|
||||
exportSection.appendChild(exportContent);
|
||||
body.appendChild(exportSection);
|
||||
|
||||
function autoUnavailableReason() {
|
||||
if (!state.role) return '请选择岗位后再开启自动选择。';
|
||||
@@ -260,7 +273,7 @@
|
||||
if (destroyed) return;
|
||||
panel.classList.toggle('collapsed', !state.expanded);
|
||||
body.hidden = !state.expanded;
|
||||
brand.textContent = state.expanded ? '谊安学助手' : '题库助手';
|
||||
brand.textContent = state.expanded ? '谊安学助手 2.0' : '题库助手';
|
||||
expand.textContent = state.expanded ? '收起' : '展开';
|
||||
expand.setAttribute('aria-label', state.expanded ? '收起题库助手' : '展开题库助手');
|
||||
expand.setAttribute('aria-expanded', String(Boolean(state.expanded)));
|
||||
@@ -310,8 +323,9 @@
|
||||
notProcessed.forEach(function (item) {
|
||||
unprocessedList.appendChild(el(doc, 'div', '', '第 ' + item.number + ' 题 · ' + (metricLabels[item.status] || '已跳过') + ':' + (item.reason || '请人工核对。')));
|
||||
});
|
||||
exportButtons.forEach(function (button) { button.disabled = !state.canExport; });
|
||||
autoExportInput.checked = Boolean(state.autoExport);
|
||||
exportSwitch.input.checked = Boolean(state.exportEnabled);
|
||||
exportContent.hidden = !state.exportEnabled;
|
||||
exportButtons.forEach(function (button) { button.disabled = !state.exportEnabled || !state.canExport; });
|
||||
previous.disabled = currentOffset === 0 || Boolean(state.loading);
|
||||
next.disabled = currentOffset + PAGE_SIZE >= resultTotal || Boolean(state.loading);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user