Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
FogNetwork
GitHub Repository: FogNetwork/Tsunami
Path: blob/main/public/js/go.js
1036 views
1
var rhodiumproxy = window.location.protocol + "//" + window.location.hostname + "/rhodium/gateway?url="
2
3
var corrosionproxy = window.location.protocol + "//" + window.location.hostname + "/corrosion/gateway?url="
4
5
var ultravioletproxy = window.location.protocol + "//" + window.location.hostname + __uv$config.prefix
6
7
var stompproxy = window.location.protocol + "//" + window.location.hostname
8
9
if ('serviceWorker' in navigator) {
10
window.navigator.serviceWorker.register('./uv.js', {scope: __uv$config.prefix})
11
}
12
13
var Stomp = new StompBoot({
14
bare_server: "/bare/",
15
directory: "/stomp/",
16
loglevel: StompBoot.LOG_ERROR,
17
codec: StompBoot.CODEC_XOR
18
})
19
20
var StompSearch = new StompBoot.SearchBuilder("https://google.com/search?q=%s")
21
22
function searchurl(url) {
23
var search = localStorage.getItem("search")
24
if (search == "Google") {
25
pxyopen("https://www.google.com/search?q=" + url)
26
} else if (search == "DuckDuckGo") {
27
pxyopen("https://duckduckgo.com/?q=" + url)
28
} else if (search == "Bing") {
29
pxyopen("https://www.bing.com/search?q=" + url)
30
} else if (search == "Brave") {
31
pxyopen("https://search.brave.com/search?q=" + url)
32
} else {
33
console.log("Error with search")
34
}
35
}
36
37
function getproxy(url) {
38
var currentproxy = localStorage.getItem("proxy")
39
if (currentproxy == "Rhodium") {
40
return rhodiumproxy + url
41
} else if (currentproxy == "Corrosion") {
42
return corrosionproxy + url
43
} else if (currentproxy == "Ultraviolet") {
44
return ultravioletproxy + __uv$config.encodeUrl(url)
45
} else if (currentproxy == "Stomp") {
46
return stompproxy + Stomp.html(StompSearch.query(url))
47
}
48
}
49
50
function pxyopen(url) {
51
if (localStorage.getItem("proxy") !== null) {
52
var mode = localStorage.getItem("mode") || "defualt"
53
54
if (mode == "defualt") {
55
var surf = document.getElementById("surf");
56
var closesurf = document.getElementById("closesurf");
57
var reloadsurf = document.getElementById("reloadsurf");
58
var controls = document.getElementById("controls");
59
controls.style.display = "flex";
60
surf.style.display = "initial";
61
closesurf.style.display = "initial";
62
reloadsurf.style.display = "initial";
63
surf.setAttribute("src", getproxy(url));
64
document.getElementById("search").value = "";
65
} else if (mode == "simple") {
66
window.location.href = getproxy(url)
67
} else if (mode == "about") {
68
var page = new ABC({
69
"type": "blank",
70
"url": getproxy(url)
71
})
72
page.open()
73
}
74
}
75
}
76
77
function go(url) {
78
if (url !== '') {
79
if (url.includes('.')) {
80
pxyopen(url)
81
} else if (url.startsWith('https://')) {
82
pxyopen(url)
83
} else if (url.startsWith('http://')) {
84
pxyopen(url)
85
} else {
86
searchurl(url)
87
}
88
} else {
89
return false;
90
}
91
}
92
93
window.onload = function() {
94
95
search = document.getElementById("search");
96
search.addEventListener('keydown', function(e) {
97
if (e.keyCode === 13) {
98
go(search.value)
99
}
100
});
101
};
102
103
function closesurf() {
104
var surf = document.getElementById("surf");
105
var closesurf = document.getElementById("closesurf");
106
var reloadsurf = document.getElementById("reloadsurf");
107
var controls = document.getElementById("controls");
108
var navtitle = document.getElementById("nav-title");
109
controls.style.display = "none";
110
surf.style.display = "none";
111
closesurf.style.display = "none";
112
reloadsurf.style.display = "none";
113
surf.setAttribute("src", "");
114
navtitle.innerText = "Loading..."
115
}
116
117
function reloadsurf() {
118
var surf = document.getElementById("surf");
119
surf.contentWindow.location.reload()
120
}
121
122
function fullscreensurf() {
123
var surf = document.getElementById("surf");
124
surf.contentWindow.location.reload()
125
}
126
127
var currentproxy = localStorage.getItem("proxy")
128
var rhodium = document.getElementById("rhodium")
129
var corrosion = document.getElementById("corrosion")
130
var ultraviolet = document.getElementById("ultraviolet")
131
var stomp = document.getElementById("stomp")
132
133
if (localStorage.getItem("proxy") !== null) {
134
var currentproxy2 = currentproxy.toLowerCase()
135
document.getElementById(currentproxy2).classList.add("proxysel")
136
}
137
138
function setproxy(proxy) {
139
localStorage.setItem("proxy", proxy)
140
if (proxy == "Rhodium") {
141
rhodium.classList.add("proxysel")
142
corrosion.classList.remove("proxysel")
143
ultraviolet.classList.remove("proxysel")
144
stomp.classList.remove("proxysel")
145
} else if (proxy == "Corrosion") {
146
rhodium.classList.remove("proxysel")
147
ultraviolet.classList.remove("proxysel")
148
corrosion.classList.add("proxysel")
149
stomp.classList.remove("proxysel")
150
} else if (proxy == "Ultraviolet") {
151
rhodium.classList.remove("proxysel")
152
corrosion.classList.remove("proxysel")
153
ultraviolet.classList.add("proxysel")
154
stomp.classList.remove("proxysel")
155
} else if (proxy == "Stomp") {
156
rhodium.classList.remove("proxysel")
157
corrosion.classList.remove("proxysel")
158
ultraviolet.classList.remove("proxysel")
159
stomp.classList.add("proxysel")
160
}
161
}
162
163
function hidesugg() {
164
document.getElementById("omnibox").style.borderRadius = "5px";
165
document.getElementById("suggestions").style.display = "none";
166
}
167
168
function showsugg() {
169
document.getElementById("omnibox").style.borderRadius = "5px 5px 0 0";
170
document.getElementById("suggestions").style.display = "inherit"
171
}
172
173
function sugggo(suggtext) {
174
if (localStorage.getItem("proxy") !== null) {
175
go(suggtext)
176
document.getElementById("search").value = ""
177
hidesugg()
178
}
179
}
180
181
window.addEventListener("load", function() {
182
var search = document.getElementById("search")
183
search.addEventListener("keyup", function(event) {
184
event.preventDefault()
185
if (event.keyCode == 13)
186
if (this.value !== "") {
187
go(this.value)
188
this.value = ""
189
}
190
});
191
192
search.addEventListener("keyup", function(event) {
193
event.preventDefault()
194
if (search.value.trim().length !== 0) {
195
document.getElementById("suggestions").innerText = ""
196
showsugg()
197
async function getsuggestions() {
198
var term = search.value || "";
199
var response = await fetch("/suggestions?q=" + term);
200
var result = await response.json();
201
var suggestions = result.slice(0, 8);
202
for (sugg in suggestions) {
203
var suggestion = suggestions[sugg]
204
var sugg = document.createElement("div")
205
sugg.innerText = suggestion
206
sugg.setAttribute("onclick", "sugggo(this.innerText)")
207
sugg.className = "sugg"
208
document.getElementById("suggestions").appendChild(sugg)
209
}
210
}
211
getsuggestions()
212
} else {
213
hidesugg()
214
}
215
});
216
217
search.addEventListener("click", function(event) {
218
if (search.value.trim().length !== 0) {
219
showsugg()
220
}
221
})
222
223
})
224
225
function hidesuggclick(){
226
if (window.event.srcElement.id !== "search" && window.event.srcElement.id !== "suggestions" && window.event.srcElement.className !== "sugg") {
227
hidesugg()
228
}
229
}
230
231
document.onclick = hidesuggclick
232
233
function fullscreensurf() {
234
var surf = document.getElementById("surf")
235
surf.requestFullscreen()
236
}
237
238
function setTabTitle(title) {
239
if (title) {
240
var navtitle = document.getElementById("nav-title")
241
navtitle.innerText = title
242
} else {
243
var navtitle = document.getElementById("nav-title")
244
var surf = document.getElementById("surf")
245
navtitle.innerText = surf.contentWindow.location.host
246
}
247
}
248
249
function setTabIcon(favicon) {
250
if (favicon) {
251
var navicon = document.getElementById("nav-icon")
252
navicon.src = favicon
253
} else {
254
var navicon = document.getElementById("nav-icon")
255
navicon.src = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PHBhdGggZD0iTTEyIDJjNS41MiAwIDEwIDQuNDggMTAgMTBzLTQuNDggMTAtMTAgMTBTMiAxNy41MiAyIDEyIDYuNDggMiAxMiAyek00IDEyaDQuNGMzLjQwNy4wMjIgNC45MjIgMS43MyA0LjU0MyA1LjEyN0g5LjQ4OHYyLjQ3YTguMDA0IDguMDA0IDAgMDAxMC40OTgtOC4wODNDMTkuMzI3IDEyLjUwNCAxOC4zMzIgMTMgMTcgMTNjLTIuMTM3IDAtMy4yMDYtLjkxNi0zLjIwNi0yLjc1aC0zLjc0OGMtLjI3NC0yLjcyOC42ODMtNC4wOTIgMi44Ny00LjA5MiAwLS45NzUuMzI3LTEuNTk3LjgxMS0xLjk3QTguMDA0IDguMDA0IDAgMDA0IDEyeiIgZmlsbD0iIzNDNDA0MyIvPjwvc3ZnPg=="
256
}
257
}
258
259
surf.addEventListener("load", function() {
260
var navtitle = document.getElementById("nav-title")
261
var navicon = document.getElementById("nav-icon")
262
263
if (surf.contentWindow.location.toString() == "about:blank") {
264
return {
265
name : navtitle.innerText = "Loading...",
266
favicon : navicon.src = ""
267
};
268
}
269
270
var initTitle = surf.contentWindow.document.title
271
setTabTitle(initTitle)
272
273
var initFavicon = null;
274
var icon = surf.contentWindow.document.querySelector("link[rel='icon']") || null
275
var shortcuticon = surf.contentWindow.document.querySelector("link[rel='shortcut icon']") || null
276
if (icon) {
277
initFavicon = new URL(surf.contentWindow.document.querySelector("link[rel='icon']").getAttribute("href"), surf.contentWindow.document.baseURI).toString();
278
} else if (shortcuticon) {
279
initFavicon = new URL(surf.contentWindow.document.querySelector("link[rel='shortcut icon']").getAttribute("href"), surf.contentWindow.document.baseURI).toString();
280
}
281
if (initFavicon == surf.contentWindow.document.baseURI) {
282
initFavicon = null
283
}
284
setTabIcon(initFavicon)
285
})
286
287
var gosurf = localStorage.getItem("go") || "default"
288
document.body.setAttribute("go", gosurf)
289