Skip to content

Commit

Permalink
fix(core): 更新智慧树脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
enncy committed Jun 30, 2022
1 parent 8adfede commit dc04328
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 84 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": "3.17.4",
"version": "3.17.5",
"description": "ocs - online course script 在线网络课程辅助工具",
"types": "./lib/src/core/index.d.ts",
"main": "./lib/src/core/index.js",
Expand Down
5 changes: 1 addition & 4 deletions packages/core/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,6 @@ function listenHistoryChange() {
}
</script>
<style
scoped
lang="less"
>
<style lang="less">
@import './assets/less/common.less';
</style>
99 changes: 22 additions & 77 deletions packages/core/src/script/zhs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { WorkSettingPanel } from '../../components/zhs/WorkSettingPanel';
import { defineScript } from '../../core/define.script';
import { sleep } from '../../core/utils';
import { logger } from '../../logger';
import { useContext, useSettings } from '../../store';
import { useSettings } from '../../store';
import { creditStudy, study } from './study';
import { creditWork, workOrExam } from './work';

Expand Down Expand Up @@ -91,97 +91,42 @@ export const ZHSScript = defineScript({
}
},
{
name: '文本识别脚本',
name: '文字识别脚本',
url: [
'**zhihuishu.com/stuExamWeb.html#/webExamList/dohomework**',
'**zhihuishu.com/stuExamWeb.html#/webExamList/doexamination*'
],
async onload() {
const { zhs } = useContext();
zhs.isRecognizing = true;

const interval = setInterval(() => {
const scripts = Array.from(document.querySelectorAll('script'));
for (const script of scripts) {
const params = new URLSearchParams(script.src.substring(script.src.indexOf('?') + 1));
const json = params.get('json');
if (json) {
let dtos = [];
try {
dtos = JSON.parse(JSON.parse(JSON.parse(json).data[0].data).data);
} catch {}
if (dtos.length === 0) {
try {
dtos = JSON.parse(JSON.parse(json).data[0].data).data;
} catch {}
}
try {
const questionDtos = dtos.rt.examBase.workExamParts.map((p: any) => p.questionDtos).flat();
questionDtos
.map((d: any) => {
d.eid = d.eid.replace(/\\|\/|\?|\*|"|'|<|>|\{|\}|\[|\]|:|\^|\$|!|~|`|=|\+|/g, '');
return d;
})
.forEach((d: any) => {
const desc = document
.querySelector('#anchor_' + d.eid)
?.parentNode?.parentNode?.querySelector('.subject_describe');
if (desc) desc.innerHTML = d.name;
});
zhs.isRecognizing = false;
clearInterval(interval);
break;
} catch {}
}
setTimeout(() => {
for (const div of Array.from(document.querySelectorAll('.subject_describe > div'))) {
// @ts-ignore
div.__vue__.$el.innerHTML = div.__vue__._data.shadowDom.textContent;
}
}, 3000);
}
},
{
name: '页面反反混淆功能',
url: '**zhihuishu.com/videoStudy.html**',
priority: 999,
onstart() {
name: '视频守护脚本',
url: ['**zhihuishu.com/videoStudy.html**'],
onload() {
// @ts-ignore
// eslint-disable-next-line no-extend-native
RegExp.prototype._test = RegExp.prototype.test;
const study = document.querySelector('.video-study').__vue__;
const empty = () => {};
// @ts-ignore
// eslint-disable-next-line no-extend-native
RegExp.prototype.test = function (s) {
if (this.source.includes('function') || this.source.includes('native code')) {
console.log(this.source);
return true;
}
study.checkout = empty;
// @ts-ignore
study.notTrustScript = empty;
// @ts-ignore
study.checkoutNotTrustScript = empty;
// @ts-ignore
const _videoClick = study.videoClick;
// @ts-ignore
study.videoClick = function (...args) {
args[args.length - 1] = { isTrusted: true };
// @ts-ignore
return this._test(s);
return _videoClick.apply(study, args);
};
}
},
{
name: '屏蔽视频检测脚本',
url: '**zhihuishu.com/videoStudy.html**',
onstart() {
function hookAddEventListener() {
const args = [...arguments];
const temp = args[1];
args[1] = function () {
const args2 = [...arguments];
args2[0] = new Proxy(args2[0], {
get(target: any, p: string | symbol) {
return p === 'isTrusted' ? true : target[p];
}
});
return temp(...args2);
};
// @ts-ignore
return this._addEventListener(...args);
}
if (Element.prototype.addEventListener !== hookAddEventListener) {
// @ts-ignore
Element.prototype._addEventListener = Element.prototype.addEventListener;
Element.prototype.addEventListener = hookAddEventListener;
}
}
}
],
panels: [
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export let loaded = false;
* 显示面板,检测是否存在需要运行的脚本,并执行
*/
export function start(options?: StartOptions) {
// 先创建面板元素,防止 shadow root 被自身混淆
const div = document.createElement('div');
const shadowRoot = div.attachShadow({ mode: 'closed' });
// 执行脚本
executeScripts(options?.scripts || definedScripts);

Expand All @@ -39,8 +42,7 @@ export function start(options?: StartOptions) {

/** 绑定元素 */
app = createApp(App);
const div = document.createElement('div');
const shadowRoot = div.attachShadow({ mode: 'closed' });

const style = document.createElement('style');
panel = document.createElement('div');
style.innerHTML = options?.style || '';
Expand Down

0 comments on commit dc04328

Please sign in to comment.