Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
amethystnetwork-dev
GitHub Repository: amethystnetwork-dev/Incognito
Path: blob/main/static/script/home.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
const tips = [
37
'Modify Inc&#173;ogni&#173;tos appearance & browser tab in <a href="#settings">settings.</a>',
38
'You can enable about:blank tab cloaking in <a href="#settings">settings.</a>',
39
'Access popular media & sites easily in <a href="#apps">apps.</a>',
40
'This <a href="https://github.com/amethystnetwork-dev/Incognito">unofficial In&#173;cog&#173;nito version</a> is made by Am&#173;et&#173;hy&#173;st Net&#173;wo&#173;rk.',
41
'Join the <a href="#community">Am&#173;et&#173;hyst Ne&#173;tw&#173;ork d&#173;i&#173;sco&#173;rd</a>',
42
'Get answers to questions in <a href="#support">support</a>'
43
];
44
45
import { searchProviders } from "./search.js";
46
47
48
function access(app) {
49
if (document.querySelector('header').hasAttribute('data-init')) {
50
document.querySelector('header').removeAttribute('data-init')
51
};
52
53
app.search.back.style.display = 'none';
54
app.search.logo.style.display = 'inline';
55
app.search.logo.style.marginLeft = '0';
56
app.search.submit.style.display = 'inline';
57
app.search.input.style.removeProperty('display');
58
app.search.input.placeholder = 'Search the web';
59
app.header.target.setAttribute('data-page', '');
60
app.nav.target.style.removeProperty('display');
61
document.querySelector('#open-nav').setAttribute('data-open', '');
62
app.search.input.focus();
63
64
65
66
app.nav.community = app.createLink('#community', 'Community');
67
app.nav.support = app.createLink('#support', 'Support');
68
app.nav.apps = app.createLink('#apps', 'Apps');
69
app.nav.games = app.createLink('#gs', 'Games');
70
app.nav.settings = app.createLink('#settings', '<i class="fas fa-sliders-h secondary"></i>', {
71
id: 'apps'
72
})
73
app.main.tip = app.createElement('div', (localStorage.getItem('incog||disabletips') !== 'none' ? tips[Math.floor(Math.random()*tips.length)] : ''), { class: 'tip' });
74
75
async function searchSuggestions(event) {
76
app.main.suggestions.innerHTML = '';
77
if (!event.target.value) {
78
app.nav.target.style.removeProperty('display');
79
app.header.target.setAttribute('data-page', '');
80
app.main.tip.style.removeProperty('display');
81
app.search.logo.style.display = 'inline';
82
return;
83
}
84
85
app.main.tip.style.display = 'none';
86
app.header.target.removeAttribute('data-page');
87
app.nav.target.style.display = 'none';
88
app.search.logo.style.display = 'none';
89
90
clearTimeout(app.timeout);
91
app.timeout = setTimeout(async () => {
92
const providerName = localStorage.getItem('incog||suggestions');
93
const provider = searchProviders[(providerName in searchProviders) ? providerName : 'ddg'];
94
95
const res = await app.bare.fetch(provider.mapQuery(event.target.value));
96
const text = await res.text();
97
const suggestions = provider.parseResponse(text);
98
99
suggestions.forEach(element => {
100
app.main.suggestions.append(app.createElement('div', element, { class: 'suggestion',
101
events: {
102
click() {
103
app.search.input.value = element;
104
app.registerSW();
105
const frame = document.querySelector('iframe');
106
document.querySelector('main').style.display = 'none';
107
document.querySelector('header').style.display = 'none';
108
frame.style.display = 'block';
109
frame.src = './load.html#' + encodeURIComponent(btoa(element));
110
document.querySelector('.access-panel').style.removeProperty('display');
111
}
112
}
113
}))
114
115
});
116
}, 400);
117
}
118
119
if(localStorage.getItem('incog||suggestions') !== 'none') {
120
app.main.suggestions = app.createElement('div', [], {
121
class: 'suggestions',
122
style: {
123
display: 'block'
124
}
125
});
126
127
app.search.input.addEventListener('input', searchSuggestions);
128
app.once('exit', () => app.search.input.removeEventListener('input', searchSuggestions));
129
}
130
131
app.search.input.setAttribute('form', 'access-form');
132
app.search.submit.setAttribute('form', 'access-form');
133
134
const params = new URLSearchParams(window.location.search);
135
136
if (params.has('link')) {
137
app.main.target.style.display = 'none';
138
app.header.target.style.display = 'none';
139
app.registerSW();
140
141
const frame = document.querySelector('.access-frame');
142
143
frame.src = './load.html#' + encodeURIComponent(params.get('link'));
144
frame.style.display = 'block';
145
146
document.querySelector('.access-panel').style.removeProperty('display');
147
history.replaceState('', '', window.location.pathname + '#');
148
};
149
};
150
151
export { access };
152
153