-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.es6
59 lines (49 loc) · 1.8 KB
/
script.es6
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
document.querySelector('form').addEventListener('submit', e => {
e.preventDefault()
search(true)
})
document.querySelector('button').addEventListener('click', () => {
search(true)
})
document.querySelector('input[type="text"]').addEventListener('input', () => search())
/**
* @param go {bool} - If true, page will navigate to the first result if there
* exactly one.
*/
function search (go) {
const query = document.querySelector('input[type="text"]').value.toLowerCase()
const results = Object.keys(keyData).filter(host => host.includes(query)).sort((a, b) => a.indexOf(query) - b.indexOf(query))
if (go === true) {
window.location.href = keyData[results[0]]
}
else showResults(results)
}
function showResults(results) {
function result(host, url) {
const div = document.createElement('div')
const h3 = document.createElement('h3')
const a = document.createElement('a')
a.textContent = host
a.href = url
h3.appendChild(a)
div.appendChild(h3)
return div
}
const output = document.createElement('div')
results.map(host =>
result(host, keyData[host])
).forEach(node =>
output.appendChild(node)
)
const resultsDiv = document.querySelector('.results')
if(resultsDiv.lastChild) resultsDiv.removeChild(resultsDiv.lastChild)
document.querySelector('.results').appendChild(output)
}
const keyData = {
'github.com': 'https://help.github.com/articles/github-s-ssh-key-fingerprints/',
'gitlab.com': 'https://docs.gitlab.com/ee/user/gitlab_com/#ssh-host-keys-fingerprints',
'gist.github.com': 'https://help.github.com/articles/github-s-ssh-key-fingerprints/',
'bitbucket.com': 'https://confluence.atlassian.com/bitbucket/ssh-keys-935365775.html',
'sourceforge.net': 'https://sourceforge.net/p/forge/documentation/SSH%20Key%20Fingerprints/'
}
search()