Skip to content

Commit

Permalink
[Add] 支持听说同步
Browse files Browse the repository at this point in the history
[Upd] 优化部分逻辑
  • Loading branch information
ravizhan committed Jul 28, 2024
1 parent bc56e12 commit 2ec1aa4
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 27 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "xiyou_monkey",
"private": true,
"version": "0.0.4",
"version": "0.0.5",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
52 changes: 52 additions & 0 deletions src/components/written.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<div class="side-blank">
<el-button
@click="answerDialogVisible=true"
>
参考答案
</el-button>
<el-dialog
v-model="answerDialogVisible"
title="参考答案"
width="40%"
draggable
align-center
>
<div
class="div-style"
>
{{ answer }}
</div>
</el-dialog>
</div>
</template>

<script>
export default {
data() {
return {
answerDialogVisible: false,
}
},
computed: {
answer() {
return localStorage.getItem(window.location.hash.split("&")[0].split("id=")[1])
}
}
}
</script>

<style scoped>
.side-blank {
display: flex;
flex-direction: column;
margin-top: 10px;
}
.div-style {
white-space: pre-line;
overflow: auto;
height: 300px;
color: black;
}
</style>
16 changes: 15 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {processResponse} from "./scripts/parse.js";
import {show_answer_for_paper} from "./scripts/paper.js";
import {show_setting_for_accent} from "./scripts/accent.js";
import {show_answer_for_written} from "./scripts/written.js";
import {show_answer_for_chooseTranslate, show_setting_for_word} from "./scripts/words.js";
import "element-plus/dist/index.css"
import { ElNotification } from "element-plus"
Expand All @@ -20,6 +21,9 @@ history.pushState = function (...arg) {
if (arg[2].includes("accentDetail")) {
show_setting_for_accent();
}
if (arg[2].includes("writtenDetail")) {
show_answer_for_written();
}
return old.call(this, ...arg);
}

Expand All @@ -40,6 +44,9 @@ if (hash.includes("paperDetail")) {
if (hash.includes("accentDetail")) {
show_setting_for_accent();
}
if (hash.includes("writtenDetail")) {
show_answer_for_written();
}

// XHR劫持
const originOpen = XMLHttpRequest.prototype.open;
Expand All @@ -54,7 +61,14 @@ XMLHttpRequest.prototype.send = function (data) {
if (this._url === "https://app.xiyouyingyu.com/paper/getPaperGroupById") {
this.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
localStorage.setItem(data.split("groupId=")[1], processResponse(JSON.parse(this.responseText)["data"]));
localStorage.setItem(data.split("groupId=")[1], processResponse(JSON.parse(this.responseText)["data"],1));
}
});
}
if (this._url === "https://app.xiyouyingyu.com/write/selectByPrimaryKey") {
this.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
localStorage.setItem(data.split("examId=")[1], processResponse(JSON.parse(this.responseText)["data"],2));
}
});
}
Expand Down
65 changes: 41 additions & 24 deletions src/scripts/parse.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
export function processResponse(res) {
export function processResponse(res,mode) {
let answer = "";
for (let i of res) {
if (!(i["questionsName"].includes("模仿朗读"))) {
for (let question of i["smallList"]) {
for (let process of question["processList"]) {
if (process["name"] === "录音作答") {
let question_text = JSON.parse(process["content"])["showTxt"]
let question_answer = String(process["oralTypeModel"]["answerTxt"])
question_answer = question_answer.replaceAll("<blockquote>", "")
question_answer = question_answer.replaceAll("</blockquote>", "")
answer += `\n${question_text}\n\n${question_answer}\n`
if (mode === 1) {
for (let i of res) {
console.log(i)
if (i["name"] !== "模仿朗读" || i["name"] !== "单词或句子朗读") {
for (let question of i["smallList"]) {
for (let process of question["processList"]) {
if (process["name"] === "录音作答") {
let question_text = JSON.parse(process["content"])["showTxt"]
let question_answer = String(process["oralTypeModel"]["answerTxt"])
question_answer = question_answer.replaceAll("<blockquote>", "")
question_answer = question_answer.replaceAll("</blockquote>", "")
answer += `\n${question_text}\n\n${question_answer}\n`
}
if (process["name"] === "选项勾选") {
let data = JSON.parse(process["content"])["textModelList"]
for (let a of data) {
if (a["showType"] === "3" || a["showType"] === "4") {
for (let b of JSON.parse(a["showTxt"])) {
let question_text = b["text"]
let question_answer = b["answer"]
answer += `\n${question_text}\n\n${question_answer}\n`
}
}
if (a["showType"] === "5") {
for (let b of JSON.parse(a["showTxt"])) {
let question_text = b["text"]
let question_answer = b["answers"][0]
answer += `\n${question_text}\n\n${question_answer}\n`
}
}
}
}
}
}
}
}
if (i["name"].includes("重读训练")) {
for (let question of i["smallList"]) {
for (let process of question["processList"]) {
if (process["name"] === "选项勾选") {
let data = JSON.parse(process["content"])["textModelList"]
for (let a of data) {
if (a["showType"] === "3") {
let question_text = JSON.parse(a["showTxt"])[0]["text"]
let question_answer = JSON.parse(a["showTxt"])[0]["answer"]
answer += `\n${question_text}\n\n${question_answer}\n`
}
}
}
}
if (mode === 2) {
for (let i of res["titleList"]) {
if (["单项选择","重点词汇听写"].includes(i["questionsTypeName"])) {
for (let question of i["writtenList"]) {
let question_text = question["libList"][0]["titleType"]["text"]
let question_answer = question["libList"][0]["titleType"]["answer"]
answer += `\n${question_text}\n\n${question_answer}\n`
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/scripts/written.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {createApp} from "vue";
import written from "../components/written.vue";
import ElementPlus from "element-plus";

export function show_answer_for_written() {
if (localStorage.getItem(window.location.hash.split("&")[0].split("id=")[1]) === null) {
alert("未找到答案,请重新进入当前页面");
} else {
setTimeout(() => {
createApp(written).use(ElementPlus).mount(
(() => {
const app = document.createElement("div");
document.querySelector("#app > div > div.card > div.main").appendChild(app)
return app;
})(),
);
}, 1000)
}
}
2 changes: 1 addition & 1 deletion vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig({
namespace: "ravizhan@hotmail.com",
name: "西柚英语辅助脚本",
author: "Ravi",
version: "0.0.4",
version: "0.0.5",
description: "一键修改分数,一键获取答案。更多功能正在添加~",
match: [
"https://student.xiyouyingyu.com/*",
Expand Down

0 comments on commit 2ec1aa4

Please sign in to comment.