-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
193 lines (171 loc) · 3.68 KB
/
index.js
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
console.clear()
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
var playerSize = 600
var aspect = 640/360
let videoID = 'cXgA1d_E-jY'
let filename;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
height: playerSize,
width: playerSize * aspect,
videoId: videoID,
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event) {
event.target.seekTo(0)
event.target.playVideo();
}
function onPlayerStateChange(event) {
}
function stopVideo() {
player.stopVideo();
}
let prevtime = 0;
function getYTTime() {
return player.getCurrentTime().toFixed(2)
}
let d = { "youtubeID":videoID,
"formatArray":[] }
var editor = ace.edit("editor");
editor.setTheme("ace/theme/twilight");
// editor.session.setMode("ace/mode/javascript");
editor.setOptions({
enableBasicAutocompletion: false
});
// change
var recordPos = false
editor.getSession().on('change', function(e) {
if(recordPos) {
opCursor()
recordPos = false
}
console.log(e)
if (e.action === 'insert') {
if (e.lines.length > 1 || e.lines[0].length > 1){
opBlock(e.lines)
recordPos = true
} else {
opCharacter(e.lines[0])
}
} else if (e.action === 'remove') {
opBackspace()
}
//console.log(d)
});
// down
editor.commands.addCommand({
name: "down-arrow",
exec: function(editor, args) {
editor.navigateDown(args.times);
opCursor()
},
bindKey: {mac: "Down", win: "Down"}
})
// up
editor.commands.addCommand({
name: "up-arrow",
exec: function(editor, args) {
editor.navigateUp(args.times);
opCursor()
},
bindKey: {mac: "Up", win: "Up"}
})
// left
editor.commands.addCommand({
name: "left-arrow",
exec: function(editor, args) {
editor.navigateLeft(args.times);
opCursor()
},
bindKey: {mac: "Left", win: "Left"}
})
// right
editor.commands.addCommand({
name: "right-arrow",
exec: function(editor, args) {
editor.navigateRight(args.times);
opCursor()
},
bindKey: {mac: "Right", win: "Right"}
})
$('#editor').click(function() {
opCursor()
})
$('#add-file').click(() => {
$("#modal").show()
})
$('#submit').click(function() {
opAddFile($("#file-name-input").val())
$("#modal").hide()
})
function opCharacter(ch) {
d.formatArray.push({
"op": "ch",
"ts": getYTTime(),
"ch": ch
})
}
function opBlock(lines) {
let blockStr = ""
lines.forEach((line, i) => {
blockStr += line
if (i !== lines.length-1) {
blockStr += '\n'
}
})
d.formatArray.push({
"op": "block",
"ts": getYTTime(),
"block": blockStr
})
}
function opCursor() {
let pos = editor.getCursorPosition()
console.log(filename)
d.formatArray.push({
"op": "cur",
"ts": getYTTime(),
"pos": [pos.row, pos.column],
"file": filename
})
console.log(JSON.stringify(d.formatArray))
}
function opBackspace() {
d.formatArray.push({
"op": "bck",
"ts": getYTTime(),
})
}
function opAddFile(name) {
d.formatArray.push({
"op": "adf",
"ts": getYTTime(),
"file": name
})
filename=name
}
$("#save-file").click(() => {
save(filename + ".json", JSON.stringify(d))
})
function save(filename, data) {
var blob = new Blob([data], {type: 'text/csv'});
if(window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, filename);
}
else{
var elem = window.document.createElement('a');
elem.href = window.URL.createObjectURL(blob);
elem.download = filename;
document.body.appendChild(elem);
elem.click();
document.body.removeChild(elem);
}
}