-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
160 lines (142 loc) · 5.41 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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>UUID 2 Hedgedoc longid converter</title>
<meta name="description" content="Converts hedgedoc's internal database uuids into public longids and vice versa">
<meta name="author" content="SitePoint">
<meta property="og:title" content="A Basic HTML5 Template">
<meta property="og:type" content="website">
<meta property="og:url" content="https://www.sitepoint.com/a-basic-html5-template/">
<meta property="og:description" content="A simple HTML5 Template for new projects.">
<meta property="og:image" content="image.png">
<link rel="icon" href="/favicon.ico">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
</head>
<body>
<div class="container p-5 vh-100">
<div class="input-group h-25">
<textarea class="form-control" id="uuids" aria-label="With textarea" placeholder="af2b0b2c-dbe0-47ba-8a33-2965d8359984
103b1fba-1041-47a6-8650-f556708e470b
ab0207ef-2cc6-4a0d-bbdb-485d53bd4102
ee5546cf-d683-4273-a1ab-f64d454ceee2"></textarea>
</div>
<div class="mb-5 mt-5">
<div class="input-group">
<input type="text" class="form-control w-50" id="domain" aria-describedby="domain" placeholder="https://yourdomain.org/">
<span class="input-group-text w-50" id="preview" aria-describedby="preview">rysLLNvgR7qKMyll2DWZhA</span>
</div>
<div class="ps-3 form-text">Add your domain to genrated long Ids</div>
</div>
<div class="input-group h-25">
<textarea class="form-control" id="longids" aria-label="With textarea"></textarea>
</div>
</div>
<script type="text/javascript">
input_uuids = document.getElementById("uuids")
input_longids = document.getElementById("longids")
input_domain = document.getElementById("domain")
label_preview = document.getElementById("preview")
let global_longids = []
let global_uuids = []
function encode(uuid){
/* Encode
* converts an uuid to a hedgedoc longid
* ex: input: af2b0b2c-dbe0-47ba-8a33-2965d8359984, output:rysLLNvgR7qKMyll2DWZhA
*/
uuid = uuid.replaceAll('-', '')
ret = []
for (var i = 0; i < uuid.length; i += 2){
part = uuid.substr(i,2)
if (part.length < 2){
part = '0' + part
}
ret.push(String.fromCharCode(parseInt(part,16)))
}
return btoa(ret.join('')).toString().replaceAll('=','').replaceAll('/','_').replaceAll('+','-'))
}
function decode(longid){
/* Decode
* converts a hedgedoc longid to an uuid
* ex: input: rysLLNvgR7qKMyll2DWZhA, output: af2b0b2c-dbe0-47ba-8a33-2965d8359984
*/
longid_bin = atob(longid.replaceAll('_','/').replaceAll('-','+'))
hexValues = []
for (let i = 0; i < longid_bin.length; i+=1){
value = parseInt(longid_bin.charCodeAt(i)).toString(16)
// Hex values below 0xf only have one digit and are not proccessed correctly
// pad with 0 infront
if (value.length == 1){
value = '0' + value
}
hexValues.push(value)
}
uuid = hexValues.join('')
// https://github.com/hedgedoc/hedgedoc/blob/d26dcd04a147a52047efbe66a0fc99d08049265e/lib/models/note.js#L172:L183
// add dashes between the UUID string parts
const uuidParts = []
uuidParts.push(uuid.substr(0, 8))
uuidParts.push(uuid.substr(8, 4))
uuidParts.push(uuid.substr(12, 4))
uuidParts.push(uuid.substr(16, 4))
uuidParts.push(uuid.substr(20, 12))
return uuidParts.join('-')
}
function updateLongIds(longids){
input_longids.value = longids.join('\n')
}
input_domain.addEventListener("input", f =>{
updateLongIds(prependDomain(global_longids))
})
function prependDomain(_longids){
if(_longids.length != 0){
let longids = []
for(let i = 0; i<_longids.length; i += 1){
longids.push(input_domain.value + _longids[i])
}
return longids
}
}
input_uuids.addEventListener("input", f => {
domain = input_domain.value
str = input_uuids.value
strs = str.split('\n')
longids = []
for (var str of strs){
// longids.push(domain + encode(str))
longids.push(encode(str))
}
global_longids = longids
label_preview.innerText = longids[0]
updateLongIds(prependDomain(longids))
})
input_longids.addEventListener("input", f => {
longids = input_longids.value
longids = longids.split('\n')
uuids = []
for (let i = 0; i<longids.length; i+=1){
let longid = longids[i]
let idx_slash = longid.lastIndexOf('/') + 1
if (idx_slash > 0){
if (i==0){
input_domain.value = longid.substr(0,idx_slash)
}
longid = longid.substr(idx_slash, longid.length)
}
let idx_questionmark = longid.indexOf('?')
if (idx_questionmark > 0){
longid = longid.substr(0,idx_questionmark)
}
longids[i] = longid
uuids.push(decode(longid))
}
label_preview.innerText = longids[0]
global_longids = longids
input_uuids.value = uuids.join('\n')
global_uuids = uuids
})
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
</body>
</html>