-
Notifications
You must be signed in to change notification settings - Fork 3
/
moecard.html
277 lines (214 loc) · 10.3 KB
/
moecard.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<!DOCTYPE html>
<head>
<meta charset="utf-8">
<title>萌典閃卡</title>
<style type="text/css">
.simple {
text-decoration: none;
/* text-transform: none; */
}
</style>
<script src="javascript/jquery-1.9.1.min.js"></script>
<link rel="stylesheet" type="text/css" class="ui" href="css/semantic.min.css">
</head>
<body>
<script type="text/javascript">
var bottonFunNow, objNow;
var flipped = 0;
// var ansBig = '<div>歡迎使用活潑的萌典閃卡!<br/>請按Enter鍵開始。<br />手機橫放畫面較佳。</div><div></div>';
// var ansQueqe = [ansBig];
var ansQueqe = [];
var start = 0; var faceNow = 0;
var card = "單面"; var mode = "閃卡模式";
var faceBack = "漢英";
var indexM; // 之後還可加上用location.hash來給字庫的功能
var example = {
"body" : ['身體', '汗毛','皮膚','肌肉','筋','骨','淋巴','血管','血','頭', '頭髮', '頭皮', '眉毛','眼睛','鼻子','耳朵','聽小骨','身蝸', '口','嘴巴','牙齒','門牙','犬齒','臼齒','智齒','舌頭','牙齦','喉嚨','氣管','心臟','心包','肺', '乳房','食道', '肩膀','橫隔膜','胃','脾臟','胰臟','小腸','大腸','闌尾', '肝臟', '膽', '腎臟', '腎上腺', '甲狀腺', '攝護腺', '皮脂腺', '手肘', '上臂', '下臂','手掌','手心','掌紋', '手指', '三頭肌', '二頭肌', '膀胱','肛門', '生殖器', '子宮', '陽具', '陰道', '陰蒂', '屁股','大腿','膝蓋','腳','腳踝','腳底板','腳掌', '腳指','經絡','穴道','神經','神經系統','循環系統','消化系統','排泄系統','汗水','眼淚','鼻涕','腦', '下視丘','前額葉','海馬迴','小腦','脊椎骨','顱骨','腦下垂體','生命','死亡','運動','吃','大便','尿尿', '睡眠','成長','老化'],
"relation" : ['媽媽','爸爸','爺爺','奶奶','外婆','外公', '祖先', '親戚','兄','弟','姐','妹', '姑', '嫂','叔','伯','姨','舅', '甥','媳','弟媳', '夫妻','兒子','女兒','孫子','孫女','外孫女','外孫', '後代','同宗', '同鄉','同居人','族人','青梅竹馬', '玩伴', '朋友', '夥伴','生死之交','患難之交','手帕交','同黨','同事','上司','下屬','隨從','跟班','領袖','競爭者','敵人','對頭','死敵','仇人','恩人','主人','奴隸','僕人','代議士','公僕','照顧者','剝削者','工具'],
"home" : ['家人','房屋','廚房','臥室','書房','教室','客廳','飯廳','庭院','公寓','公共空間','地下室','睡眠','飲食','運動','搬家','水管','電線','瓦斯','天然氣','綠建築','太陽能','風能','火力發電','核能','房租','房貸','寄人籬下','流浪','遊民'],
"food" : ['稻米','在來米','小麥','地瓜','芋頭','馬零薯','玉米','蕃茄','蔥','薑','蒜','韭','艾草','川七','昭和草','地瓜葉','佛手瓜','南瓜','絲瓜','香瓜','小黃瓜','大黃瓜','西瓜','哈蜜瓜','火龍果','奇異果','香蕉','芭樂','柳丁','鳳梨','芒果','文旦','連霧','香茅','香椿','桂枝','甘草'],
"chemistry" : ['氫','氦','鋰','鈹','硼','碳','氮','氧','氟','氖','鈉','鎂','鋁','矽','磷','硫','氯','氬','鉀','鈣','錳','鐵礦','鈷','鎳','鋅','砷','硒','銀','金','汞','碘','鈽','鈾','燃燒','化合','電解','蒸餾','聚合','乾餾', '碳酸氫納', '氯化納'],
"math" : ['計數','計算','加法','減法','乘法','除法','畫畫','圓','三角形','正方形','長方形','對稱','代數','分母','演算法','計算機','機率','統計','變數','函數','同構','指數','對數','三角函數','微積分','無限', '抽象', '投影', '垂直','正交','向量','特徵值','邏輯']
};
function pickone(list) {
return list[Math.floor(Math.random() * list.length)];
}
function clearStr (str){
return str.split('~').join('').split('`').join('').split('(S)').join('');
}
function toTower(word) {
// console.log(word.zh);
var tower = $('#tower').html(); tower = tower.substr(1, tower.length-2);
$('#tower').html('[' + word.zh.split('space')+ ',' + tower +']'); // 加入字塔中
}
function innerBig () {
var face1, face2, faceZh, faceEn;
var data;
if (flipped) {
return;
}
else {
if (ansQueqe[0]) {
if (card == "雙面") data = ansQueqe[0];
if (card == "單面") {toTower(ansQueqe[0]); data = ansQueqe.shift()}
faceZh = "<div><a class = 'simple blue' href = "+"'https://www.moedict.tw/#"+data.zh+"' target = 'new'>"+data.zh+"</a></div>";
faceEn = "<div>"+data.en+"</div>";
switch (faceBack) {
case "漢英":
face1 = faceZh; face2 = faceEn; break;
case "英漢":
face1 = faceEn; face2 = faceZh; break;
}
if (card == "雙面") {
$('#bigans').show().children("hr").hide();
if (faceNow == 0) $('#bigans').html(face1);
if (faceNow == 1) $('#bigans').html(face2);
}
if (card == "單面") $('#bigans').html(face1 + '<hr>'+face2);
}
else {
document.getElementById('bigans').innerHTML ="<div class = 'cyan'>萌典讀取中...請3秒後再按一次Enter</div>";
}
}
}
function core (obj) {
if (!indexM) {console.log('索引尚未讀取'); return};
var newSrc = $("#source").val();
var wordNow = pickone(indexM); //indexCore
var wordNowD = decodeURIComponent(wordNow.replace(/\+/g, " ")); // 國字
console.log(wordNowD);
$.getJSON("https://www.moedict.tw/a/"+wordNowD+".json", function(x){
var enWord, zhPrononce; // 英文, 注音
zhPrononce = x.h[0].b;
try {
enWord = x.translation.English[0];
if (enWord.substr(0,8) == 'same as `'){
console.log("發現"+enWord+"重新取得英文翻譯")
var nextWord = decodeURIComponent(enWord.split('same as `')[1].split('~')[0].replace(/\+/g, " "));
enWord = $.getJSON("https://www.moedict.tw/a/"+nextWord+".json", function(x) {return x.translation.English[0]});
}
if (enWord.substr(0,8) == 'same as `'){
console.log("發現"+enWord+"重新取得英文翻譯")
var nextWord = decodeURIComponent(enWord.split('same as `')[1].split('~')[0].replace(/\+/g, " "));
enWord = $.getJSON("https://www.moedict.tw/a/"+nextWord+".json", function(x) {return x.translation.English[0]});
}
console.log(enWord);
ansQueqe.push({"zh":wordNowD, "en":enWord});
}
catch (err) {
console.log(err+"____條目「"+wordNowD+"」暫無英文翻譯");
core(obj); // 條目無英文對照就換一張
}
});
}
function showAndCore (obj) { // 預先讀好下次要顯示的資料,使用者按鍵時就不用等
innerBig(); faceNow++;
if (card != "雙面" || faceNow == 2) {
core(obj);core(obj);
if (faceNow == 2) {toTower(ansQueqe[0]); ansQueqe.shift()}
faceNow = 0;
}
}
// goal: 使用者可設定: 「是否加注音?」「存下顯示過的成為字庫」
function runCode(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if (keycode == 13) { // 32:Spacebar 13:ENTER
bottonFunNow(objNow);
}
}
function doSwi(obj, doCard, doFaceBack, word, doStart, doInner){
if (confirm(word)) {
if (doCard) card = doCard;
if (doFaceBack) faceBack = doFaceBack;
start = doStart;
if (doInner) obj.innerHTML = doInner;
}
}
function swiByName (obj, name) {
core();
switch (name)
{
case "雙面" :
doSwi(obj, "單面",'', "換成單面卡?", 0, "單面"); break;
case "單面" :
doSwi(obj, "雙面",'', "換成雙面卡?", 0, "雙面"); break;
case "漢英" :
doSwi(obj, '', "英漢", "改為英漢對照?", 0, "英漢");
// ansQueqe = []; core();
break;
case "英漢" :
doSwi(obj, '', "漢英", "改為漢英對照?", 0, "漢英");
// ansQueqe = []; core();
break
case "自訂字庫" :
var newSrc = $("#source").val();
if (newSrc.substr(0,1) == '[') {
console.log('[\'' + newSrc.substr(1,newSrc.length - 2).split(/,\s*/).join('\',\'') + '\']');
indexM = eval('[\'' + newSrc.substr(1,newSrc.length - 2).split(/,\s*/).join('\',\'') + '\']');
}
if (newSrc.substr(newSrc.length-4,4) == 'json') {
$.getJSON(newSrc, function(x) {indexM = x});
}
ansQueqe = []; core(); core();
break;
default :
alert("發生錯誤");
};
}
function swi(obj) {
var data = obj.innerHTML;
swiByName (obj, data);
}
function chIndex(list) {
$("#source").val('['+list.join()+']');
indexM = list;
ansQueqe = []; core();
}
//目標:桌電 ==> Enter連閃, 按字查詢 手機&平板 ==> 右滑連閃, 按字查詢
</script>
<div style="float:right; width:20%;">
<p>範例字庫</p>
<button onclick="chIndex(example.body)">身體字庫</button>
<button onclick="chIndex(example.relation)">關係字庫</button>
<button onclick="chIndex(example.home)">居家字庫</button>
<button onclick="chIndex(example.food)">食物字庫</button>
<button onclick="chIndex(example.chemistry)">化學字庫</button>
<button onclick="chIndex(example.math)">數學字庫</button>
</div>
<button class="ui pink large button" onclick="swi(this)">單面</button>
<button class="ui pink large button" onclick="swi(this)">漢英</button>
<textarea id = "source" rows = "2" cols = "60" onchange="swiByName(this,'自訂字庫')">https://www.moedict.tw/c/index.json</textarea>
<button class="ui pink large button" onclick="swi(this)">自訂字庫</button>
<p align="center">
歡迎您參考範例的格式,自訂字庫,開一個文字檔,諸存累積
</p>
<div class="ui message blue" style="height: 50ex;">
<big id = "bigans" style="font-size: 400%; margin-left:20px;">
<div>歡迎使用活潑的萌典閃卡!<br/>請按Enter鍵開始。<br />手機橫放畫面較佳。</div>
</big>
</div>
<br />
<div id="tower">[萌]</div>
<div>
<button onclick="{
location = 'moecard.html#'+ $('#tower').html().split(/\s/).join('');
location.reload();
}">用這些字當字庫</button>
</div>
<script type="text/javascript">
if (!location.hash){
$.getJSON("https://www.moedict.tw/c/index.json", function(x) {
indexM = x; core();core();core();
});
}
else {
$('#source').val(location.hash.split('#')[1]);
swiByName(document.getElementById('source'),'自訂字庫');
}
bottonFunNow = showAndCore;
document.onkeydown = runCode;
core(); core();
</script>
</body>