-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
79 lines (73 loc) · 3.3 KB
/
app.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
"use strict"
document.getElementById("vs-code").textContent = `\
.. . ....
.''.;xd:l:. .ldxl,,;;.
.lOOx0WXKXd. .lOKNK0XX0:
.xWWNWMMWWd. ;KWWMWMMMK;
:XMMMMMMWd. cXMMMMMMWx.
.OWMMMMMWd. lNMMMMMMXc
.oNMMMMMWd. oNMMMMMMO'
;KMMMMMWd. .dWMMMMMNo.
.xWMMMMWd. .oXMMMMMK:
:KMMMMWx. .xWMMMWk.
.dWMMMWx. .dWMMMNl
cXMMMWx. .xWMMM0,
cXMMMNl .kWMMWd.
,0MMMWd. .kMMMX:
.xWMMM0, .OMMWk.
lNMMMK; 'OMMNl
,0MMMX: '0MMK,
.kWMMK; '0MWk.
oNMMO' '0MNo.
;KWM0' '0MX:
.oKW0, ,0MO'
.dNK; ;KWd.
;0K: cXXc
.x0c lN0,
.:xl. :Kx.
.:l. ;kc
.:. :x,
'. co.
::
'.
`
// Search.
document.getElementById("vs-search").onkeyup = function () {
const re = new RegExp(this.value.toLowerCase(), "i")
for (const elem of document.getElementsByClassName("vs-snippet-entry")) {
elem.classList.toggle("d-none", !re.test(elem.innerText))
}
}
// Select from list.
const code = document.getElementById("vs-code")
const title = document.getElementById("vs-title")
const download = document.getElementById("vs-download")
let selected
const setActive = (a) => {
if (!a) return;
if (selected) selected.classList.remove("active")
a.classList.add("active")
selected = a
history.replaceState(null, "", "#!" + a.pathname.replace(/^\/$/g, ""))
fetch(a.href)
.then((response) => response.text())
.then((text) => {
code.textContent = text
Prism.highlightElement(code)
const str = a.getElementsByClassName("vs-list-title")[0].textContent
document.title = str + " | VT Snippets"
title.textContent = str
download.href = a.href
})
}
for (const entry of document.getElementsByClassName("vs-snippet-entry")) {
entry.onclick = function(e) {
e.preventDefault()
setActive(this)
}
}
setActive(document.querySelector(`a[href='${window.location.hash.substr(2)}']`))
const copy = document.getElementById("vs-copy")
new ClipboardJS(copy).on("success", (e) => {
e.clearSelection()
})