Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
amethystnetwork-dev
GitHub Repository: amethystnetwork-dev/Incognito
Path: blob/main/static/script/index.js
918 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
37
console.log(`Incognito
38
This program is free software: you can redistribute it and/or modify
39
it under the terms of the GNU General Public License as published by
40
the Free Software Foundation, either version 3 of the License, or
41
(at your option) any later version.
42
43
This program is distributed in the hope that it will be useful,
44
but WITHOUT ANY WARRANTY; without even the implied warranty of
45
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46
GNU General Public License for more details.
47
48
You should have received a copy of the GNU General Public License
49
along with this program. If not, see <https://www.gnu.org/licenses/>.`);
50
51
if(['netlify.app', 'vercel.app', 'github.io', 'gitlab.io', 'pages.dev'].filter(host => window.location.hostname.includes(host)).length) throw alert(`You cannot deploy to ${window.location.hostname}. Did you read the notice before deploying?`);
52
53
import { App } from './app.js';
54
import { gs } from './gs.js';
55
import { apps } from './apps.js';
56
import { access } from './home.js';
57
import { options } from './options.js';
58
import { support } from './support.js';
59
import { community } from './community.js';
60
61
window.app = new App();
62
window.addEventListener("load", () => {
63
app.registerSW();
64
});
65
66
switch(localStorage.getItem('incog||background')) {
67
case 'stars':
68
particlesJS.load('.particles', './json/stars.json');
69
break;
70
case 'particles':
71
particlesJS.load('.particles', './json/particles.json');
72
};
73
74
app.openNav = function() {
75
document.querySelector('#close-nav').style.display = 'flex';
76
document.querySelector('nav').style.display = 'flex';
77
};
78
79
app.closeNav = function() {
80
document.querySelector('#close-nav').style.removeProperty('display')
81
document.querySelector('nav').style.removeProperty('display')
82
};
83
84
app.destroyParticles = function() {
85
if (window.pJSDom && window.pJSDom.length) window.pJSDom[0].pJS.fn.vendors.destroypJS();
86
window.pJSDom = [];
87
return true;
88
};
89
90
document.querySelector('#open-nav').addEventListener('click', app.openNav);
91
document.querySelector('#close-nav').addEventListener('click', app.closeNav);
92
93
document.title = localStorage.getItem('incog||title') || 'Incognito';
94
window.icon = document.querySelector('#favicon');
95
96
icon.href = localStorage.getItem('incog||icon') || './index.svg';
97
98
app.on('init', () => {
99
app.icon = document.querySelector('#favicon');
100
app.search.back = app.createElement('a', 'chevron_left', {
101
class: 'submit',
102
style: {
103
'font-family': 'Material Icons',
104
'font-size': '30px',
105
'color': 'var(--accent)',
106
'display': 'none',
107
}
108
});
109
app.search.title = app.createElement('div', [], {
110
class: 'title',
111
style: {
112
'font-size': '16px',
113
'font-weight': '500',
114
color: 'var(--accent)',
115
display: 'none',
116
}
117
});
118
app.search.logo = createLink('#', '<img class="hu" src="img/hu.png" width="50px" height="50px"><svg class="nav-logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 365.37 365.37"><defs> <style> .cls-1{ fill:none; stroke-width:18px;} .cls-1, .cls-2 { stroke: var(--accent); stroke-miterlimit:10;} .cls-2 { fill: var(--accent); stroke-width:5px;} </style> </defs><circle class="cls-1" cx="182.68" cy="182.68" r="173.68"></circle><path class="cls-2" d="M210.41,66.38A115.27,115.27,0,0,1,70.52,248.19,134,134,0,1,0,210.41,66.38Z" transform="translate(-17.32 -17.32)"></path></svg>', {
119
style: {
120
display: 'none'
121
}
122
});
123
app.search.input = app.createElement('input', [], {
124
attrs: {
125
placeholder: ''
126
},
127
class: 'interactive',
128
});
129
app.search.submit = app.createElement('button', '<i class="fas fa-search"></i>', {
130
class: 'submit',
131
style: {
132
display: 'none'
133
}
134
});
135
});
136
137
app.on('exit', async () => {
138
document.querySelector('#open-nav').removeAttribute('data-open');
139
if (document.querySelector('header').hasAttribute('data-init')) {
140
document.querySelector('header').removeAttribute('data-init')
141
};
142
143
if (app.search.logo.style.display === 'none') {
144
app.search.logo.style.removeProperty('display');
145
};
146
147
if (document.querySelector('header').hasAttribute('data-page')) {
148
document.querySelector('header').removeAttribute('data-page');
149
};
150
151
app.search.logo.style.display = 'none';
152
app.search.submit.style.display = 'none';
153
154
app.search.title.textContent = '';
155
app.search.title.style.display = 'none';
156
157
app.nav.clear();
158
app.main.clear();
159
160
app.main.target.classList.toggle('transition')
161
});
162
163
164
app.on('after', () => {
165
app.main.target.classList.toggle('transition')
166
});
167
168
169
document.querySelector('#access-form').addEventListener('submit', event => {
170
event.preventDefault();
171
app.registerSW().then(() => {
172
app.main.target.style.display = 'none';
173
app.header.target.style.display = 'none';
174
175
const frame = document.querySelector('.access-frame');
176
177
frame.src = '/load.html#' + btoa(event.target[0].value);
178
frame.style.display = 'block';
179
180
document.querySelector('.access-panel').style.removeProperty('display');
181
});
182
});
183
184
document.querySelector('.close-access').addEventListener('click', event => {
185
event.preventDefault();
186
app.main.target.style.display = 'block';
187
app.header.target.style.display = 'flex';
188
189
const frame = document.querySelector('.access-frame');
190
191
frame.src = 'about:blank';
192
frame.style.display = 'none';
193
194
document.querySelector('.access-panel').style.display = 'none';
195
});
196
197
document.querySelector('.refresh-access').addEventListener('click', () => {
198
const frame = document.querySelector('.access-frame');
199
const win = frame.contentWindow;
200
201
try {
202
win.location.reload();
203
} catch(e) {
204
205
};
206
});
207
208
document.querySelector('.access-link').addEventListener('click', () => {
209
const frame = document.querySelector('.access-frame');
210
const win = frame.contentWindow;
211
212
if (win.__uv$location) {
213
navigator.clipboard.writeText(
214
new URL('./?link=' + encodeURIComponent(btoa(win.__uv$location.href)), location.href).href
215
);
216
};
217
218
});
219
220
document.querySelector('.access-panel .controls .icon').addEventListener('error', event => {
221
event.target.src = 'img/globe.svg';
222
});
223
224
225
document.querySelector('.access-panel').addEventListener('mouseenter', async event => {
226
const frame = document.querySelector('.access-frame');
227
const win = frame.contentWindow;
228
229
const { bare } = app;
230
231
if (win && win.__uv) {
232
document.querySelector('.access-panel .controls input').value = Object.getOwnPropertyDescriptor(Document.prototype, 'title').get.call(win.document);
233
const favi = document.querySelector.call(win.document, 'link[rel=icon]');
234
235
if (favi && Object.getOwnPropertyDescriptor(HTMLLinkElement.prototype, 'href').get.call(favi)) {
236
const res = await bare.fetch(
237
__uv$config.decodeUrl(Object.getOwnPropertyDescriptor(HTMLLinkElement.prototype, 'href').get.call(favi).replace(new URL(__uv$config.prefix, window.location.origin), ""))
238
);
239
240
const blob = await res.blob();
241
const url = URL.createObjectURL(blob);
242
243
document.querySelector('.access-panel .controls .icon').src = url;
244
URL.revokeObjectURL(url);
245
} else {
246
const res = await bare.fetch(new URL('/favicon.ico', win.__uv$location.origin));
247
248
const blob = await res.blob();
249
const url = URL.createObjectURL(blob);
250
251
document.querySelector('.access-panel .controls .icon').src = url;
252
URL.revokeObjectURL(url);
253
};
254
};
255
});
256
257
app.on('default', access);
258
app.on('#gs', gs);
259
app.on('#apps', apps);
260
app.on('#settings', options);
261
app.on('#support', support);
262
app.on('#community', community);
263
264
app.init();
265
266
267
function createLink(href = null, content = '', config = {}) {
268
const elem = app.createElement('a', content, config);
269
if (href) elem.href = href;
270
return elem;
271
};
272
273
function timeout(time = 1000) {
274
return new Promise(resolve =>
275
setTimeout(resolve, time)
276
);
277
};
278