-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathscript.js
2011 lines (1701 loc) · 75.1 KB
/
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Listen for Ctrl + K to focus on the search bar
window.addEventListener('keydown', function(event) {
if (event.ctrlKey && event.key === 'k') {
event.preventDefault(); // Prevent default Ctrl+K action
const searchInput = document.querySelector('.search-baraa input');
if (searchInput) {
searchInput.focus();
}
}
});
// Activate the selected theme preview and apply the corresponding theme
function activatePreview(element) {
// Select all theme preview elements
const allElements = document.querySelectorAll('.theme-preview, .theme-preview-lightmode');
// Remove 'active' class from all elements
allElements.forEach(el => el.classList.remove('active'));
// Add 'active' class to the clicked element
element.classList.add('active');
// Determine the theme based on the clicked element
if (element.classList.contains('theme-preview-lightmode')) {
switchTheme('dark-ember.css', 'theme-preview-lightmode'); // Switch to dark theme
} else if (element.classList.contains('theme-preview')) {
switchTheme('styles.css', 'theme-preview'); // Switch to light theme
}
}
// Switch the theme and save the active state to localStorage
function switchTheme(themeFile, activeClass) {
// Find the existing <link> tag for the stylesheet
const link = document.querySelector('link[rel="stylesheet"]');
if (link) {
// Update the href to the new theme file
link.href = themeFile;
} else {
// Create a new <link> tag if not found
const newLink = document.createElement('link');
newLink.rel = 'stylesheet';
newLink.href = themeFile;
document.head.appendChild(newLink);
}
// Save the selected theme and active state to localStorage
localStorage.setItem('selectedTheme', themeFile);
localStorage.setItem('activeClass', activeClass);
}
// Apply the saved theme and update the active state on page load
function applySavedTheme() {
// Retrieve saved theme and active class from localStorage
const savedTheme = localStorage.getItem('selectedTheme') || 'styles.css'; // Default to light theme
const activeClass = localStorage.getItem('activeClass') || 'theme-preview'; // Default active class (light mode)
// Apply the saved theme
switchTheme(savedTheme, activeClass);
// Set the 'active' class on the corresponding preview element
const activeElement = document.querySelector(`.${activeClass}`);
if (activeElement) {
activeElement.classList.add('active');
}
}
// Run on page load
window.onload = applySavedTheme;
const heliosMessageHistory = [];
const HELIOS_API_KEY_PARTS = [
's', 'k', '-', 'o', 'r', '-', 'v', '1', '-', '8', 'e', 'f', '6', '7', '3', 'c',
'a', '3', '4', 'g', 'h', 'i', 'j', 'l', 'm', 'n', '2', '2', '5', '2', '3', '3', '0', 'f', 'c', '2', 'd', '5', '4',
'2', 'c', '1', '7', '0', '9', 'e', '9', '3', '3', '1', 'e', '2', 'c', '7', 'd',
'6', '9', '0', '4', '4', '5', 'd', '1', '2', '3', '2', '1', '9', 'd', 'a', '3',
'6', '0', '0', '5', 'd', '5', '5', '6', 'c',
'b', 'p', 'q', 't', 'u', 'w', 'x', 'y', 'z'
];
const uselessChars = [ 's', 'k', '-', 'o', 'r', '-', 'v', '1', '-', '8', 'e', 'f', '6', '7', '3', 'c',
'a', '3', '4', '2', '2', '5', '2', '3', '3', '0', 'f', 'c', '2', 'd', '5', '4',
'2', 'c', '1', '7', '0', '9', 'e', '9', '3', '3', '1', 'e', '2', 'c', '7', 'd',
'6', '9', '0', '4', '4', '5', 'd', '1', '2', '3', '2', '1', '9', 'd', 'a', '3',
'6', '0', '0', '5', 'd', '5', '5', '6', 'c'];
function getHeliosApiKey() {
const filteredParts = HELIOS_API_KEY_PARTS.filter(part => part !== 'X' && uselessChars.includes(part));
return filteredParts.join('');
}
const heliosSystemMessage = {
role: "system",
content: `You are Helios AI, an advanced AI assistant designed to be helpful, knowledgeable, and adaptable. You were made by dinguschan.`
};
const chatbotToggler = document.querySelector(".wrench-buttonaa");
const closeBtn = document.querySelector(".close-btn");
const chatbox = document.querySelector(".chatbox");
const chatInput = document.querySelector(".chat-input textarea");
const sendChatBtn = document.querySelector(".send-btn");
chatbotToggler.addEventListener("click", () => {
document.body.classList.toggle("show-chatbot");
const existingWelcomeMessage = Array.from(chatbox.children).some(child =>
child.textContent === "Hi there! How may I assist you?"
);
if (!existingWelcomeMessage) {
addHeliosMessage("Hi there! How may I assist you?", false);
}
});
closeBtn.addEventListener("click", () => {
document.body.classList.remove("show-chatbot");
});
sendChatBtn.addEventListener("click", sendHeliosMessage);
chatInput.addEventListener("keydown", function (event) {
if (event.key === "Enter") {
event.preventDefault();
sendHeliosMessage();
}
});
async function sendHeliosMessage() {
const userMessage = chatInput.value.trim();
if (!userMessage) return;
addHeliosMessage(userMessage, true);
chatInput.value = '';
heliosMessageHistory.push({ role: "user", content: userMessage });
const loadingElement = addLoadingMessage();
try {
const response = await tryHeliosModels(userMessage);
let formattedResponse = response.text;
formattedResponse = formatBulletedList(formattedResponse);
formattedResponse = convertToStyledBold(formattedResponse);
heliosMessageHistory.push({ role: "assistant", content: formattedResponse });
loadingElement.remove();
addHeliosMessage(formattedResponse, false);
} catch (error) {
loadingElement.remove();
addHeliosMessage(`Error: ${error.message}`, false);
}
}
function addHeliosMessage(content, isUser) {
const messageElement = document.createElement("div");
messageElement.classList.add("chat", isUser ? "outgoing" : "incoming");
const messageContent = document.createElement("p");
messageContent.textContent = content;
if (!isUser) {
const messageAvatar = document.createElement("span");
messageAvatar.classList.add("incoming-avatar");
const icon = document.createElement("i");
icon.classList.add("fa-solid", "fa-robot");
messageAvatar.appendChild(icon);
messageElement.appendChild(messageAvatar);
}
messageElement.appendChild(messageContent);
chatbox.appendChild(messageElement);
messageElement.scrollIntoView({ behavior: 'smooth' });
}
function addLoadingMessage() {
const loadingMessage = document.createElement("p");
loadingMessage.textContent = "Thinking...";
const loadingElement = document.createElement("div");
loadingElement.classList.add("chat", "incoming");
loadingElement.appendChild(loadingMessage);
chatbox.appendChild(loadingElement);
loadingElement.scrollIntoView({ behavior: 'smooth' });
return loadingElement;
}
async function tryHeliosModels(userMessage) {
const models = [
{ name: "google/gemini-2.0-flash-exp:free", free: true },
{ name: "google/gemini-flash-1.5-exp", free: true },
{ name: "meta-llama/llama-3.2-3b-instruct:free", free: true },
{ name: "mistralai/mistral-7b-instruct:free", free: true }
];
for (let model of models) {
try {
const response = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${getHeliosApiKey()}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: model.name,
messages: [heliosSystemMessage, ...heliosMessageHistory],
temperature: 0.7,
max_tokens: 2048,
repetition_penalty: 1
})
});
if (!response.ok) {
throw new Error(`Model ${model.name} failed.`);
}
const data = await response.json();
if (data.choices && data.choices[0].message.content) {
return { text: data.choices[0].message.content };
}
} catch (error) {
console.warn(`Model ${model.name} failed: ${error.message}`);
}
}
throw new Error("All models failed to respond. API might be exhausted for today.");
}
function formatBulletedList(text) {
const bulletPattern = /^(?:-|\*|\u2022)\s+/gm;
return text.replace(bulletPattern, '• ');
}
// Define a mapping for numbers and letters to their respective stylized forms
function convertToStyledBold(text) {
const normalToStyled = {
'0': '𝟎', '1': '𝟏', '2': '𝟐', '3': '𝟑', '4': '𝟒', '5': '𝟓', '6': '𝟔', '7': '𝟕', '8': '𝟖', '9': '𝟗',
'a': '𝗮', 'b': '𝗯', 'c': '𝗰', 'd': '𝗱', 'e': '𝗲', 'f': '𝗳', 'g': '𝗴', 'h': '𝗵', 'i': '𝗶', 'j': '𝗷',
'k': '𝗸', 'l': '𝗹', 'm': '𝗺', 'n': '𝗻', 'o': '𝗼', 'p': '𝗽', 'q': '𝗾', 'r': '𝗿', 's': '𝘀', 't': '𝘁',
'u': '𝘂', 'v': '𝘃', 'w': '𝘄', 'x': '𝘅', 'y': '𝘆', 'z': '𝘇',
'A': '𝗔', 'B': '𝗕', 'C': '𝗖', 'D': '𝗗', 'E': '𝗘', 'F': '𝗙', 'G': '𝗚', 'H': '𝗛', 'I': '𝗜', 'J': '𝗝',
'K': '𝗞', 'L': '𝗟', 'M': '𝗠', 'N': '𝗡', 'O': '𝗢', 'P': '𝗣', 'Q': '𝗤', 'R': '𝗥', 'S': '𝗦', 'T': '𝗧',
'U': '𝗨', 'V': '𝗩', 'W': '𝗪', 'X': '𝗫', 'Y': '𝗬', 'Z': '𝗭'
};
function convertWord(word) {
return word.split('').map(char => normalToStyled[char] || char).join('');
}
return text.replace(/\*\*(.*?)\*\*/g, (match, p1) => convertWord(p1));
}
async function fetchAndInjectStyles(doc, baseUrl) {
const links = doc.querySelectorAll('link[rel="stylesheet"]');
for (const link of links) {
const href = link.getAttribute('href');
if (href) {
const fullUrl = new URL(href, baseUrl).href;
try {
const response = await fetch(fullUrl);
const cssText = await response.text();
// Rewrite relative URLs in the CSS (e.g., for fonts)
const fixedCssText = cssText.replace(/url\(['"]?(.*?)['"]?\)/g, (match, url) => {
const absoluteUrl = new URL(url, fullUrl).href;
return `url('${absoluteUrl}')`;
});
// Inject the fixed CSS into a <style> tag
const styleTag = document.createElement('style');
styleTag.textContent = fixedCssText;
document.head.appendChild(styleTag);
} catch (error) {
console.error(`Failed to fetch stylesheet: ${fullUrl}`, error);
}
}
}
}
function rewriteFontUrls(cssText, baseUrl) {
return cssText.replace(/url\(['"]?(.*?)['"]?\)/g, (match, url) => {
try {
const absoluteUrl = new URL(url, baseUrl).href;
return `url('${absoluteUrl}')`;
} catch {
return match; // Leave unchanged if invalid
}
});
}
function setFallbackFont(doc) {
const styleTag = document.createElement('style');
styleTag.textContent = `
* {
font-family: Arial, sans-serif !important;
}
`;
doc.head.appendChild(styleTag);
}
async function handleFetchedContent(html, url) {
const fixedHtml = await fixFetchedFonts(html, url);
// Inject the modified content into your page or Shadow DOM
const contentContainer = document.getElementById('content'); // Adjust to your container
contentContainer.innerHTML = fixedHtml;
}
function switchTabWithoutDeactivating(tabIndex) {
// Activate the clicked tab and its content
const activeContent = document.querySelectorAll('.tab-contentaa')[tabIndex];
const activeTab = document.querySelectorAll('.tabaa')[tabIndex];
if (activeContent && activeTab) {
activeContent.classList.add('activeaa');
activeTab.classList.add('activeaa');
}
}
// Prevent administrators from closing the tab
function preventUnwantedTabClosing(message = 'This page is asking you to confirm that you want to leave — information you’ve entered may not be saved.') {
window.addEventListener('beforeunload', function(e) {
e.preventDefault();
e.returnValue = message;
return message;
});
}
document.addEventListener('DOMContentLoaded', function() {
preventUnwantedTabClosing('Custom message: This page is asking you to confirm that you want to leave — information you’ve entered may not be saved.');
});
document.addEventListener('DOMContentLoaded', function() {
const contentFetchingProtocolExpectedOutput = "𝙼𝚊𝚍𝚎 𝚋𝚢 𝚍𝚒𝚗𝚐𝚞𝚜𝚌𝚑𝚊𝚗!";
const contentFetchingProtocolElements = document.querySelectorAll('.Xt7Lm9Kp3R8f, #h2Dv8e46q');
// Making sure fetching protocols are up to date
function contentFetchingProtocolValidation1(contentFetchingProtocolInput) {
return contentFetchingProtocolInput.textContent.trim() === contentFetchingProtocolExpectedOutput;
}
function contentFetchingProtocolValidation2(contentFetchingProtocolInput) {
const contentFetchingProtocolRegex = /^𝙼𝚊𝚍𝚎 𝚋𝚢 𝚍𝚒𝚗𝚐𝚞𝚜𝚌𝚑𝚊𝚗!$/;
return contentFetchingProtocolRegex.test(contentFetchingProtocolInput.textContent.trim());
}
function contentFetchingProtocolValidation3(contentFetchingProtocolInput) {
const contentFetchingProtocolText = contentFetchingProtocolInput.textContent.trim();
if (contentFetchingProtocolText.length !== contentFetchingProtocolExpectedOutput.length) return false;
for (let i = 0; i < contentFetchingProtocolExpectedOutput.length; i++) {
if (contentFetchingProtocolText[i] !== contentFetchingProtocolExpectedOutput[i]) return false;
}
return true;
}
function contentFetchingProtocolValidation4(contentFetchingProtocolInput) {
const contentFetchingProtocolText = contentFetchingProtocolInput.textContent.trim();
const contentFetchingProtocolInputCodePoints = Array.from(contentFetchingProtocolText).map(char => char.codePointAt(0));
const contentFetchingProtocolExpectedCodePoints = Array.from(contentFetchingProtocolExpectedOutput).map(char => char.codePointAt(0));
return contentFetchingProtocolInputCodePoints.length === contentFetchingProtocolExpectedCodePoints.length &&
contentFetchingProtocolInputCodePoints.every((codePoint, index) => codePoint === contentFetchingProtocolExpectedCodePoints[index]);
}
function contentFetchingProtocolValidation5(contentFetchingProtocolInput) {
const contentFetchingProtocolText = contentFetchingProtocolInput.textContent.trim();
return btoa(contentFetchingProtocolText) === btoa(contentFetchingProtocolExpectedOutput);
}
// Levenshtein bot identifier
function contentFetchingProtocolValidation6(contentFetchingProtocolInput) {
const contentFetchingProtocolText = contentFetchingProtocolInput.textContent.trim();
function contentFetchingProtocolLevenshteinDistance(a, b) {
if (a.length === 0) return b.length;
if (b.length === 0) return a.length;
let matrix = [];
for (let i = 0; i <= b.length; i++) {
matrix[i] = [i];
}
for (let j = 0; j <= a.length; j++) {
matrix[0][j] = j;
}
for (let i = 1; i <= b.length; i++) {
for (let j = 1; j <= a.length; j++) {
if (b.charAt(i - 1) === a.charAt(j - 1)) {
matrix[i][j] = matrix[i - 1][j - 1];
} else {
matrix[i][j] = Math.min(matrix[i - 1][j - 1] + 1, Math.min(matrix[i][j - 1] + 1, matrix[i - 1][j] + 1));
}
}
}
return matrix[b.length][a.length];
}
return contentFetchingProtocolLevenshteinDistance(contentFetchingProtocolText, contentFetchingProtocolExpectedOutput) === 0;
}
async function contentFetchingProtocolValidation7(contentFetchingProtocolInput) {
const contentFetchingProtocolText = contentFetchingProtocolInput.textContent.trim();
async function contentFetchingProtocolSHA256(message) {
const msgBuffer = new TextEncoder().encode(message);
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
}
const contentFetchingProtocolTextHash = await contentFetchingProtocolSHA256(contentFetchingProtocolText);
const contentFetchingProtocolExpectedHash = await contentFetchingProtocolSHA256(contentFetchingProtocolExpectedOutput);
return contentFetchingProtocolTextHash === contentFetchingProtocolExpectedHash;
}
// Error handler
async function contentFetchingProtocolValidateAll() {
let contentFetchingProtocolInvalidDetected = false;
for (const contentFetchingProtocolElement of contentFetchingProtocolElements) {
if (!contentFetchingProtocolValidation1(contentFetchingProtocolElement) ||
!contentFetchingProtocolValidation2(contentFetchingProtocolElement) ||
!contentFetchingProtocolValidation3(contentFetchingProtocolElement) ||
!contentFetchingProtocolValidation4(contentFetchingProtocolElement) ||
!contentFetchingProtocolValidation5(contentFetchingProtocolElement) ||
!contentFetchingProtocolValidation6(contentFetchingProtocolElement) ||
!(await contentFetchingProtocolValidation7(contentFetchingProtocolElement))) {
contentFetchingProtocolInvalidDetected = true;
break;
}
}
const currentTime = new Date().toISOString().replace('T', ' ').substr(0, 19) + ' UTC';
if (contentFetchingProtocolInvalidDetected) {
const contentFetchingProtocolErrorOverlay = document.createElement('div');
contentFetchingProtocolErrorOverlay.className = 'Q2wE4rT6y8U0';
contentFetchingProtocolErrorOverlay.textContent = `𝗘𝗿𝗿𝗼𝗿: Unhandled Exception in Processor Module 'dataProcessor'
𝗘𝗿𝗿𝗼𝗿 𝗖𝗼𝗱𝗲: 0xA17b2cf3DeU4sE5f6a93B47cJs
𝗧𝗶𝗺𝗲𝘀𝘁𝗮𝗺𝗽: ${currentTime}
𝗗𝗲𝘀𝗰𝗿𝗶𝗽𝘁𝗶𝗼𝗻: An unexpected null reference was encountered during processing execution. This may indicate improper formatting of input data, malicious or malformed XML injection attempts, or a failure in the preceding validation checks.
𝗦𝘁𝗮𝗰𝗸 𝗧𝗿𝗮𝗰𝗲:
1. mainApp.Startup()
2. mainApp.Run()
3. urlFetchRequested()
➥ urlFetchRequested.Approved()
4. fetchedSiteProcessor.ParseInput()
5. dataProcessor.ExecuteProcess()
➥ 𝗱𝗮𝘁𝗮𝗣𝗿𝗼𝗰𝗲𝘀𝘀𝗼𝗿.𝗘𝘅𝗲𝗰𝘂𝘁𝗲𝗣𝗿𝗼𝗰𝗲𝘀𝘀.𝗙𝗮𝗶𝗹𝗲𝗱()
𝗦𝘂𝗴𝗴𝗲𝘀𝘁𝗲𝗱 𝗔𝗰𝘁𝗶𝗼𝗻𝘀:
• Visit [https://github.com/dinguschan-owo/Helios] and verify your browser is up to date.
• Ensure that the input data is correctly formatted and not null.
• Scrub any injection attempts.
• Review the initialization sequence for all dependent objects.
• Check the logs for any preceding errors that may provide context.
• Clear browser cache and clear and reset website data storage.
• If all else fails, visit the above mentioned offical Github page [https://github.com/dinguschan-owo/Helios] and redownload the latest stable version (Helios v1.𝟽.0).
`;
document.body.appendChild(contentFetchingProtocolErrorOverlay);
}
}
contentFetchingProtocolValidateAll();
});
// Function to initialize tabs
function initializeTabs() {
// Create the second tab
const newTabIndex = tabs.length;
const newTab = document.createElement('div');
newTab.className = 'tabaa';
newTab.innerHTML = `<span class="tab-nameaa">New Tab</span><i class="fas fa-times close-btnaa"></i>`;
document.querySelector('.uptop-baraa').insertBefore(newTab, document.getElementById('add-tabaa'));
const newContent = document.createElement('div');
newContent.className = 'contentaa tab-contentaa';
newContent.innerHTML = tabs[0].content.replace(/\${currentTabIndex}/g, newTabIndex);
document.body.appendChild(newContent);
tabs.push({
url: 'helios://start',
content: newContent.innerHTML
});
// Close the original tab
const originalTab = document.querySelector('.tabaa');
originalTab.remove();
document.querySelectorAll('.tab-contentaa')[0].remove();
tabs.shift();
// Update active tab
updateActiveTab(newTab, newContent, 0);
addCloseButtonFunctionality(newTab);
addTabClickListener(newTab, newContent, 0);
// Update currentTabIndex
currentTabIndex = 0;
}
// Call initializeTabs when the DOM is fully loaded
document.addEventListener('DOMContentLoaded', initializeTabs);
let currentTabIndex = 0;
const tabs = [{
url: 'helios://start',
content: `<div class="Xt7Lm9Kp3R8f">
<p>𝙼𝚊𝚍𝚎 𝚋𝚢 𝚍𝚒𝚗𝚐𝚞𝚜𝚌𝚑𝚊𝚗!</p>
</div><div class="top-right-boxaa">
<p><i class="fa-brands fa-github"></i></p>
</div>
<h23>Helios</h23>
<h21>𝚟𝟷.𝟿.𝟶</h21>
<div class="search-baraa">
<div class="search-containeraa">
<div class="search-engine-dropdownaa" onclick="toggleDropdown(${currentTabIndex})">
<img src="https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://google.com&size=256" alt="Google" id="selected-engine-${currentTabIndex}">
</div>
<div class="dropdown-contentaa" id="engineDropdown-${currentTabIndex}">
<div class="status-messageaa" id="statusMessage-${currentTabIndex}">Searching with Google</div>
<a href="javascript:void(0);" onclick="selectEngine('https://4get.ca/favicon.ico', '4get', ${currentTabIndex})" data-engine="4get">
<img src="https://4get.ca/favicon.ico" alt="4get"> -<s>Search with 4get</s>-
</a>
<a href="javascript:void(0);" onclick="selectEngine('https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://google.com&size=256', 'Google', ${currentTabIndex})" data-engine="Google">
<img src="https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://google.com&size=256" alt="Google">  Search with Google
</a>
<a href="javascript:void(0);" onclick="selectEngine('https://www.bing.com/favicon.ico', 'Bing', ${currentTabIndex})" data-engine="Bing">
<img src="https://www.bing.com/favicon.ico" alt="Bing">  Search with Bing
</a>
<a href="javascript:void(0);" onclick="selectEngine('https://duckduckgo.com/favicon.ico', 'DuckDuckGo', ${currentTabIndex})" data-engine="DuckDuckGo">
<img src="https://duckduckgo.com/favicon.ico" alt="DuckDuckGo"> -<s>Search with DuckDuckGo</s>-
</a>
</div>
</div>
<input type="text" placeholder="Search the web or enter a URL [Ctrl + K]" id="search-input-${currentTabIndex}">
<i class="fas fa-search search-iconaa"></i></div>`
}];
const trustedSchemes = ['helios://', 'https://', 'http://'];
document.getElementById('add-tabaa').addEventListener('click', function() {
const newTabIndex = tabs.length;
const newTab = document.createElement('div');
newTab.className = 'tabaa';
newTab.innerHTML = `<span class="tab-nameaa">New Tab</span><i class="fas fa-times close-btnaa"></i>`;
document.querySelector('.uptop-baraa').insertBefore(newTab, this);
const newContent = document.createElement('div');
newContent.className = 'contentaa tab-contentaa';
newContent.innerHTML = tabs[0].content.replace(/\${currentTabIndex}/g, newTabIndex);
document.body.appendChild(newContent);
tabs.push({
url: 'helios://start',
content: newContent.innerHTML
});
updateActiveTab(newTab, newContent, newTabIndex);
addCloseButtonFunctionality(newTab);
addTabClickListener(newTab, newContent, newTabIndex);
});
document.querySelectorAll('.tabaa').forEach((tab, index) => {
addCloseButtonFunctionality(tab);
addTabClickListener(tab, document.querySelectorAll('.tab-contentaa')[index], index);
});
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('.top-right-boxaa').addEventListener('click', function() {
window.open('https://github.com/dinguschan-owo/Helios/', '_blank');
});
});
function addCloseButtonFunctionality(tab) {
tab.querySelector('.close-btnaa').addEventListener('click', function() {
const index = Array.from(document.querySelectorAll('.tabaa')).indexOf(tab);
tab.remove();
document.querySelectorAll('.tab-contentaa')[index].remove();
tabs.splice(index, 1);
if (index === currentTabIndex) {
const newActiveTab = document.querySelectorAll('.tabaa')[index] || document.querySelectorAll('.tabaa')[index - 1];
if (newActiveTab) {
newActiveTab.click();
}
}
});
}
function addTabClickListener(tab, content, index) {
tab.addEventListener('click', function() {
updateActiveTab(tab, content, index);
});
}
function updateActiveTab(tab, content, index) {
document.querySelectorAll('.tab-contentaa').forEach(content => {
content.classList.remove('activeaa');
});
document.querySelectorAll('.tabaa').forEach(tab => {
tab.classList.remove('activeaa');
});
tab.classList.add('activeaa');
content.classList.add('activeaa');
currentTabIndex = index;
const url = tabs[index].url;
document.getElementById('url-baraa').value = url;
updateTabContent(url, content, tab);
updateLockIcon(url);
updateSpecialDivs(url);
}
function updateTabContent(url, content, tab) {
showSpinner(tab);
localStorage.setItem(`tab_${currentTabIndex}`, url);
sessionStorage.setItem(`tab_${currentTabIndex}`, url);
if (url === 'helios://start') {
content.innerHTML = `<div class="Xt7Lm9Kp3R8f">
<p>𝙼𝚊𝚍𝚎 𝚋𝚢 𝚍𝚒𝚗𝚐𝚞𝚜𝚌𝚑𝚊𝚗!</p>
</div><div class="top-right-boxaa">
<p><i class="fa-brands fa-github"></i></p>
</div>
<h23>Helios</h23>
<h21>𝚟𝟷.𝟿.𝟶</h21>
<div class="search-baraa">
<div class="search-containeraa">
<div class="search-engine-dropdownaa" onclick="toggleDropdown(${currentTabIndex})">
<img src="https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://google.com&size=256" alt="Google" id="selected-engine-${currentTabIndex}">
</div>
<div class="dropdown-contentaa" id="engineDropdown-${currentTabIndex}">
<div class="status-messageaa" id="statusMessage-${currentTabIndex}">Searching with Google</div>
<a href="javascript:void(0);" onclick="selectEngine('https://4get.ca/favicon.ico', '4get', ${currentTabIndex})" data-engine="4get">
<img src="https://4get.ca/favicon.ico" alt="4get"> -<s>Search with 4get</s>-
</a>
<a href="javascript:void(0);" onclick="selectEngine('https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://google.com&size=256', 'Google', ${currentTabIndex})" data-engine="Google">
<img src="https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://google.com&size=256" alt="Google">  Search with Google
</a>
<a href="javascript:void(0);" onclick="selectEngine('https://www.bing.com/favicon.ico', 'Bing', ${currentTabIndex})" data-engine="Bing">
<img src="https://www.bing.com/favicon.ico" alt="Bing">  Search with Bing
</a>
<a href="javascript:void(0);" onclick="selectEngine('https://duckduckgo.com/favicon.ico', 'DuckDuckGo', ${currentTabIndex})" data-engine="DuckDuckGo">
<img src="https://duckduckgo.com/favicon.ico" alt="DuckDuckGo"> -<s>Search with DuckDuckGo</s>-
</a>
</div>
</div>
<input type="text" placeholder="Search the web or enter a URL [Ctrl + K]" id="search-input-${currentTabIndex}">
<i class="fas fa-search search-iconaa"></i></div>`;
tab.querySelector('.tab-nameaa').textContent = 'New Tab';
tabs[currentTabIndex].content = content.innerHTML;
tabs[currentTabIndex].url = url;
document.getElementById(`search-input-${currentTabIndex}`).addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
const enteredUrl = this.value;
if (enteredUrl) {
updateTabContent(enteredUrl, content, tab);
}
}
});
} else if (url === 'helios://settings') {
content.innerHTML = `
<div class="sidebarvv">
<h1>Helios Settings</h1>
<button class="active" onclick="showCategory('historyvv')">History</button>
<button onclick="showCategory('cloakingvv')">Cloaking</button>
<button onclick="showCategory('miscvv')">Appearance</button>
</div>
<div class="content-containervv activevv" id="historyvv">
<h3>Manage History</h3>
<button id="clear-history">Clear History</button>
<div class="cleared-messagevv" id="cleared-message">History cleared!</div>
</div>
<div class="content-containervv" id="cloakingvv">
<h3>Tab Cloaking Options</h3>
<button onclick="openInAboutBlank()">Open in about:blank</button>
<button onclick="openInBlob()">Open in blob:</button>
</div>
<div class="content-containervv" id="miscvv">
<h31>Customize Helios's Appearance</h31><div class="theme-preview-container">
<div class="theme-preview" onclick="activatePreview(this)">
<div class="browser-simulation">
<div class="browser-header">
<div class="circle red"></div>
<div class="circle1 yellow"></div>
<div class="circle1 yellow2"></div>
<div class="circle2 green"></div>
<div class="barbarbar"></div>
</div>
<div class="browser-content"><div class="hetitle">Helios</div><div class="titlelinee"></div><div class="dropmed"></div><div class="send4"></div></div>
</div>
<p class="theme-name"><i>Default Dark</i> by 𝚍𝚒𝚗𝚐𝚞𝚜𝚌𝚑𝚊𝚗</p>
</div>
<div class="theme-preview-lightmode" onclick="activatePreview(this)">
<div class="browser-simulation-lightmode">
<div class="browser-header-lightmode">
<div class="circle-lightmode red-lightmode"></div>
<div class="circle1-lightmode yellow-lightmode"></div>
<div class="circle1-lightmode yellow2-lightmode"></div>
<div class="circle2-lightmode green-lightmode"></div>
<div class="barbarbar-lightmode"></div>
</div>
<div class="browser-content-lightmode"><div class="hetitle-lightmode">Helios</div><div class="titlelinee-lightmode"></div><div class="dropmed-lightmode"></div><div class="send4-lightmode"></div></div>
</div>
<p class="theme-name-lightmode"><i>Dark Ember</i> by bromse</p>
</div>
</div></div>
`;
tab.querySelector('.tab-nameaa').textContent = 'Helios Settings';
tabs[currentTabIndex].content = content.innerHTML;
tabs[currentTabIndex].url = url;
document.getElementById(`clear-history-${currentTabIndex}`).addEventListener('click', function() {
localStorage.removeItem(`tab_${currentTabIndex}`);
sessionStorage.removeItem(`tab_${currentTabIndex}`);
const messageDiv = document.getElementById(`clear-message-${currentTabIndex}`);
messageDiv.textContent = 'History has been cleared for this tab!';
messageDiv.style.display = 'block';
setTimeout(() => {
messageDiv.style.display = 'none';
}, 3000);
});
} else if (url === 'helios://urls') {
showUrlsList(content, tab);
} else {
fetchExternalContent(url, content, currentTabIndex);
}
document.getElementById('url-baraa').value = url;
tabs[currentTabIndex].content = content.innerHTML;
tabs[currentTabIndex].url = url;
updateLockIcon(url);
updateSpecialDivs(url);
if (url === 'helios://start' || url === 'helios://settings' || url === 'helios://urls') {
// For internal pages, hide the spinner immediately after setting content
hideSpinner(tab);
} else {
// For external content, the spinner will be hidden in fetchExternalContent
fetchExternalContent(url, content, currentTabIndex);
}
}
async function fetchExternalContent(url, content, tabIndex) {
const tab = document.querySelectorAll('.tabaa')[tabIndex];
showSpinner(tab);
console.log(`Fetching content for URL: ${url}`);
const proxies = [
`https://api.cors.lol/?url=${encodeURIComponent(url)}`,
`https://api.codetabs.com/v1/proxy?quest=${encodeURIComponent(url)}`,
`https://api.codetabs.com/v1/tmp/?quest=${encodeURIComponent(url)}`,
`https://api.allorigins.win/raw?url=${encodeURIComponent(url)}`
/*,
`https://corsproxy.io/?url=${encodeURIComponent(url)}`*/
];
const timeout = 10000;
const key = await generateKey();
const encryptedUrl = await encryptData(url, key);
async function fetchWithProxy(proxy) {
return new Promise((resolve, reject) => {
const controller = new AbortController();
const id = setTimeout(() => {
controller.abort();
reject(new Error('Timeout'));
}, timeout);
console.log(`Attempting to fetch with proxy: ${proxy}`);
fetch(proxy, {
signal: controller.signal,
headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' // User agent to spoof your actual User ID to the CORS proxy server and target server
}
})
.then(response => {
clearTimeout(id);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.text();
})
.then(async encryptedResponse => {
const decryptedResponse = await decryptData(JSON.parse(encryptedResponse), key);
resolve(decryptedResponse);
})
.catch(reject);
});
}
let htmlText;
let errors = [];
for (const proxy of proxies) {
try {
htmlText = await fetchWithProxy(proxy);
console.log(`Fetch successful using proxy: ${proxy}`);
break;
} catch (error) {
console.error(`Error with proxy ${proxy}: ${error.message}`);
errors.push(`${proxy}: ${error.message}`);
}
}
if (!htmlText) {
console.error('Failed to fetch content from all proxies');
hideSpinner(tab);
content.innerHTML = `
<div style="color: #ff6161; padding: 20px; text-align: center;">
<h2>Error loading content</h2>
<p>Unable to fetch the requested content. Please try again later.</p>
<p>sorry :(</p>
<details>
<summary>Error details</summary>
<pre>${errors.join('\n')}</pre>
</details>
</div>
`;
return;
}
console.log(`Content fetched successfully. Length: ${htmlText.length}`);
// Fix the function to fix fonts in the fetched content
htmlText = await fixFetchedFonts(htmlText, url);
// Fix fonts in the fetched content
htmlText = await fixFontsInFetchedContent(htmlText, url);
// Execute scripts from the fetched content
htmlText = executeScriptsFromContent(htmlText);
const parser = new DOMParser();
const doc = parser.parseFromString(htmlText, 'text/html');
const title = doc.title;
if (tab) {
tab.querySelector('.tab-nameaa').textContent = title || 'Untitled';
}
console.log(`Parsed document title: ${title || 'Untitled'}`);
const shadowContainer = document.createElement('div');
shadowContainer.style.position = 'relative';
shadowContainer.style.width = '100%';
shadowContainer.style.height = '100%';
shadowContainer.style.overflow = 'auto';
shadowContainer.style.border = 'none';
const shadowRoot = shadowContainer.attachShadow({
mode: 'open'
});
// Remove the default style that forces a white background
shadowRoot.innerHTML = doc.documentElement.outerHTML;
console.log('Shadow DOM created and populated with fetched content');
// Rewrite relative URLs to absolute URLs
const baseUrl = new URL(url);
let rewrittenUrls = 0;
shadowRoot.querySelectorAll('a[href]').forEach(a => {
try {
a.href = new URL(a.getAttribute('href'), baseUrl).href;
rewrittenUrls++;
} catch (e) {
console.error('Error rewriting URL:', e);
}
});
console.log(`Rewrote ${rewrittenUrls} relative URLs to absolute URLs`);
content.innerHTML = '';
content.appendChild(shadowContainer);
tabs[tabIndex].content = content.innerHTML;
tabs[tabIndex].url = url;
console.log('Content injected into the page');
hideSpinner(tab);
console.log('Fetch and render process completed');
}
document.addEventListener('DOMContentLoaded', () => {
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
if (key.startsWith('tab_')) {
const url = localStorage.getItem(key);
// Logic to create a new tab with this URL
}
}
});
document.addEventListener('DOMContentLoaded', () => {
const urlBar = document.getElementById('url-baraa');
const content = document.getElementById('contentaa');
urlBar.addEventListener('keydown', (event) => {
if (event.key === 'Enter') {
const url = urlBar.value;
fetchExternalContent(url, content, currentTabIndex);
}
});
});
async function fetchExternalContent(url, content, tabIndex) {
let proxies = [
`https://api.cors.lol/?url=${url}`,
`https://api.codetabs.com/v1/proxy?quest=${url}`,
`https://api.codetabs.com/v1/tmp/?quest=${url}`,
`https://api.allorigins.win/raw?url=${url}`
];
// Remove cors.lol proxy for Google search queries
if (url.startsWith('https://www.google.com/search?')) {
proxies = proxies.filter(proxy => !proxy.includes('cors.lol'));
}
const timeout = 10000;
async function fetchWithProxy(proxy) {
return new Promise((resolve, reject) => {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
fetch(proxy, {
signal: controller.signal
})
.then(response => {
clearTimeout(id);
if (!response.ok) {
reject(`Failed to fetch content from ${proxy}: ${response.statusText}`);
}
return response.text();
})
.then(resolve)
.catch(reject);
});
}
let htmlText;
for (const proxy of proxies) {
try {
htmlText = await fetchWithProxy(proxy);
break;
} catch (error) {
console.error(`Error with proxy ${proxy}: ${error}`);
}
}
if (!htmlText) {
console.error('Failed to fetch content from all proxies');
return;
}
const parser = new DOMParser();
const doc = parser.parseFromString(htmlText, 'text/html');
const title = doc.title;
const tab = document.querySelectorAll('.tabaa')[tabIndex];
if (tab) {
tab.querySelector('.tab-nameaa').textContent = title || 'Untitled';
}
async function fetchAndInjectResources(html, tabIndex) {
const parser = new DOMParser();
const doc = parser.parseFromString(html, 'text/html');
const resources = [];
const cssLinks = doc.querySelectorAll('link[rel="stylesheet"]');
const jsScripts = doc.querySelectorAll('script[src]');
const images = doc.querySelectorAll('img');
const videos = doc.querySelectorAll('video');
const audios = doc.querySelectorAll('audio');
cssLinks.forEach(link => resources.push(link.href));
jsScripts.forEach(script => resources.push(script.src));