-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.html
162 lines (149 loc) · 3.18 KB
/
manage.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage commands</title>
<style>
* {
box-sizing: border-box;
}
body {
background-color: #111;
color: #fff;
font: 1.4em system-ui, sans-serif;
}
table {
width: 100%;
height: 95vh;
transition: 0.2s opacity;
}
td {
border: 1px solid #00ff6988;
border-radius: 5px;
vertical-align: top;
padding: .5em;
overflow: scroll;
min-width: 15vw;
color: #fff;
}
#heading {
height: 2em;
}
#cmdsw {
width: 12em;
}
ul {
list-style: none;
}
li {
margin-left: -20px;
padding: .5em;
background-color: #222;
margin-bottom: 5px;
border-radius: 5px;
}
textarea {
width: 100%;
height: 40vh;
resize: none;
background-color: #111;
color: #bbb;
border: none;
}
button {
padding: 10px;
border: 1px solid #00ff69;
background-color: black;
color: #fff;
border-radius: 5px;
margin-right: 20px;
}
</style>
</head>
<body>
<table id="table">
<tr id="heading">
<td colspan="2">
<h2 style="margin: 10px;">Manage custom commands</h2>
<div id="menu">
<button onclick="location='./'">« Back</button>
<button onclick="save();flash()">Save changes</button>
<button onclick="addCmd();flash()">Add command</button>
<button onclick="delCmd();flash()">Delete Selection</button>
</div>
</td>
</tr>
<tr>
<td id="cmdsw">
<ul id="cmds"></ul>
</td>
<td>
<textarea id="editor" oninput="onEdit()"></textarea>
</td>
</tr>
</table>
<style id="highlight"></style>
<script>
let data = JSON.parse(localStorage.getItem("bn-data"))
let editing = ""
function editchange() {
highlight.innerText = `#menuitem${editing}{border: 2px solid #00ff69;}`
}
function save() {
localStorage.setItem("bn-data", JSON.stringify(data))
}
function flash() {
table.style.opacity = '0'
setTimeout(() => {
table.style.opacity = '1'
}, 500)
}
function load() {
editor.value = ""
cmds.innerText = ""
Object.keys(data.brings).forEach(name => {
if (!name) return
let el = document.createElement("li")
el.innerText = name
el.id = "menuitem" + name
el.addEventListener('click', () => open(name))
document.getElementById('cmds').appendChild(el)
})
}
function onEdit() {
if (!editing) { editor.value = ""; return }
data.brings[editing] = editor.value
}
function open(name) {
editing = name
editchange()
editor.value = data.brings[name]
}
function addCmd() {
let name = prompt("Enter name or leave blank to cancel")
if (name) {
if (!/^([a-zA-Z\-_0-9])+$/.test(name)) {
alert("Invalid command name. Use only letters, numbers, hyphens and underscores.")
return
}
if (name in data.brings) {
alert("Already exists")
}
data.brings[name] = ""
load()
open(name)
}
}
function delCmd() {
if (!editing) alert("Select command first")
if (confirm("Are you sure you want to delete " + editing)) {
delete data.brings[editing]
load()
open(Object.keys(data.brings)[0])
}
}
load()
</script>
</body>
</html>