forked from ZuoAoyu/Anki-Blank-Space
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_en.html
90 lines (88 loc) · 3.76 KB
/
main_en.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<!DOCTYPE html>
<html>
<head>
<title>Anki隔字挖空</title>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div class="card">
<article>
<h1>英文测试</h1>
<div id="acon">
Cats never fail to fascinate human beings. They can be friendly and affectionate towards humans, but they lead mysterious lives of their own as well. They never become submissive like dogs and horses. As a result, humans have learned to respect feline independence. Most cats remain suspicious of humans all their lives.
<div>One of the things that fascinates us most about cats is the popular belief that they have nine lives. Apparently, there is a good deal of truth in this idea. A cat's ability to survive falls is based on fact.</div>
</div>
</article>
</div>
<script>
var sen;//原来的句子
var str;//保存挖空后的字符串
var state;//控制该不该挖空
var divstate;//是否遇到div,英文状态
var wordstate;//在单词内或外,英文状态
var patt;//正则表达式
var i;
var lang = 0;//语言,1为中文,0为英语
sen = document.getElementById("acon").innerHTML;
str = "";
state = 0;//0为偶数挖空,1为奇数挖空
if (lang == 1) {
patt = /[0-9a-zA-Z\s\u3002|\uff1f|\uff01|\uff0c|\u3001|\uff1b|\uff1a|\u201c|\u201d|\u2018|\u2019|\uff08|\uff09|\u300a|\u300b|\u3008|\u3009|\u3010|\u3011|\u300e|\u300f|\u300c|\u300d|\ufe43|\ufe44|\u3014|\u3015|\u2026|\u2014|\uff5e|\ufe4f|\uffe5|\>|\<|\/|\.|\,]/;
for (i=0; i<sen.length; i++) {
if (patt.test(sen[i])) {
str += sen[i];
} else {
if (state == 1) {
str += "☐";
state = 0;
} else if (state == 0) {
str += sen[i];
state = 1;
}
}
}
} else if (lang == 0) {
divstate = 0;
wordstate = 0;
patt = /[0-9]|\s|\<|\>|\t|\n|\.|\?|\,|\{|\}|\[|\]|\!|\&|\'|\"|\:|\;|\/|\(|\)|\~|\`|\&/;
for (i=0; i<sen.length; i++) {
if (patt.test(sen[i])) {
str += sen[i];
if (sen[i] == '\<' || sen[i] == '\&') {//解决 符号问题
divstate = 1;
} else if (sen[i] == '\>' || sen[i] == '\;') {
divstate = 0;
//解决单词消失问题方案二
if (state == 1) {
state = 0;
} else if (state == 0) {
state = 1;
wordstate = 0;
}
} else if (sen[i] == ' ' || sen[i] == '\n' || sen[i] == '\t') {
if (state == 1) {
state = 0;
} else if (state == 0) {
state = 1;
wordstate = 0;
}
}
} else if (divstate == 1) {
str += sen[i];
} else if (state == 1) {
if (wordstate == 0) {
str += "☐";
wordstate = 1;
}
} else if (state == 0) {
str += sen[i];
} else {
str += sen[i];
}
}
}
document.getElementById("acon").innerHTML = str;
</script>
</body>
</html>