-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenglish.js
More file actions
71 lines (62 loc) · 1.35 KB
/
english.js
File metadata and controls
71 lines (62 loc) · 1.35 KB
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
$(function(){
var myVoice = null;
var cursor = null;
$('a[href="#v"]').click(function(event){
if(myVoice == null){
myVoice = document.createElement("audio");
addWordCursor();
}
cursor = $(event.target).parent();
readCursor();
return false;
});
function readCursor(){
var text = findWords(cursor.text());
myVoice.src = "http://dict.youdao.com/dictvoice?audio=" + text +"&type=2";
myVoice.play();
}
function readNext(){
cursor = cursor.next();
readCursor();
}
function readPrev(){
cursor = cursor.prev();
readCursor();
}
function readRepeat(){
myVoice.pause();
myVoice.currentTime = 0;
myVoice.play();
}
function addWordCursor(){
$(document).keydown(function(event) {
switch(event.which) {
case 37: // left
readPrev();
break;
case 38: // up
readRepeat();
break;
case 39: // right
readNext();
break;
case 40: // down
readRepeat();
break;
default:
return true;
}
return false;
});
}
}
);
function findWords(text){
text = text.trim();
var index = text.search('[\\[/]');
if(index != -1){
text = text.substr(0,index).trim();
}
text = text.replace(/\s+/,'%2B');
return text;
}