-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
57 lines (50 loc) · 1.21 KB
/
index.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
<body>
<script src="./diffsync.js"></script>
<script>
var t = document.createElement('textarea')
t.style.width = '100%'
t.style.height = '100%'
// work here
t.style.height = '90%'
var b = document.createElement('button')
b.innerHTML = 'make me go go'
b.onclick = function () {
function blah() {
var s = t.value
var i = Math.floor(Math.random() * s.length)
var del = Math.floor(Math.random() * Math.random() * Math.random() * 3)
s = s.slice(0, i) + String.fromCharCode(65 + Math.floor(Math.random() * 26)) + s.slice(i + del)
t.value = s
ds.on_change()
setTimeout(blah, Math.random() * 400)
}
blah()
}
document.body.append(b)
document.body.append(t)
var ds = diffsync.create_client({
// ws_url : 'ws://localhost:' + diffsync.port,
ws_url : 'wss://invisible.college:' + diffsync.port,
channel : '/wiki/god',
get_text : function () {
return t.value
},
get_range : function () {
return [t.selectionStart, t.selectionEnd]
},
on_text : function (text, range) {
t.value = text
t.setSelectionRange(range[0], range[1])
},
on_range : null
})
t.onkeyup = function () {
ds.on_change()
}
t.onpaste = function () {
setTimeout(function () {
ds.on_change()
}, 0)
}
</script>
</body>