-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbrowser-script.js
489 lines (416 loc) · 19.7 KB
/
browser-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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
// AFTER WE ARE FINISHED USE https://obfuscator.io/
document.addEventListener('DOMContentLoaded', function() {
const addressBar = document.querySelector('.addressbar-urlbar-225461');
const tabContent = document.querySelector('.browser-tab-content-164148');
const rhNewTab = document.querySelector('.rhpages-357971.rhnewtab-340432');
const svgElement = document.querySelector('.chrome-tabs-newtab-btn-682118');
const containerDiv = document.querySelector('.chrome-tabs-content-769439');
const tabs = document.querySelector('#tabs');
const welcome = document.querySelector('.welcome');
const backButton = document.querySelector('#back-btn');
const forwardButton = document.querySelector('#forward-btn');
const refreshButton = document.querySelector('#refresh-btn');
const infoButton = document.querySelector('#info-btn');
const fbLogo = document.getElementById('fb-logo');
const shortcuts = document.querySelectorAll('.shortcut');
let leftCounter = 249;
let one = 1;
let tab_title = "New Tab";
let activeTab = null;
let tabNumber = null;
let shortcut_url = "";
let firsttab=null;
function setFavicon(shortcutshorter, favicon_num, shortcut_url) {
let favicon = document.getElementById(`favicon-container-${favicon_num}`);
let iconPath = `./img/links/${shortcutshorter}.svg`;
switch (shortcutshorter) {
case "youtube":
shortcut_url = "https://youtube.com";
break;
case "cornhub":
shortcut_url = "https://i.pinimg.com/736x/32/52/19/325219b7fd5afbf88cdcbfce87c75090.jpg";
iconPath = `./img/links/${shortcutshorter}.png`;
break;
case "netflix":
shortcut_url = "https://www.netflix.com";
break;
case "discord":
shortcut_url = "https://discord.com";
break;
case "reddit":
shortcut_url = "https://reddit.com";
break;
case "twitch":
shortcut_url = "https://twitch.tv";
break;
default:
console.error("Unknown shortcut:", shortcutshorter);
return;
}
favicon.innerHTML = `<img id='favicon-${favicon_num+1}' src='${iconPath}' height='17px' width='17px'>`;
favicon.removeAttribute("hidden");
return shortcut_url;
}
//code For Shortcuts
// Add event listener to each shortcut
shortcuts.forEach(shortcut => {
shortcut.addEventListener('click', function() {
// Get the text content of the clicked shortcut
var shortcutText = this.querySelector('a').textContent.toLowerCase()
var shortcutshorter=shortcutText.replace(/\s/g, '');
console.log(`Clicked on: ${shortcutshorter}`);
const newTabElement = document.createElement('div');
newTabElement.className = 'chrome-tab';
newTabElement.style = "width: 258px; "
newTabElement.id = `tab-num-${one}`;
newTabElement.innerHTML = `
<div class="chrome-tab-dividers"></div>
<div class="chrome-tab-background">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs><symbol id="chrome-tab-geometry-left" viewBox="0 0 214 36"><path d="M17 0h197v36H0v-2c4.5 0 9-3.5 9-8V8c0-4.5 3.5-8 8-8z"></path></symbol><symbol id="chrome-tab-geometry-right" viewBox="0 0 214 36"><use xlink:href="#chrome-tab-geometry-left"></use></symbol><clipPath id="crop"><rect class="mask" width="100%" height="100%" x="0"></rect></clipPath></defs><svg width="52%" height="100%"><use xlink:href="#chrome-tab-geometry-left" width="214" height="36" class="chrome-tab-geometry"></use></svg><g transform="scale(-1, 1)"><svg width="52%" height="100%" x="-100%" y="0"><use xlink:href="#chrome-tab-geometry-right" width="214" height="36" class="chrome-tab-geometry"></use></svg></g></svg>
</div>
<div class="chrome-tab-content">
<div class='chrome-tab-favicon' id="favicon-container-${one}" hidden="" ><img id="favicon-${one}" src="./img/spinner.gif" height="17px" width="17px"></div>
<div class="chrome-tab-title" id="title-tab-num-${one}">${shortcutText}</div>
<div class="chrome-tab-drag-handle" style="touch-action: none;"></div>
<div class="chrome-tab-close" id="close-tab-num-${one}"></div>
</div>
`;
containerDiv.appendChild(newTabElement);
leftCounter += 239;
svgElement.style.left = `${leftCounter}px`;
tabs.textContent += `#tab-num-${one} { transform: translate3d(${one * 239}px, 0, 0); }\n\n`;
one++;
// Set the new tab as active
if (activeTab) {
activeTab.removeAttribute('active');
}
newTabElement.setAttribute('active', '');
activeTab = newTabElement;
tabNumber = containerDiv.childElementCount - 1; // Assuming the new tab is the last one
const newIframe = document.createElement('iframe');
shortcut_url = "";
favicon_num = containerDiv.childElementCount-1; // Assuming the new tab is the last one
shortcut_url = "";
if (shortcutshorter === "youtube" || shortcutshorter === "cornhub" || shortcutshorter === "netflix" || shortcutshorter === "discord" || shortcutshorter === "reddit" || shortcutshorter === "twitch") {
shortcut_url = setFavicon(shortcutshorter, favicon_num, shortcut_url);
}
newIframe.src = createURL(shortcut_url, tabNumber);
newIframe.id = `iframe-num-${tabNumber}`;
newIframe.referpolicy = 'no-referrer';
newIframe.sandbox = 'allow-downloads allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-presentation allow-same-origin allow-scripts';
newIframe.style.display = 'block';
newIframe.className = "browser-tab-content-iframe";
tabContent.appendChild(newIframe);
tabContent.style.display = 'block';
rhNewTab.style.display = 'none';
welcome.style = "Display:none;";
//test, fixed kinda
// var isReloading = false;
// currentFavicon = document.getElementById(`favicon-container-${tabNumber}`);
// newIframe.addEventListener('load', function() {
// if (isReloading) {
// console.log('Iframe has finished reloading');
// spinnerElement.setAttribute('hidden', '');
// } else {
// currentFavicon.removeAttribute('hidden');
// isReloading = true;
// }
// });
const existingIframe = document.querySelector(`#iframe-num-${tabNumber}`);
if (existingIframe) {
existingIframe.style.display = 'block';
rhNewTab.style.display = 'none';
tabContent.style.display = 'block';
} else {
rhNewTab.style.display = 'block';
tabContent.style.display = 'none';
}
});
});
//adding tab
svgElement.addEventListener('click', function() {
const containerWidth = containerDiv.getBoundingClientRect().width;
let posX3 = event.clientX;
tabNumber = Math.ceil(posX3 / 239) - 1;
var n_small = Math.floor(containerWidth / tabNumber);
console.log("Total available width for the tabs:", n_small-239, "pixels");
console.log(containerWidth)
var current_num_Tabs = document.querySelectorAll('.chrome-tab').length;
if (n_small >= 269 && !(current_num_Tabs >= 7)) {
console.log("There's enough space for a new tab")
} else {
console.error("No space for a new tab");
alert("No space for a new tab. Remove a Tab to continue Browsing")
return false; // There's not enough space for a new tab
}
const newTabElement = document.createElement('div');
newTabElement.className = 'chrome-tab';
newTabElement.style = "width: 258px; "
newTabElement.id = `tab-num-${one}`
newTabElement.innerHTML = `
<div class="chrome-tab-dividers"></div>
<div class="chrome-tab-background">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg"><defs><symbol id="chrome-tab-geometry-left" viewBox="0 0 214 36"><path d="M17 0h197v36H0v-2c4.5 0 9-3.5 9-8V8c0-4.5 3.5-8 8-8z"></path></symbol><symbol id="chrome-tab-geometry-right" viewBox="0 0 214 36"><use xlink:href="#chrome-tab-geometry-left"></use></symbol><clipPath id="crop"><rect class="mask" width="100%" height="100%" x="0"></rect></clipPath></defs><svg width="52%" height="100%"><use xlink:href="#chrome-tab-geometry-left" width="214" height="36" class="chrome-tab-geometry"></use></svg><g transform="scale(-1, 1)"><svg width="52%" height="100%" x="-100%" y="0"><use xlink:href="#chrome-tab-geometry-right" width="214" height="36" class="chrome-tab-geometry"></use></svg></g></svg>
</div>
<div class="chrome-tab-content">
<div class='chrome-tab-favicon' id="favicon-container-${one}" hidden="" ><img id="favicon-${one}" src="./img/spinner.gif" height="17px" width="17px"></div>
<div class="chrome-tab-title" id="title-tab-num-${one}">${tab_title}</div>
<div class="chrome-tab-drag-handle" style="touch-action: none;"></div>
<div class="chrome-tab-close" id="close-num-${one}"></div>
</div>
`;
containerDiv.appendChild(newTabElement);
leftCounter += 239;
svgElement.style.left = `${leftCounter}px`;
tabs.textContent += `#tab-num-${one} { transform: translate3d(${one * 239}px, 0, 0); }\n\n`;
one++;
});
containerDiv.addEventListener('click', function(event) {
if (event.target.classList.contains('chrome-tab-close')) {
const tabToRemove = event.target.closest('.chrome-tab');
leftCounter -= 239;
svgElement.style.left = `${leftCounter}px`;
const tabToRemoveID = parseInt(tabToRemove.id.replace('tab-num-', ''));
const iframeToRemove = document.querySelector(`#iframe-num-${tabToRemoveID}`);
if (iframeToRemove) {
iframeToRemove.remove();
}
tabToRemove.remove();
const tabsToMove = document.querySelectorAll('.chrome-tab');
tabsToMove.forEach(tab => {
const tabID = parseInt(tab.id.replace('tab-num-', ''));
if (tabID > tabToRemoveID) {
const newLeft = (tabID - 1) * 239;
tab.style.transform = `translate3d(${newLeft}px, 0, 0)`;
tab.id = `tab-num-${tabID - 1}`;
const closeBtn = tab.querySelector('.chrome-tab-close');
closeBtn.id = `close-num-${tabID - 1}`;
const title = tab.querySelector('.chrome-tab-title');
title.id = `title-tab-num-${tabID - 1}`;
const iframe = document.querySelector(`#iframe-num-${tabID}`);
if (iframe) {
iframe.id = `iframe-num-${tabID - 1}`;
}
}
});
tabs.textContent = tabs.textContent.replace(`#tab-num-${one} { transform: translate3d(${one * 239}px, 0, 0); }\n\n`, "");
one--;
if (activeTab === tabToRemove) {
activeTab = null;
tabNumber = null;
}
} else {
if (activeTab) {
activeTab.removeAttribute('active');
if (tabNumber !== null) {
const iframe = document.querySelector(`#iframe-num-${tabNumber}`);
if (iframe) {
iframe.style.display = 'none';
}
}
}
try {
if (firsttab!=false) {
const zerodayt = document.querySelector(`#iframe-num-0`);
if(zerodayt){
zerodayt.style.display = 'none';
rhNewTab.style.display = 'block';
}
firsttab = false;
}
const clickedTab = event.target.closest('.chrome-tab');
if (!clickedTab) {
console.error('Clicked tab not found or no tab there');
return;
}
clickedTab.setAttribute('active', '');
activeTab = clickedTab;
let posX = event.clientX;
tabNumber = Math.ceil(posX / 239) - 1;
console.log('Clicked tab number:', tabNumber);
const existingIframe = document.querySelector(`#iframe-num-${tabNumber}`);
if (existingIframe) {
existingIframe.style.display = 'block';
rhNewTab.style.display = 'none';
tabContent.style.display = 'block';
} else {
rhNewTab.style.display = 'block';
tabContent.style.display = 'none';
}
} catch (error) {
console.error('An error occurred in selecting tab:', error);
}
}
if (one > 2) {
const previousIframe = document.querySelector(`#iframe-num-${one - 2}`);
if (previousIframe) {
previousIframe.style.display = 'none';
}
}
});
refreshButton.addEventListener('click', function() {
console.log("refreshed")
if (activeTab) {
const iframe = document.querySelector(`#iframe-num-${tabNumber}`);
if (iframe) {
iframe.src = iframe.src;
}
}
});
backButton.addEventListener('click', function() {
if (activeTab) {
console.log("back")
}
});
forwardButton.addEventListener('click', function() {
if (activeTab) {
console.log("forward")
}
});
infoButton.addEventListener('click', function() {
const info = document.createElement('div');
info.className = 'modal';
info.innerHTML = `
<div class="modal-content">
<span class="close">×</span>
<h2>helpful Information</h2>
<p>Would you like some help or iformation</p>
<p>too bad we havent added it yet</p>
</div>
`;
document.body.appendChild(info);
const infocloseButton = info.querySelector('.close');
infocloseButton.addEventListener('click', function() {
info.remove();
});
});
addressBar.addEventListener('keypress', function(event) {
if (event.key === 'Enter' && (activeTab == null || event.target != addressBar)) {
alert("Click on a tab to start browsing.");
} else if (event.key === 'Enter') {
let url = addressBar.textContent;
if (url == 'fb://dino') {
fetch('dino/dino.txt')
.then(response => response.text())
.then(docsrc => {
const newIframe = document.createElement('iframe');
newIframe.srcdoc = docsrc;
newIframe.id = `iframe-num-${tabNumber}`;
newIframe.referpolicy = 'no-referrer';
newIframe.sandbox = 'allow-downloads allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-presentation allow-same-origin allow-scripts';
newIframe.style.display = 'block';
newIframe.className = "browser-tab-content-iframe";
tabContent.appendChild(newIframe);
tabContent.style.display = 'block';
rhNewTab.style.display = 'none';
welcome.style = "Display:none;";
addressBar.textContent = " ";
if (activeTab) {
const tabTitleElement = activeTab.querySelector('.chrome-tab-title');
if (tabTitleElement) {
tabTitleElement.textContent = "Dino";
}
}
})
.catch(error => console.error('Error fetching document source:', error));
} else {
// Used when user enters something into address bar
let url = addressBar.textContent.trim();
updateIframe(url);
const newIframe = document.createElement('iframe');
newIframe.src = createURL(url, tabNumber);
newIframe.id = `iframe-num-${tabNumber}`;
newIframe.referpolicy = 'no-referrer';
newIframe.sandbox = 'allow-downloads allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-presentation allow-same-origin allow-scripts';
newIframe.style.display = 'block';
newIframe.className = "browser-tab-content-iframe";
tabContent.appendChild(newIframe);
tabContent.style.display = 'block';
rhNewTab.style.display = 'none';
welcome.style = "Display:none;";
addressBar.textContent = " ";
if (activeTab) {
const tabTitleElement = activeTab.querySelector('.chrome-tab-title');
if (tabTitleElement) {
tabTitleElement.textContent = url;
}
}
}
}
});
function updateIframe(url) {
const activeIframe = document.querySelector(`#iframe-num-${tabNumber}`);
if (activeIframe) {
activeIframe.src = createURL(url);
}
}
function changeTheme(colour) {
const linkElement = document.querySelector('link[rel="stylesheet"]');
if (!linkElement) return; // Guard clause to handle cases where the stylesheet link is not found
const currentHref = linkElement.getAttribute("href");
let newHref;
let fbLogoSrc;
if (colour === "hub") {
newHref = currentHref === "css/browser-style.css" ? "css/orange.css" : "css/browser-style.css";
fbLogoSrc = currentHref === "css/browser-style.css" ? '/img/white_logo.png' : '/img/black_logo.png';
} else {
newHref = currentHref === "css/browser-style.css" ? "css/browser-style-Darkmode.css" : "css/browser-style.css";
fbLogoSrc = currentHref === "css/browser-style.css" ? '/img/white_logo.png' : '/img/black_logo.png';
}
linkElement.setAttribute("href", newHref);
fbLogo.src = fbLogoSrc;
}
$('input[type="checkbox"]').click(function() {
$('input[type="checkbox"]').not(this).prop("checked", false);
var inputValue = $(this).attr("value");
$("." + inputValue).toggle().siblings(".box").hide();
if (inputValue === "normal" || inputValue === "dark" || inputValue === "hub") {
changeTheme(inputValue);
}
});
// New System to select a tab when opened which fixes most of previous issues
const setTab = document.getElementById('tab-num-0');
if (firsttab===true || firsttab===null){
firsttab= true;
console.log("first tab set")
}
setTab.setAttribute('active', '');
activeTab = setTab;
tabNumber = 0;
console.log('Set tab number:', tabNumber);
const existingIframe = document.querySelector(`#iframe-num-${tabNumber}`);
if (existingIframe) {
existingIframe.style.display = 'block';
rhNewTab.style.display = 'none';
tabContent.style.display = 'block';
} else {
rhNewTab.style.display = 'block';
tabContent.style.display = 'none';
};
const urlParams = new URLSearchParams(window.location.search);
const query = urlParams.get('query');
if (query) {
console.log('Query parameter is present:', query);
let url = query
updateIframe(url);
const newIframe = document.createElement('iframe');
newIframe.src = createURL(url, tabNumber);
newIframe.id = `iframe-num-${tabNumber}`;
newIframe.referpolicy = 'no-referrer';
newIframe.sandbox = 'allow-downloads allow-forms allow-modals allow-orientation-lock allow-pointer-lock allow-popups allow-popups-to-escape-sandbox allow-presentation allow-same-origin allow-scripts';
newIframe.style.display = 'block';
newIframe.className = "browser-tab-content-iframe";
tabContent.appendChild(newIframe);
tabContent.style.display = 'block';
rhNewTab.style.display = 'none';
welcome.style = "Display:none;";
addressBar.textContent = " ";
if (activeTab) {
const tabTitleElement = activeTab.querySelector('.chrome-tab-title');
if (tabTitleElement) {
tabTitleElement.textContent = url;
}
}
}
});