-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
1479 lines (1294 loc) · 48.6 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
//------------------------------------- MAIN VARIABLES -------------------------------------------------------------- //
const terminal = document.getElementById('terminal');
const output = document.getElementById('output');
const inputLine = document.getElementById('input-line');
const commandLine = document.getElementById('command-line');
const rootUserForm = document.getElementById('root-user-form');
const createRootUserButton = document.getElementById('create-root-user');
let audio;
let currentSong = '';
let endOfSongDisplayed = false;
let isInputFocused = false;
let commandHistory = JSON.parse(localStorage.getItem('commandHistory')) || [];
let historyIndex = -1;
let rootUser = JSON.parse(localStorage.getItem('rootUser'));
let cmatrixRunning = false;
let cmatrixInterval;
//------------------------------------- KEYBOARD INPUT KEY : / -------------------------------------------------------------- //
document.addEventListener('keydown', function (event) {
if (event.key === '/' && event.target.tagName !== 'INPUT') {
event.preventDefault(); // Prevent the default action of the key
document.getElementById('command-line').focus();
}
});
//------------------------------------- ROOT PART DONT TOUCH -------------------------------------------------------------- //
document.addEventListener("DOMContentLoaded", function () {
// Check if ROOT user exists in localStorage
if (!rootUser) {
terminal.style.display = 'none';
rootUserForm.style.display = 'flex';
taskbar.style.display = 'none'; // Hide the taskbar if root user doesn't exist
} else {
rootUserForm.style.display = 'none';
terminal.style.display = 'block';
updatePrompt();
taskbar.style.display = 'block'; // Show the taskbar if root user exists
}
createRootUserButton.addEventListener('click', () => {
const rootUsername = document.getElementById('root-username').value.trim();
const rootPassword = document.getElementById('root-password').value.trim();
// Regular expression to match single-word usernames
const singleWordRegex = /^[a-zA-Z]+$/;
if (rootUsername && rootPassword) {
if (!singleWordRegex.test(rootUsername)) {
alert('Please input a single word for the username without any additional numbers or symbols.');
return; // Exit the function if the username format is incorrect
}
// Make the output area visible
outputjs.style.display = 'block';
// Displaying "Creating ROOT User..." message
// Array of texts to display
const texts = [
"− Setting up environment...",
"− Configuring system...",
"− Installing packages...",
"− Applying settings...",
"− Initializing system...",
"− Creating user profiles...",
"− Optimizing performance...",
"− Loading essential components...",
"− Configuring network settings...",
"− Setting up security protocols...",
"− Checking system integrity...",
"− Applying updates...",
"⁂ Finalizing setup & 🗑 Removing all messages...",
];
// Function to display text with animation and delay
function displayTextWithAnimationAndDelay(outputElement, text, delay) {
setTimeout(() => {
// Make the output area visible
outputElement.style.display = 'block';
// Displaying text
outputElement.innerHTML = `<div class="animation">${text}</div>`;
// Set timeout to hide the text after 8 seconds
setTimeout(() => {
// Hide the text after 8 seconds
outputElement.innerHTML = '';
outputElement.style.display = 'none';
}, 8000);
}, delay);
}
// Display each text with animation and delay
texts.forEach((text, index) => {
displayTextWithAnimationAndDelay(document.getElementById(`outputjs${index + 2}`), text, (index + 1) * 500);
});
setTimeout(() => {
// After 8 seconds, proceed to log in
rootUser = { username: rootUsername, password: rootPassword };
localStorage.setItem('rootUser', JSON.stringify(rootUser));
rootUserForm.style.display = 'none';
terminal.style.display = 'block';
updatePrompt();
taskbar.style.display = 'block'; // Show the taskbar after root user is created
}, 8000); // 8000 milliseconds = 8 seconds
} else {
alert('Please enter both username and password.');
}
});
});
commandLine.addEventListener('keydown', function (event) {
if (event.key === 'Enter') {
const command = commandLine.value.trim();
if (command !== '') {
displayCommand(command);
commandHistory.push(command);
localStorage.setItem('commandHistory', JSON.stringify(commandHistory));
historyIndex = -1;
executeCommand(command);
}
commandLine.value = '';
} else if (event.key === 'ArrowUp') {
event.preventDefault();
if (historyIndex < commandHistory.length - 1) {
historyIndex++;
commandLine.value = commandHistory[commandHistory.length - 1 - historyIndex];
}
} else if (event.key === 'ArrowDown') {
event.preventDefault();
if (historyIndex > 0) {
historyIndex--;
commandLine.value = commandHistory[commandHistory.length - 1 - historyIndex];
} else {
historyIndex = -1;
commandLine.value = '';
}
}
});
function displayCommand(command) {
if (command !== 'clear') {
output.innerHTML += `<div>${rootUser.username}@frostOS:~$ ${command}</div>`;
}
terminal.scrollTop = terminal.scrollHeight;
}
function executeCommand(command) {
const args = command.split(' ');
const mainCommand = args[0].toLowerCase();
const params = args.slice(1);
switch (mainCommand) {
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// CLEAR COMMAND
case 'clear':
clearTerminal();
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// PASSWD COMMAND
case 'passwd':
if (params.length === 1) {
const newPassword = params[0];
changePassword(newPassword);
} else {
output.innerHTML += `<div>Usage: passwd [new-password]</div>`;
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// ECHO COMMAND
case 'echo':
if (params.length > 0) {
let message = '';
if (params[0] === '$SHELL') {
message = '/bin/bash'; // Default shell path
} else {
message = params.join(' '); // If not a special variable, echo the message
}
output.innerHTML += `<div>${message}</div>`;
} else {
output.innerHTML += `<div>Usage: echo [message|$SHELL]</div>`;
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// CD COMMAND
case 'cd':
if (params.length === 1) {
changeDirectory(params[0]);
} else {
output.innerHTML += `<div>Usage: cd [directory]</div>`;
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// LS COMMAND
case 'ls':
listDirectory();
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// OPEN COMMAND
case 'open':
if (params.length === 1) {
const target = params[0];
if (currentDirectory === '/github' && target === 'frostos') {
window.open('https://github.com/fr0st-iwnl/frostos', '_blank');
} else {
output.innerHTML += `<div>No such target to open: ${target}</div>`;
}
} else {
output.innerHTML += `<div>Usage: open [target]</div>`;
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// CAT COMMAND
case 'cat':
if (params.length === 1) {
const target = params[0];
if (currentDirectory === '/github' && target === 'README.txt') {
output.innerHTML += `
<div>To preview the source code of FrostOS :</div>
<div>Use the open command to display the frostOS repo [open frostos]</div>
`;
} else {
output.innerHTML += `<div>No such target to read: ${target}</div>`;
}
} else {
output.innerHTML += `<div>Usage: cat [target]</div>`;
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// HELP COMMAND
case 'help':
displayCategorizedHelp();
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// NEOFETCH COMMAND
case 'neofetch':
neofetch();
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// PLAY SONG COMMAND
case 'play':
if (params.length > 0) {
playMusic(params.join(' '));
} else {
output.innerHTML += `<div>Usage: play [song]</div>`;
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// STOP SONG COMMAND
case 'stop':
stopMusic();
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// PAUSE SONG COMMAND
case 'pause':
pauseMusic();
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// VOLUME SONG COMMAND
case 'volume':
if (params.length > 0) {
const volumeLevel = parseFloat(params[0]);
setVolume(volumeLevel);
} else {
output.innerHTML += `<div>Usage: volume [level] (0.0 - 1.0)</div>`;
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// SEARCH COMMAND
case 'search':
if (params.length > 0) {
const query = params.join(' ');
output.innerHTML += `<div>Searching with DuckDuckGo for "${query}"...</div>`;
searchDuckDuckGo(query);
} else {
output.innerHTML += `<div>Usage: search [query]</div>`;
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// WHOAMI COMMAND
case 'whoami':
displayCurrentUser();
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// CMATRIX COMMAND
case 'cmatrix':
toggleCmatrix();
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// REBOOT COMMAND
case 'reboot':
rebootSystem();
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// EXIT COMMAND
case 'exit':
endGame();
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// CALC COMMAND
case 'calc':
if (params.length === 1) {
const expression = params[0];
calculate(expression);
} else {
output.innerHTML += `<div>Usage: calc [expression]</div>`;
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// DELUSER COMMAND
case 'deluser':
handleDelUserCommand(command);
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// NSLOOKUP COMMAND
case 'nslookup':
if (params.length === 1) {
performNslookup(params[0]);
} else {
output.innerHTML += `<div>Usage: nslookup [domain]</div>`;
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// HANGMAN GAME COMMAND
case 'hangman':
// Select a random word
word = wordList[Math.floor(Math.random() * wordList.length)];
guessedLetters = [];
incorrectGuesses = 0;
displayHangman();
output.innerHTML += 'Word: ' + displayWord() + '<br>';
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// GUESS COMMAND FOR HANGMAN
case 'guess':
if (!word) {
output.innerHTML += 'Please start the game first using the "starthangman" command.<br>';
break;
}
const letter = prompt('Enter a letter to guess:');
if (letter && letter.length === 1 && letter.match(/[a-z]/i)) {
handleGuess2(letter.toLowerCase());
} else {
output.innerHTML += 'Please enter a valid letter.<br>';
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// THEME COMMAND
case 'theme':
if (params.length > 0) {
changeTheme(params[0]);
} else {
output.innerHTML += `<div>Usage: theme [theme-name]</div>`;
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// GUESSING GAME COMMAND
case 'guessinggame':
startGuessingGame();
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
// DEFAULT ERROR COMMAND NOT FOUND
default:
if (!gameIsRunning) {
output.innerHTML += `<div>bash: ${mainCommand}: command not found</div>`;
} else {
// If the game is running, handle the user's guess
handleGuess(mainCommand);
}
break;
//-------------------------------------------------------------------------------------------------------------------------------------------------------//
}
terminal.scrollTop = terminal.scrollHeight;
}
//------------------------------------------------------------ GAME 1 ------------------------------------------------------------------------------ //
let gameIsRunning = false;
let randomNumber;
function startGuessingGame() {
gameIsRunning = true;
randomNumber = Math.floor(Math.random() * 100) + 1;
output.innerHTML += `<div>Guess a number between 1 and 100:</div>`;
}
function handleGuess(command) {
const guess = parseInt(command);
if (!isNaN(guess)) {
if (guess === randomNumber) {
output.innerHTML += `<div>Congratulations! You guessed the number ${randomNumber} correctly!</div>`;
gameIsRunning = false;
} else if (guess < randomNumber) {
output.innerHTML += `<div>Your guess (${guess}) is too low. Try again:</div>`;
} else {
output.innerHTML += `<div>Your guess (${guess}) is too high. Try again:</div>`;
}
} else {
output.innerHTML += `<div>Please enter a valid number:</div>`;
}
}
//------------------------------------------------------------ GAME 2 ------------------------------------------------------------------------------ //
const wordList = ['frostos', 'javascript', 'programming', 'terminal', 'templeos', 'developer'];
// select a random word from the list
let word = '';
// initial states of the game
let guessedLetters = [];
let incorrectGuesses = 0;
const maxIncorrectGuesses = 6; // number of parts (incorrect guesses)
// output terminal (dont create a normal output like e.g const output because it already exists)
const output2 = document.getElementById('output');
// pre tags for hangmanParts
function displayHangman() {
const hangmanParts = [
`<pre>
________
| |
|
|
|
|
|
|
__|______
| |
</pre>`,
`<pre>
________
| |
| O
|
|
|
|
|
__|______
| |
</pre>`,
`<pre>
________
| |
| O
| |
|
|
|
|
__|______
| |
</pre>`,
`<pre>
________
| |
| O
| /|
|
|
|
|
__|______
| |
</pre>`,
`<pre>
________
| |
| O
| /|\\
|
|
|
|
__|______
| |
</pre>`,
`<pre>
________
| |
| O
| /|\\
| /
|
|
|
__|______
| |
</pre>`,
`<pre>
________
| |
| O
| /|\\
| / \\
|
|
|
__|______
| |
</pre>`
];
output.innerHTML = hangmanParts[incorrectGuesses];
}
function displayWord() {
let displayedWord = '';
for (let char of word) {
if (guessedLetters.includes(char)) {
displayedWord += char + ' ';
} else {
displayedWord += '_ ';
}
}
return displayedWord;
}
// Function to handle user guesses WATCH OUT FOR HANDLEGUESS FUNCTIONS!
function handleGuess2(letter) {
if (!word.includes(letter)) {
incorrectGuesses++;
}
guessedLetters.push(letter);
// display the current state of the game (update status)
displayHangman();
output.innerHTML += 'Word: ' + displayWord() + '<br>';
if (displayWord().replace(/ /g, '') === word) {
output.innerHTML += 'Congratulations! You guessed the word: ' + word + '<br>';
} else if (incorrectGuesses >= maxIncorrectGuesses) {
output.innerHTML += 'Sorry, you lose! The word was: ' + word + '<br>';
}
}
function endGame() {
if (word || gameIsRunning) {
word = '';
guessedLetters = [];
incorrectGuesses = 0;
gameIsRunning = false;
output.innerHTML += `<div>Game ended.</div>`;
} else {
output.innerHTML += `<div>No game is currently running.</div>`;
}
}
//------------------------------------- CMATRIX -------------------------------------------------------------- //
function toggleCmatrix() {
if (cmatrixRunning) {
stopCmatrix();
cmatrixRunning = false;
} else {
startCmatrix();
cmatrixRunning = true;
}
}
function startCmatrix() {
output.innerHTML = '';
// Set up cmatrix animation
const matrixChars = ['0', '1']; // Characters for the animation
let matrixRowCount = 10; // Number of rows for normal screens
let matrixColCount = 130; // Number of columns for normal screens
const speed = 100; // Animation speed in milliseconds
// Check if the screen width is below a certain threshold (for example, 600px)
if (window.innerWidth <= 600) {
matrixRowCount = 10; // Set number of rows to 1 for low-resolution screens
matrixColCount = 30; // Set number of columns to 30 for low-resolution screens
}
const matrix = Array.from({ length: matrixRowCount }, () => []);
for (let row = 0; row < matrixRowCount; row++) {
for (let col = 0; col < matrixColCount; col++) {
matrix[row][col] = matrixChars[Math.floor(Math.random() * matrixChars.length)];
}
}
function updateMatrix() {
for (let row = matrixRowCount - 1; row > 0; row--) {
matrix[row] = matrix[row - 1];
}
matrix[0] = matrix[0].map(() => matrixChars[Math.floor(Math.random() * matrixChars.length)]);
const matrixOutput = matrix.map(row => row.join('')).join('\n');
output.textContent = matrixOutput;
}
cmatrixInterval = setInterval(updateMatrix, speed);
}
function stopCmatrix() {
clearInterval(cmatrixInterval);
cmatrixInterval = null;
output.innerHTML = '';
}
//------------------------------------- DELUSER -------------------------------------------------------------- //
function deleteRootUser() {
localStorage.removeItem('rootUser');
}
// Function to handle deluser command
function handleDelUserCommand(command) {
if (command === 'deluser') {
if (confirm("Are you sure you want to delete the root user?")) {
deleteRootUser();
window.location.reload(); // Refresh the page
}
return true;
}
return false; // Command not handled
}
//------------------------------------- NSLOOKUP FUNCTION -------------------------------------------------------------- //
async function performNslookup(domain) {
// Remove protocol if present
domain = domain.replace(/^https?:\/\//, '');
const apiUrl = `https://dns.google/resolve?name=${domain}`;
try {
const response = await fetch(apiUrl);
const data = await response.json();
if (data.Status === 0 && data.Answer) {
data.Answer.forEach(answer => {
output.innerHTML += `<div>${answer.name} - ${getTypeName(answer.type)} - ${answer.data}</div>`;
});
} else {
output.innerHTML += `<div>No DNS records found for ${domain}</div>`;
}
} catch (error) {
output.innerHTML += `<div>Error performing nslookup: ${error.message}</div>`;
}
terminal.scrollTop = terminal.scrollHeight;
}
function getTypeName(type) {
switch (type) {
case 1:
return 'A';
case 2:
return 'NS';
case 5:
return 'CNAME';
case 6:
return 'SOA';
case 12:
return 'PTR';
case 15:
return 'MX';
case 16:
return 'TXT';
case 28:
return 'AAAA';
default:
return type;
}
}
function displayCurrentUser() {
output.innerHTML += `<div>${rootUser.username}</div>`;
}
//------------------------------------- CALCULATE FUNCTION -------------------------------------------------------------- //
function calculate(expression) {
try {
const result = eval(expression);
output.innerHTML += `<div>${expression} = ${result}</div>`;
} catch (error) {
output.innerHTML += `<div>Error: ${error}</div>`;
}
}
//------------------------------------- REBOOT FUNCTION -------------------------------------------------------------- //
function rebootSystem() {
clearTerminal();
const lockedScreen = document.createElement('div');
lockedScreen.innerHTML = `
<div style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: flex; justify-content: center; align-items: center;">
<div style="text-align: center; color: white; padding: 20px;">
<h2>System is rebooting.</h2>
<p>Please wait while the system reboots...</p>
</div>
</div>
`;
document.body.appendChild(lockedScreen);
setTimeout(() => {
lockedScreen.remove();
output.innerHTML += `<div>Rebooting system...</div>`;
setTimeout(() => {
location.reload();
}, 2000);
}, 2000);
}
//------------------------------------- CHANGE DIRECTORY FUNCTION -------------------------------------------------------------- //
function changeDirectory(directory) {
if (directory === 'github') {
currentDirectory = '/github'; // Update current directory path
updatePrompt(); // Update the prompt to display the new path
} else if (directory === '../') {
currentDirectory = '~'; // Navigate to the parent directory (home directory)
updatePrompt(); // Update the prompt to display the new path
} else if (directory === 'frostos') {
output.innerHTML += `<div>bash: cd: ${directory}: Folder is locked.</div>`;
currentDirectory = '/github'; // Update current directory path
updatePrompt(); // Update the prompt to display the new path
}
else {
output.innerHTML += `<div>bash: cd: ${directory}: No such file or directory</div>`;
}
}
let currentDirectory = '~'; // main home directory
//------------------------------------- LIST DIRECTORY FUNCTION -------------------------------------------------------------- //
function listDirectory() {
if (currentDirectory === '/github') {
output.innerHTML += `
<div><span style="color: #94b113;">* 📂 frostos</span></div>
<div><span style="color: #5baeb5;">* 📄 README.txt</span></div>
`;
} else if (currentDirectory === '~') {
output.innerHTML += `
<div><span style="color: #458588;">📁 github</span></div>
`;
} else {
output.innerHTML += `<div>${rootUser.username}@frostOS:${currentDirectory}$</div>`;
}
}
//------------------------------------- OPEN FILE OR DIRECTORY FUNCTION-------------------------------------------------------------- //
function openFileOrDirectory(name) {
if (currentDirectory === 'github') {
if (name === 'github') {
window.open('https://github.com', '_blank');
} else if (name === 'source') {
window.open('https://github.com/your-repository-name/your-file-path', '_blank');
} else {
output.innerHTML += `<div>bash: open: ${name}: No such file or directory</div>`;
}
} else {
output.innerHTML += `<div>bash: open: ${name}: No such file or directory</div>`;
}
}
//------------------------------------- NEOFETCH FUNCTION-------------------------------------------------------------- //
function neofetch() {
const resolution = `${window.screen.width}x${window.screen.height}`;
// Specific ASCII art
const asciiArt = `
<pre>
______ __ ____ _____
/ ____/________ _____/ /_/ __ \\/ ___/
/ /_ / ___/ __ \\/ ___/ __/ / / /\\__ \\
/ __/ / / / /_/ (__ ) /_/ /_/ /___/ /
/_/ /_/ \\____/____/\\__/\\____//____/
</pre>
`;
// Get the user's operating system
let os;
const platform = navigator.platform.toLowerCase();
if (platform.includes('win')) {
os = 'Windows';
} else if (platform.includes('mac')) {
os = 'Mac OS';
} else if (platform.includes('linux')) {
os = 'Linux';
} else if (platform.includes('iphone') || platform.includes('ipad')) {
os = 'iOS';
} else if (platform.includes('android')) {
os = 'Android';
} else {
os = 'Unknown';
}
// Get the kernel based on the browser
let kernel;
const userAgent = navigator.userAgent.toLowerCase();
if (userAgent.indexOf('firefox') !== -1) {
kernel = 'Firefox (Gecko)';
} else if (userAgent.indexOf('chrome') !== -1 || userAgent.indexOf('chromium') !== -1) {
kernel = 'Chrome (Blink)';
} else {
kernel = 'Webkit';
}
// Calculate the uptime since the user has been on the website
const now = new Date();
const loadTime = new Date(performance.timing.navigationStart);
const uptimeMilliseconds = now - loadTime;
const hours = Math.floor(uptimeMilliseconds / (1000 * 60 * 60));
const minutes = Math.floor((uptimeMilliseconds % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((uptimeMilliseconds % (1000 * 60)) / 1000);
const uptime = `${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}:${seconds < 10 ? '0' + seconds : seconds}`;
// Get the selected theme from localStorage
const selectedTheme = localStorage.getItem('selectedTheme') || 'gruvbox';
const theme = themes[selectedTheme];
// Neofetch output with specific ASCII art and theme information
const neofetchOutput = `
<div class="neofetch-container">
<div class="ascii-art-neofetch">
${asciiArt}
</div>
<pre>
<code>
┌──────────────────────────────────────┐
<b><i class="fa-light fa-computer"></i> OS</b>: ${os}
<b><i class="fa-brands fa-hive"></i> Host</b>: Netlify
<b><i class="fa-solid fa-cloud-binary"></i> Kernel</b>: ${kernel}
<b><i class="fa-solid fa-timer"></i> Uptime</b>: ${uptime}
<b><i class="fa-solid fa-high-definition"></i> Resolution</b>: ${resolution}
<b><i class="fa-solid fa-crab"></i> Shell</b>: /bin/bash
<b><i class="fa-solid fa-roller-coaster"></i> Theme</b>: ${selectedTheme}
<b><i class="fa-solid fa-terminal"></i> Terminal</b>: kitty (web-based)
<b><i class="fa-light fa-rectangle-terminal"></i> Terminal Font</b>: Monospace
└────────────────────<b style="color: #7c6f64; font-size: 1.29em; padding: 0.1em;">x</b><b style="color: #cc241d; font-size: 1.29em; padding: 0.1em;">x</b><b style="color: #98971a; font-size: 1.29em; padding: 0.1em;">x</b><b style="color: #98971a; font-size: 1.29em; padding: 0.1em;">x</b><b style="color: #458588; font-size: 1.29em; padding: 0.1em;">x</b><b style="color: #b16286; font-size: 1.29em; padding: 0.1em;">x</b><b style="color: #689d6a; font-size: 1.29em; padding: 0.1em;">x</b><b style="color: #bdae93; font-size: 1.29em; padding: 0.1em;">x</b>─────┘
</code>
</pre>
</div>
`;
output.innerHTML += neofetchOutput;
terminal.scrollTop = terminal.scrollHeight;
}
//------------------------------------- PLAY MUSIC FUNCTION -------------------------------------------------------------- //
function playMusic(song) {
const songPaths = {
'algysxx': './songs/algysxx.mp3',
'dazies': './songs/dazies.mp3',
'theendoftheworld': './songs/theendoftheworld.mp3',
'econyalu2008': './songs/econyalu2008.mp3',
'takingdrugs': './songs/takingdrugs.mp3',
'stylerz04': './songs/stylerz04.mp3',
'handsonthewheel': './songs/handsonthewheel.mp3',
'yng16': './songs/yng16.mp3',
'yourlove': './songs/yourlove.mp3',
};
const songPath = songPaths[song];
if (!songPath) {
output.innerHTML += `<div>Song not found: ${song}</div>`;
terminal.scrollTop = terminal.scrollHeight;
return;
}
if (audio) {
audio.pause();
audio.currentTime = 0;
audio.removeEventListener('ended', handleAudioEnd);
audio.removeEventListener('timeupdate', updateSongInfo);
endOfSongDisplayed = false;
}
audio = new Audio(songPath);
audio.volume = 0.1; // Set volume to 0.1
audio.play().catch(function (error) {
output.innerHTML += `<div>Error playing ${song}: ${error}</div>`;
terminal.scrollTop = terminal.scrollHeight;
});
audio.addEventListener('ended', handleAudioEnd);
audio.addEventListener('timeupdate', updateSongInfo);
currentSong = song;
terminal.scrollTop = terminal.scrollHeight;
}
function handleAudioEnd() {
if (!endOfSongDisplayed) {
output.innerHTML += `<div>Song ended: ${currentSong}</div>`;
endOfSongDisplayed = true;
terminal.scrollTop = terminal.scrollHeight;
}
}
let lastProgressBarUpdate = 0;
const progressBarUpdateInterval = 1000; // update progress bar every 1 sec
function updateSongInfo() {
if (!cmatrixRunning) {
const currentTime = formatTime(audio.currentTime);
const duration = formatTime(audio.duration);
const progressBar = generateProgressBar(audio.currentTime, audio.duration);
const now = Date.now();
// check if its time to update the progress bar
if (now - lastProgressBarUpdate >= progressBarUpdateInterval) {
const songInfoDiv = document.getElementById('song-info');
if (!songInfoDiv) {
const newSongInfoDiv = document.createElement('div');
newSongInfoDiv.id = 'song-info';
output.appendChild(newSongInfoDiv);
}
const songInfoContent = `
<div>Now playing: ${currentSong}</div>
<div>${currentTime} —${progressBar} ${duration}</div>
`;
document.getElementById('song-info').innerHTML = songInfoContent;
lastProgressBarUpdate = now;
}
}
}
function formatTime(time) {
const minutes = Math.floor(time / 60);
const seconds = Math.floor(time % 60);
return `${padZero(minutes)}:${padZero(seconds)}`;
}
function padZero(num) {
return num < 10 ? `0${num}` : num;
}
function generateProgressBar(currentTime, duration) {
const progress = (currentTime / duration) * 100;
const progressBar = '—'.repeat(Math.floor(progress / 2)) + '◦' + '—'.repeat(Math.floor((100 - progress) / 2));
return progressBar;
}
function stopMusic() {
if (audio) {
audio.pause();
audio.currentTime = 0;
audio.removeEventListener('ended', handleAudioEnd);
audio.removeEventListener('timeupdate', updateSongInfo);
output.innerHTML += `<div>Music stopped.</div>`;
terminal.scrollTop = terminal.scrollHeight;
const songInfoDiv = document.getElementById('song-info');
if (songInfoDiv) {
songInfoDiv.remove();
}
}
}
function pauseMusic() {
if (audio && !audio.paused) {
audio.pause();
output.innerHTML += `<div>Music paused.</div>`;
} else if (audio && audio.paused) {
audio.play().catch(function (error) {
output.innerHTML += `<div>Error resuming music: ${error}</div>`;
});
output.innerHTML += `<div>Music resumed.</div>`;
} else {
output.innerHTML += `<div>No music is currently playing.</div>`;
}
terminal.scrollTop = terminal.scrollHeight;
}
function setVolume(level) {