-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathannotation.html
146 lines (124 loc) · 4.46 KB
/
annotation.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
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<style type="text/css">
input {
height: 50px;
}
* {
font-size: 20px;
}
button {
margin: 10px;
}
</style>
<body>
<!-- 1. The <iframe> (and video player) will replace this <div> tag. -->
<form onsubmit="handleChangeVideo(event)">
Ссылка на видео:
<div>
<input type="text" style="height: 2em; width: 40em;" id="video_url" placeholder="https://www.youtube.com/watch?v=3HgApLXW-9w">
</div>
<button type="submit">Начать разметку</button>
</form>
<div>
<button onclick="player.setPlaybackRate(0.25)">Скорость 0.25</button>
<button onclick="player.setPlaybackRate(0.5)">Скорость 0.5</button>
<button onclick="player.setPlaybackRate(0.75)">Скорость 0.75</button>
<button onclick="player.setPlaybackRate(1)">Скорость 1</button>
<button onclick="player.setPlaybackRate(1.25)">Скорость 1.25</button>
</div>
<div id="player"></div>
<br>
Размечаемое слово:
<input type="text" onkeydown="handleKeydown(event)" value="НАЧАЛО" style="height: 2em;">
<div style="border: 4px solid green; padding: 10px; border-radius: 4px;">
Enter нужно нажимать ровно между словами. Если не успеваете дописать слово - ровно между словами нажмите
Escape (видео поставится на паузу).
</div>
<div id="annotation"></div>
<button onclick="handleCopyResult(event)">Скопировать результат</button>
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
var videoId;
var words = [];
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: '360',
width: '640',
videoId: '_sf1pQQktmM',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function handleChangeVideo(event) {
event.preventDefault();
videoId = new URL(document.getElementById('video_url').value).searchParams.get('v');
if (videoId === null) {
videoId = new URL(document.getElementById('video_url').value).pathname.slice(1);
}
if (videoId) {
player.loadVideoById({videoId});
words = [];
} else {
alert('Неправильная ссылка: ' + document.getElementById('video_url'));
}
}
function handleCopyResult(event) {
navigator.clipboard.writeText(JSON.stringify({
"video": videoId,
words
}));
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
event.target.playVideo();
}
// 5. The API calls this function when the player's state changes.
// The function indicates that when playing a video (state=1),
// the player should play for six seconds and then stop.
var done = false;
var lastTimestamp = 0;
function addWord(word) {
if (word) {
var newTimestamp = Math.round(player.getCurrentTime() * 10) / 10;
words.push({
word: word,
startTime: lastTimestamp,
endTime: newTimestamp
});
document.getElementById('annotation').innerText = JSON.stringify(words);
}
lastTimestamp = newTimestamp;
}
function onPlayerStateChange(event) {
if (event.data == YT.PlayerState.PAUSED) {
var word = prompt('Какое слово?');
addWord(word);
}
}
function stopVideo() {
player.stopVideo();
}
function handleKeydown(event) {
if (event.keyCode == 13) {
var word = event.target.value;
addWord(word);
event.target.value = '';
}
if (event.keyCode == 27) {
player.pauseVideo();
}
}
</script>
</body>
</html>