Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
东方怂天
cxmooc-tools
提交
17209aa5
C
cxmooc-tools
项目概览
东方怂天
/
cxmooc-tools
通知
11
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cxmooc-tools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
17209aa5
编写于
6月 21, 2018
作者:
C
CodFrm
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
从本地题库检索 #27
上级
57963777
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
65 addition
and
5 deletion
+65
-5
src/cxmooc-tools/import.js
src/cxmooc-tools/import.js
+1
-1
src/cxmooc-tools/topic.js
src/cxmooc-tools/topic.js
+64
-4
未找到文件。
src/cxmooc-tools/import.js
浏览文件 @
17209aa5
...
...
@@ -24,7 +24,7 @@ document.getElementById('test').onclick = function () {
console
.
log
(
reg
);
var
str
=
document
.
getElementById
(
'
content
'
).
value
;
var
arr
=
reg
.
exec
(
str
);
if
(
arr
.
length
>
0
)
{
if
(
arr
!=
null
)
{
document
.
getElementById
(
'
result
'
).
innerHTML
=
'
匹配内容:<br />
'
+
arr
[
0
];
document
.
getElementById
(
'
result
'
).
innerHTML
+=
'
<br /><br /><span style="color:red;">匹配答案:
'
+
(
arr
.
length
>=
2
?
arr
[
1
]
:
''
)
+
'
</span>
'
;
}
...
...
src/cxmooc-tools/topic.js
浏览文件 @
17209aa5
...
...
@@ -15,7 +15,7 @@ module.exports = function (_this, elLogo, index, over) {
auto
.
onclick
=
function
()
{
//进入下一个
var
config
=
JSON
.
parse
(
localStorage
[
'
config
'
]);
if
(
!
config
[
'
auto
'
])
{
if
(
!
config
[
'
auto
'
])
{
nextTask
();
}
setTimeout
(
function
()
{
...
...
@@ -29,7 +29,6 @@ module.exports = function (_this, elLogo, index, over) {
auto
.
id
=
'
action-btn
'
;
elLogo
.
appendChild
(
auto
);
auto
.
onclick
=
function
()
{
console
.
log
(
'
点击......
'
);
var
topicList
=
topicDoc
.
getElementsByClassName
(
'
Zy_TItle
'
);
var
topic
=
[];
for
(
let
i
=
0
;
i
<
topicList
.
length
;
i
++
)
{
...
...
@@ -264,6 +263,7 @@ module.exports = function (_this, elLogo, index, over) {
function
fillIn
(
id
,
result
)
{
var
topicEl
=
topicDoc
.
getElementById
(
id
);
var
topicMsg
=
getTopicMsg
(
topicEl
);
var
prompt
=
topicEl
.
nextSibling
.
nextSibling
.
getElementsByClassName
(
'
prompt
'
);
if
(
prompt
.
length
<=
0
)
{
prompt
=
document
.
createElement
(
'
div
'
);
...
...
@@ -276,8 +276,43 @@ module.exports = function (_this, elLogo, index, over) {
}
var
options
=
topicEl
.
nextSibling
.
nextSibling
.
getElementsByTagName
(
'
li
'
);
if
(
result
.
length
<=
0
)
{
//
无答案,检索配置有没有设置随机答案....
//
没有在线上检索到答案,先在检索本地题库
var
rand
=
document
.
head
.
getAttribute
(
'
rand-answer
'
);
//从本地题库读取内容
var
localTopic
=
getLocalTopic
(
topicMsg
.
topic
);
if
(
localTopic
!=
undefined
)
{
//检索到题目了
var
tmpResult
=
{
correct
:
[]
};
tmpResult
.
type
=
topicMsg
.
type
;
if
(
tmpResult
.
type
==
3
)
{
//判断题
tmpResult
.
correct
.
push
({
content
:
(
localTopic
.
answer
==
'
√
'
?
true
:
false
)
});
}
else
if
(
tmpResult
.
type
<=
2
)
{
//单/多选
var
reg
=
/
[\w]
/g
;
var
match
=
localTopic
.
answer
.
match
(
reg
);
for
(
var
i
=
0
;
i
<
match
.
length
;
i
++
)
{
tmpResult
.
correct
.
push
({
option
:
match
[
i
]
});
}
}
else
if
(
tmpResult
.
type
==
4
)
{
//填空题,暂时空一下
}
if
(
tmpResult
.
correct
.
length
>
0
)
{
result
.
push
(
tmpResult
);
console
.
log
(
tmpResult
);
prompt
.
innerHTML
=
"
成功的从本地题库搜索到答案:<br />
"
+
localTopic
.
content
+
"
<br/>答案:
"
+
localTopic
.
answer
+
"
<br/>
"
;
}
}
}
if
(
result
.
length
<=
0
)
{
//无答案,检索配置有没有设置随机答案....
if
(
rand
==
'
false
'
)
{
prompt
.
innerHTML
=
"
没有从题库中获取到相应记录
"
;
return
;
...
...
@@ -288,7 +323,7 @@ module.exports = function (_this, elLogo, index, over) {
var
tmpResult
=
{
correct
:
[]
};
tmpResult
.
type
=
switchTopicType
(
common
.
substrEx
(
topicEl
.
innerText
,
'
【
'
,
'
】
'
))
;
tmpResult
.
type
=
topicMsg
.
type
;
var
d
=
Math
.
floor
(
Math
.
random
()
*
10
+
1
);
//随机生成答案,有些混乱了....
for
(
let
n
=
0
;
n
<
options
.
length
;
n
++
)
{
...
...
@@ -355,9 +390,16 @@ module.exports = function (_this, elLogo, index, over) {
break
;
}
else
if
(
result
.
type
<=
2
)
{
optionsContent
=
removeHTML
(
options
[
n
].
querySelector
(
'
.after
'
).
innerHTML
);
var
option
=
options
[
n
].
querySelector
(
"
[type='radio']
"
).
value
;
//如果内容是空的,就看选项的
if
(
result
.
correct
[
i
].
content
==
optionsContent
)
{
prompt
.
innerHTML
+=
optionsContent
+
"
"
;
options
[
n
].
querySelector
(
'
.after
'
).
click
();
var
option
=
options
[
n
].
querySelector
(
"
[type='radio']
"
).
value
;
}
else
if
(
result
.
correct
[
i
].
option
==
option
)
{
prompt
.
innerHTML
+=
optionsContent
+
"
"
;
options
[
n
].
querySelector
(
'
.after
'
).
click
();
var
option
=
options
[
n
].
querySelector
(
"
[type='radio']
"
).
value
;
}
}
else
if
(
result
.
type
==
4
)
{
optionsContent
=
common
.
substrEx
(
options
[
n
].
innerHTML
,
"
第
"
,
"
空
"
);
...
...
@@ -370,6 +412,24 @@ module.exports = function (_this, elLogo, index, over) {
}
}
/**
* 获取本地题库中的信息
* @param {*} topic
*/
function
getLocalTopic
(
topic
)
{
var
reg
=
new
RegExp
(
common
.
dealRegx
(
localStorage
[
'
topic_regx
'
],
topic
));
console
.
log
(
reg
);
var
str
=
localStorage
[
'
topics
'
];
var
arr
=
reg
.
exec
(
str
);
if
(
arr
!=
null
)
{
return
{
content
:
arr
[
0
],
answer
:
arr
.
length
>=
2
?
arr
[
1
]
:
''
};
}
return
;
}
/**
* 获取题目信息
* @param {*} elTopic
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录