-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.js
89 lines (78 loc) · 2.27 KB
/
script.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
80
81
82
83
84
85
86
87
88
89
// plugins.js
plugins.sort((a, b) => a.name.localeCompare(b.name));
let plugins_el = plugins.map((plugin) => {
return el('li', { class: 'item' }, [
el('span', plugin.name, { 'class': 'name' }),
el('button', 'plug', { class: 'copy' }, { click: () => copy(plugin, false) }),
el('p', plugin.desc, { class: 'description' }),
el('a', { href: plugin.repo }, plugin.repo),
el('span', ` (${plugin.file || 'init'})`),
plugin.home
? el('p', [ el('a', { href: plugin.home }, plugin.home) ])
: el('span'),
]);
})
// themes.js
themes.sort((a, b) => a.name.localeCompare(b.name));
let themes_el = themes.map((plugin) => {
return el('li', { class: 'item' }, [
el('span', plugin.name, { 'class': 'name' }),
el('button', 'plug', { class: 'copy' }, { click: () => copy(plugin, true) }),
el('div', { class: 'image-container' }, [
el('img', { src: plugin.image, class: 'image' }, {
click: () => { window.open(plugin.image, '_blank').focus(); }
}),
]),
el('a', { href: plugin.repo }, plugin.repo),
el('span', ` (${plugin.file || 'init'})`),
plugin.home
? el('p', [ el('a', { href: plugin.home }, plugin.home) ])
: el('span'),
]);
})
// copy a vis-plug config line to the clipboard
function copy(plugin, theme) {
let repo = plugin.repo.replace(/https:\/\/(github.com\/)?/, '')
var lua = `{ '${repo}' `
if (plugin.file) {
lua += `, file = '${plugin.file}' `
}
if (theme) {
lua += `, theme = ${theme} `
}
lua += `},`
navigator.clipboard.writeText(lua);
}
// search for plugins and themes
function search() {
let query = get('search').value
let pluginList = get('plugins').getElementsByTagName('li')
for (let plugin of pluginList) {
plugin.style.display = plugin.innerText.toLowerCase()
.indexOf(query.toLowerCase()) > -1 ? 'block' : 'none'
}
}
function set_plugin_type(type) {
localStorage.setItem('plugin-type', type);
switch (type) {
case 'plugin': {
// set checked
set('plugins', plugins_el)
break;
}
case 'theme': {
set('plugins', themes_el)
break;
}
default:
break;
}
}
const plugin_type = localStorage.getItem('plugin-type') ?? 'plugin'
set_plugin_type(plugin_type)
if (plugin_type === 'plugin') {
get('show-plugins').checked = true
} else {
get('show-themes').checked = true
}
get('search').addEventListener('input', search)