Skip to content

Commit

Permalink
feat: 新增智慧树共享课考试脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Apr 28, 2022
1 parent aa5daf5 commit 5ba2022
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 100 deletions.
21 changes: 16 additions & 5 deletions packages/core/src/components/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const SearchResults = defineComponent({
<hr />

<div>
{validResult.value.map((res) => {
{validResult.value.map((res, i) => {
const title = res.ctx?.elements.title?.[0];

return (
Expand All @@ -111,10 +111,21 @@ export const SearchResults = defineComponent({
style={{ color: res.result?.finish ? '' : 'red' }}
title={res.ctx?.elements.title?.[0].innerText}
>
{StringUtils.of(title?.innerText || '')
.nowrap()
.max(40)
.toString()}
<span style={{
borderRight: '1px solid #cbcbcb',
marginRight: '2px',
paddingRight: '2px',
color: 'darkgrey'
}}>
{i + 1}
</span>
<span>
{StringUtils.of(title?.innerText || '')
.nowrap()
.max(40)
.toString()}
</span>

</div>
);
})}
Expand Down
29 changes: 29 additions & 0 deletions packages/core/src/components/zhs/ExamSettingPanel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { defineComponent } from 'vue';
import { createWorkerSetting } from '..';
import { store } from '../../script';
import { WorkSettingPanel } from './WorkSettingPanel';

export const ExamSettingPanel = defineComponent({
setup (props, { slots }) {
const settings = store.setting.zhs.exam;

return () => (
<WorkSettingPanel v-slots={{
upload: createWorkerSetting(
'自动答题',
{
selected: 'close',
options: [
{
label: '请自行检查后自行点击提交',
value: 'close'
}
]
},
(e: any) => (settings.upload = e.target.value)
)
}}>
</WorkSettingPanel>
);
}
});
6 changes: 3 additions & 3 deletions packages/core/src/core/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export function searchIFrame (root: Document) {
/**
* 检测页面是否准备完毕
*/
export function onReady (callback: () => void, root: Document = document) {
export function onComplete (callback: () => void, root: Document = document) {
function checkReady () {
if (root.readyState === 'complete') {
callback();
Expand All @@ -144,9 +144,9 @@ export function onReady (callback: () => void, root: Document = document) {
/**
* 检测页面是否加载
*/
export function onLoaded (callback: () => void, root: Document = document) {
export function onInteractive(callback: () => void, root: Document = document) {
function checkLoaded () {
if (root.readyState === 'complete' || root.readyState === 'interactive') {
if (root.readyState === 'interactive') {
root.removeEventListener('readystatechange', checkLoaded);
callback();
}
Expand Down
31 changes: 19 additions & 12 deletions packages/core/src/script/common/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { store } from '..';
import { createNote } from '../../components';
import { defineScript } from '../../core/define.script';
import { urlGlob } from '../../core/utils';
import { store } from '..';
import { onComplete, onInteractive, urlGlob } from '../../core/utils';

const supports = [
['**chaoxing.com**', 'cx'],
Expand Down Expand Up @@ -46,20 +46,27 @@ export const CommonScript = defineScript({
{
name: '开启页面右键复制粘贴功能',
url: supports.map((arr) => arr[0]),
onload () {
console.log('开启页面右键复制粘贴功能');
try {
const d = document;
const b = document.body;
d.onselectstart = d.oncopy = d.onpaste = d.onkeydown = d.oncontextmenu = () => true;
b.onselectstart = b.oncopy = b.onpaste = b.onkeydown = b.oncontextmenu = () => true;
} catch (err) {
console.error('页面右键复制粘贴功能开启失败', err);
start () {
function enableCopy () {
console.log('开启页面右键复制粘贴功能');
try {
const d = document;
const b = document.body;
d.onselectstart = d.oncopy = d.onpaste = d.onkeydown = d.oncontextmenu = () => true;
b.onselectstart = b.oncopy = b.onpaste = b.onkeydown = b.oncontextmenu = () => true;
} catch (err) {
console.error('页面右键复制粘贴功能开启失败', err);
}
}
onInteractive(() => enableCopy());
onComplete(() => {
enableCopy();
setTimeout(() => enableCopy(), 3000);
});
}
},
{
name: 'OCS样式切换, 位置定位脚本',
name: 'OCS样式切换,位置定位脚本',
url: supports.map((arr) => arr[0]),
onload () {
const target = ['o', 'c', 's'];
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/script/cx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export const CXScript = defineScript({
confirm('未设置题库配置!请在设置面板设置后刷新重试!');
} else {
/** 运行作业脚本 */
await workOrExam(setting, false);
await workOrExam(setting, 'work');
}
}
},
Expand All @@ -151,7 +151,7 @@ export const CXScript = defineScript({
confirm('未设置题库配置!请在设置面板设置后刷新重试!');
} else {
/** 运行考试脚本 */
await workOrExam(setting, true);
await workOrExam(setting, 'exam');
}
}
},
Expand Down
24 changes: 12 additions & 12 deletions packages/core/src/script/cx/work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { defaultSetting, ScriptSettings } from '../../scripts';

export async function workOrExam(
setting: ScriptSettings['cx']['work'] | ScriptSettings['cx']['exam'],
isExam: boolean
type: 'work' | 'exam' = 'work'
) {
const { period, timeout, retry } = defaults(setting, defaultSetting().work);

Expand All @@ -34,7 +34,7 @@ export async function workOrExam(
elements: {
title: 'h3',
options: '.answerBg .answer_p, .textDIV, .eidtDiv',
type: isExam ? 'input[name^="type"]' : 'input[id^="answertype"]'
type: type === 'exam' ? 'input[name^="type"]' : 'input[id^="answertype"]'
},
/** 默认搜题方法构造器 */
answerer: (elements, type) => {
Expand Down Expand Up @@ -110,14 +110,14 @@ export async function workOrExam(

logger('info', '做题完毕', results);

// 处理提交
await worker.uploadHandler({
uploadRate: setting.upload,
results,
async callback(finishedRate, uploadable) {
if (isExam) {
logger('info', '为了安全考虑,请自行检查后自行点击提交!');
} else {
if (type === 'exam') {
logger('info', '为了安全考虑,请自行检查后自行点击提交!');
} else {
// 处理提交
await worker.uploadHandler({
uploadRate: setting.upload,
results,
async callback(finishedRate, uploadable) {
logger('info', '完成率 : ', finishedRate, ' , ', uploadable ? '5秒后将自动提交' : '5秒后将自动保存');

await sleep(5000);
Expand All @@ -134,6 +134,6 @@ export async function workOrExam(
saveWork();
}
}
}
});
});
}
}
4 changes: 2 additions & 2 deletions packages/core/src/script/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import defaultsDeep from 'lodash/defaultsDeep';
import { reactive, watch } from 'vue';
import { OCSLocalStorage, OCSStore } from '../core/store';
import { isInBrowser, onReady } from '../core/utils';
import { isInBrowser, onComplete } from '../core/utils';
import { logger } from '../logger';
import { defaultOCSSetting } from '../scripts';

Expand All @@ -16,7 +16,7 @@ if (isInBrowser()) {
store = createStore();
}

onReady(() => {
onComplete(() => {
if (typeof unsafeWindow !== 'undefined') {
// 统一转向顶层对象
// eslint-disable-next-line no-undef
Expand Down
95 changes: 62 additions & 33 deletions packages/core/src/script/zhs/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { store } from '..';
import { createNote, createSearchResultPanel, createTerminalPanel } from '../../components';
import { ExamSettingPanel } from '../../components/cx/ExamSettingPanel';
import { StudySettingPanel } from '../../components/zhs/StudySettingPanel';
import { WorkSettingPanel } from '../../components/zhs/WorkSettingPanel';
import { defineScript } from '../../core/define.script';
Expand All @@ -8,7 +9,7 @@ import { logger } from '../../logger';
import { defaultSetting } from '../../scripts';
import { CreditWorkSettingPanel } from './../../components/zhs/CreditWorkSettingPanel';
import { creditStudy, study } from './study';
import { creditWork, work } from './work';
import { creditWork, workOrExam } from './work';

export const ZHSScript = defineScript({
name: '知道智慧树',
Expand All @@ -24,18 +25,6 @@ export const ZHSScript = defineScript({
await study(setting || defaultSetting().video);
}
},
{
name: '学分课视频脚本',
/** 学分共享课(翻转课) */
url: '**zhihuishu.com/aidedteaching/sourceLearning/**',
async onload (setting = store.setting.zhs.video) {
await sleep(5000);
setting.creditStudy = true;
// 智慧树视频学习
logger('info', '开始智慧树学分课视频学习');
await creditStudy(setting || defaultSetting().video);
}
},
{
name: '共享课作业脚本',
url: '**zhihuishu.com/stuExamWeb.html#/webExamList/dohomework**',
Expand All @@ -46,10 +35,37 @@ export const ZHSScript = defineScript({
confirm('未设置题库配置!请在设置面板设置后刷新重试!');
} else {
/** 运行作业脚本 */
await work(setting);
await workOrExam(setting, 'work');
}
}
},
{
name: '共享课考试脚本',
url: '**zhihuishu.com/stuExamWeb.html#/webExamList/doexamination*',
async onload (setting = store.setting.zhs.exam) {
await sleep(5000);
if (store.setting.answererWrappers.length === 0) {
logger('error', '未设置题库配置!');
confirm('未设置题库配置!请在设置面板设置后刷新重试!');
} else {
/** 运行考试脚本 */
await workOrExam(setting, 'exam');
}
}
},
{
name: '学分课视频脚本',
/** 学分共享课(翻转课) */
url: '**zhihuishu.com/aidedteaching/sourceLearning/**',
async onload (setting = store.setting.zhs.video) {
await sleep(5000);
setting.creditStudy = true;
// 智慧树视频学习
logger('info', '开始智慧树学分课视频学习');
await creditStudy(setting || defaultSetting().video);
}
},

{
name: '学分课作业脚本',
url: '**zhihuishu.com/atHomeworkExam/stu/homeworkQ/exerciseList**',
Expand All @@ -64,6 +80,7 @@ export const ZHSScript = defineScript({
}
}
}

],
panels: [
{
Expand All @@ -84,7 +101,6 @@ export const ZHSScript = defineScript({
createNote(
'进入 视频设置面板 可以调整视频设置',
'点击右侧 作业考试 可以使用作业功能',
'注意: 考试功能暂未开放',
'5秒后自动开始播放视频...'
),
children: [
Expand All @@ -96,37 +112,45 @@ export const ZHSScript = defineScript({
]
},
{
name: '学分课视频助手',
/** 学分共享课(翻转课) */
url: '**zhihuishu.com/aidedteaching/sourceLearning/**',
el: () =>
createNote('进入 视频设置面板 可以调整视频设置', '学分课默认1倍速, 不可修改', '5秒后自动开始播放视频...'),
name: '共享课作业助手',
url: '**zhihuishu.com/stuExamWeb.html#/webExamList/dohomework**',
el: () => createNote('进入 作业设置面板 可以调整作业设置', '5秒后自动开始作业...'),
children: [
{
name: '学习设置',
el: () => StudySettingPanel
name: '作业设置',
el: () => WorkSettingPanel
},
createTerminalPanel()
createTerminalPanel(),
createSearchResultPanel()
]
},
{
name: '作业考试助手',
url: '**zhihuishu.com/stuExamWeb.html#/webExamList?**',
el: () => createNote('点击任意作业可以使用作业功能', '注意: 考试功能暂未开放')
},
{
name: '共享课作业助手',
url: '**zhihuishu.com/stuExamWeb.html#/webExamList/dohomework**',
el: () => createNote('进入 作业设置面板 可以调整作业设置', '5秒后自动开始作业...'),
name: '共享课考试助手',
url: '**zhihuishu.com/stuExamWeb.html#/webExamList/doexamination*',
el: () => createNote('进入 考试设置面板 可以调整考试设置', '5秒后自动开始作业...'),
children: [
{
name: '作业设置',
el: () => WorkSettingPanel
name: '考试设置',
el: () => ExamSettingPanel
},
createTerminalPanel(),
createSearchResultPanel()
]
},
{
name: '学分课视频助手',
/** 学分共享课(翻转课) */
url: '**zhihuishu.com/aidedteaching/sourceLearning/**',
el: () =>
createNote('进入 视频设置面板 可以调整视频设置', '学分课默认1倍速, 不可修改', '5秒后自动开始播放视频...'),
children: [
{
name: '学习设置',
el: () => StudySettingPanel
},
createTerminalPanel()
]
},
{
name: '学分课作业助手',
url: '**zhihuishu.com/atHomeworkExam/stu/homeworkQ/exerciseList**',
Expand All @@ -139,6 +163,11 @@ export const ZHSScript = defineScript({
createTerminalPanel(),
createSearchResultPanel()
]
},
{
name: '作业考试助手',
url: '**zhihuishu.com/stuExamWeb.html#/webExamList?**',
el: () => createNote('点击任意作业可以使用作业功能', '考试可能不稳定,请大家预留其他搜题方式')
}
]
});
Loading

0 comments on commit 5ba2022

Please sign in to comment.