Skip to content

Commit

Permalink
update Fill Question
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonYew-SWPU committed Jan 1, 2024
1 parent 6c1f1af commit 98f1858
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## 作用
隐藏/显示作业详情页的答案,用于自己期末做题测试复习效果。思考之后再看正确答案。
<div align="center">
<img src="pics/ShowEffect1.gif" alt="效果演示" width="300">
<img src="https://cdn.jsdelivr.net/gh/LeonYew-SWPU/HideShowChaoXingAnswer@main/pics/ShowEffect1.gif" alt="效果演示" width="300">
</div>

## 使用方法
Expand All @@ -14,6 +14,11 @@
[📦v1.0 点我安装⬇️(脚本猫)](https://scriptcat.org/scripts/code/1460/%E8%B6%85%E6%98%9F%E9%9A%90%E8%97%8F%E6%98%BE%E7%A4%BA%E6%AD%A3%E7%A1%AE%E7%AD%94%E6%A1%88.user.js)

## 没人想看的更新日志
**Version: 1.2.5**
1. 修复了填空题不支持隐藏的BUG
2. 修复了GreasyFork上看不到README的GIF效果图的BUG
3. 引发了新的“特性”:填空题的div隐藏后不会保持原来的答题框大小,会造成题目位移。

**Version: 1.2.4**
1. 修改了README.MD的效果图片
2. 修改了js脚本中的版本号
Expand Down
26 changes: 20 additions & 6 deletions hideShowCXAnwser.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name 超星隐藏显示正确答案
// @namespace http://tampermonkey.net/
// @version v1.2.4
// @version v1.2.5
// @description 通过单击键盘左上方的~/`/·键来隐藏/显示正确答案,用于期末复习
// @author LeonYew-SWPU
// @match https://mooc1.chaoxing.com/mooc-ans/*
Expand All @@ -20,12 +20,16 @@

// 初始化,获取元素
var answersWindow = document.getElementsByClassName('mark_answer'); // 获取答案框div
var answers = document.getElementsByClassName('mark_key clearfix'); // 获取答案文字div
var answersChoice = document.getElementsByClassName('mark_key clearfix'); // 获取答案选择题div
var answerFill = {
'colorDeep': document.getElementsByClassName('mark_fill colorDeep'), // 获取填空题我的答案
'colorGreen': document.getElementsByClassName('mark_fill colorGreen') // 填空题正确答案
}
var answerStatuses = document.getElementsByClassName('mark_score'); // 获取答案状态div(对错+分数)
var lightGrey = '#f9f9f9'; // 浅灰色
var isHidden = false; // 答案隐藏指标

// 遍历答案框div,添加遮罩层
// 遍历答案框div,添加遮罩层,初始化Status
for (var i = 0; i < answersWindow.length; i++) {
addCover(answersWindow[i]);
}
Expand All @@ -41,13 +45,23 @@
isHidden = !isHidden;
// 遍历答案div
// 如果遍历窗口div的话,遇到简答题会找不到answers[i].style,也找不到answerStatuses[i].style
for (var i = 0; i < answers.length; i++) {
answers[i].style.display = (isHidden) ? 'none' : 'block'; // 隐藏答案文字
answersWindow[i].style.backgroundColor = (isHidden) ? lightGrey : ''; // 背景调灰
for (var i = 0; i < answersWindow.length; i++) {
// 每个answerWindow一定有的元素
answersWindow[i].getElementsByClassName('cover')[0].style.display = (isHidden) ? 'block' : 'none'; // 显示遮罩层
answersWindow[i].getElementsByClassName('icon-hide')[0].style.display = (isHidden) ? 'none' : 'inline'; // 隐藏眼睛图标
answersWindow[i].getElementsByClassName('icon-eye')[0].style.display = (isHidden) ? 'inline' : 'none'; // 显示闭眼图标
answersWindow[i].style.backgroundColor = (isHidden) ? lightGrey : ''; // 背景调灰
answerStatuses[i].style.display = (isHidden) ? 'none' : 'block'; // 隐藏答案状态div

// 每个answerWindow可能有的元素:选择题答案
if (answersChoice[i]) {
answersChoice[i].style.display = (isHidden) ? 'none' : 'block'; // 隐藏选择题答案
}
// 每个answerWindow可能有的元素:选择题答案、填空答案
if (answerFill.colorDeep[i]) {
answerFill.colorDeep[i].style.display = (isHidden) ? 'none' : 'block'; // 隐藏填空题我的答案
answerFill.colorGreen[i].style.display = (isHidden) ? 'none' : 'block'; // 隐藏填空题正确答案
}

}
// 后台提示
Expand Down

0 comments on commit 98f1858

Please sign in to comment.