Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
amethystnetwork-dev
GitHub Repository: amethystnetwork-dev/Incognito
Path: blob/main/static/script/apps.js
917 views
1
/**
2
* Incognito
3
*
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation, either version 3 of the License, or
7
* (at your option) any later version.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16
*/
17
18
/*
19
_____ _ _ _
20
| __ \ | | | | | |
21
| |__) | ___ _ __ | |_ ___ __| | | |__ _ _
22
| ___/ / _ \ | '__| | __| / _ \ / _` | | '_ \ | | | |
23
| | | (_) | | | | |_ | __/ | (_| | | |_) | | |_| |
24
|_| \___/ |_| \__| \___| \__,_| |_.__/ \__, |
25
__/ |
26
|___/
27
_ _ _ _ _ _ _
28
/\ | | | | | | | \ | | | | | |
29
/ \ _ __ ___ ___ | |_ | |__ _ _ ___ | |_ | \| | ___ | |_ __ __ ___ _ __ | | __
30
/ /\ \ | '_ ` _ \ / _ \ | __| | '_ \ | | | | / __| | __| | . ` | / _ \ | __| \ \ /\ / / / _ \ | '__| | |/ /
31
/ ____ \ | | | | | | | __/ | |_ | | | | | |_| | \__ \ | |_ | |\ | | __/ | |_ \ V V / | (_) | | | | <
32
/_/ \_\ |_| |_| |_| \___| \__| |_| |_| \__, | |___/ \__| |_| \_| \___| \__| \_/\_/ \___/ |_| |_|\_\
33
__/ |
34
|___/
35
*/
36
async function apps(app) {
37
app.search.input.placeholder = 'Search apps'
38
app.search.back.style.display = 'inline';
39
app.search.back.href = '#';
40
41
app.main.library = app.createElement('div', await compileGs(app), {
42
class: 'gs-library',
43
style: {}
44
});
45
app.main.emptySearch = app.createElement('div', [
46
app.createElement('p', 'No results found.'),
47
], {
48
class: 'gs-empty',
49
style: {
50
display: 'none'
51
}
52
});
53
54
function searchApps() {
55
let count = 0;
56
57
app.main.library.querySelectorAll('.gs-entry').forEach(node => {
58
if (node.getAttribute('data-title').toLowerCase().includes(app.search.input.value.toLowerCase())) {
59
node.setAttribute('data-active', '1');
60
count++;
61
} else {
62
node.removeAttribute('data-active');
63
};
64
});
65
66
if (!count) {
67
app.main.library.style.display = 'none';
68
app.main.emptySearch.style.display = 'block';
69
} else {
70
app.main.library.style.removeProperty('display');
71
app.main.emptySearch.style.display = 'none';
72
};
73
}
74
75
app.search.input.addEventListener('input', searchApps);
76
app.once('exit', () => app.search.input.removeEventListener('input', searchApps));
77
};
78
79
80
async function compileGs(app) {
81
const res = await fetch('./source/apps.json');
82
const json = await res.json();
83
const arr = [];
84
85
app.search.input.placeholder = `Search apps (${json.length})`
86
for (const entry of json) {
87
arr.push(
88
app.createElement('div', [], {
89
class: 'gs-entry',
90
style: {
91
background: `url(${entry.img})`,
92
'background-size': 'cover'
93
},
94
attrs: {
95
'data-title': entry.title,
96
'data-active': ''
97
},
98
events: {
99
click(event) {
100
const frame = document.querySelector('iframe');
101
document.querySelector('main').style.display = 'none';
102
document.querySelector('header').style.display = 'none';
103
frame.style.display = 'block';
104
frame.src = (entry.location.startsWith('https://') || entry.location.startsWith('http://')) ? './load.html#' + encodeURIComponent(btoa(entry.location))
105
: entry.location;
106
107
document.querySelector('.access-panel').style.removeProperty('display');
108
}
109
}
110
})
111
)
112
};
113
114
return arr;
115
};
116
117
export { apps };
118
119