-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
61 lines (53 loc) · 1.72 KB
/
main.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
function NewLine(key,cmd) {
if (key == undefined) {
key = ""
}
if (cmd == undefined) {
cmd = ""
}
var total = document.getElementsByClassName("line").length
var tempLine = document.createElement('div')
tempLine.className = 'line'
tempLine.id = String(total)
var ihtml = `
<input type="text" id="key" placeholder="key" value="` + String(key) + `">
<input type="text" id="cmd" placeholder="command" value="` + String(cmd) + `">
<input type="button" id="rem" value="-">
<br>
`
tempLine.innerHTML = ihtml
tempLine.children[2].onclick = function() {
tempLine.remove()
}
document.getElementById("lines").appendChild(tempLine)
}
NewLine()
document.getElementById("add").onclick = function() {
NewLine()
};
document.getElementById("del").onclick = function() {
document.getElementById("lines").lastChild.remove()
};
document.getElementById("rem").onclick = function() {
var parent = this.parentNode
document.getElementById(parent.id).remove()
};
document.getElementById("togui").onclick = function() {
document.getElementById("lines").innerHTML = ''
var inp = document.getElementById("inp").value
var lines = inp.split('\n')
for (var i = 0; i < lines.length; i++) {
var line = lines[i]
var splitted = line.split('"')
NewLine(splitted[1], splitted[3])
}
};
document.getElementById("totxt").onclick = function() {
var kids = document.getElementById("lines").children
var out = ""
for (var i = 0; i < kids.length; i++) {
var kid = kids[i]
out += 'bind "' + kid.children[0].value + '" "' + kid.children[1].value + '"\n'
}
document.getElementById("out").innerHTML = out
};