-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
313 lines (264 loc) · 11.7 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
// Array of quotes
const quotes = [
"Hack the planet!",
"There is no security on this earth, only opportunity.",
"The quieter you become, the more you are able to hear.",
"Talk is cheap. Show me the code.",
"In a world of locked doors, the man with the key is king.",
"The first step to securing your data is not giving it out.",
"Access the system, exploit the vulnerability.",
"404 - Inspiration not found. Keep hacking!",
"With great power comes great responsibility… to secure the network.",
"Code hard, hack smart."
];
const quoteDisplay = document.getElementById('quoteDisplay');
// Function to get a random quote
function getRandomQuote() {
const randomIndex = Math.floor(Math.random() * quotes.length);
return quotes[randomIndex];
}
// Function to display the new random quote
function displayNewQuote() {
quoteDisplay.textContent = `"${getRandomQuote()}"`;
}
// Run the display function after the DOM is fully loaded
document.addEventListener('DOMContentLoaded', function () {
displayNewQuote();
});
// script.js
function showAlert() {
const alertMessage = document.getElementById('alertMessage');
const overlay = document.getElementById('overlay');
const customAlert = document.getElementById('customAlert');
alertMessage.innerText = "Welcome To My Profile 👨🏼💻 Still Under CONSTRUCTION ⚠️";
overlay.style.display = 'block'; // Show overlay
customAlert.classList.add('show'); // Trigger slide down and fade in
// Set timeout to fade out the close button after the alert is shown
const closeButton = document.getElementById('closeButton');
setTimeout(() => {
closeButton.classList.add('fade-out'); // Start fade out
}, 3000); // Wait for 3 seconds before fading out
}
function closeAlert() {
const overlay = document.getElementById('overlay');
const customAlert = document.getElementById('customAlert');
const closeButton = document.getElementById('closeButton');
closeButton.classList.remove('fade-out'); // Reset fade out class
overlay.style.display = 'none'; // Hide overlay
customAlert.classList.remove('show'); // Remove the show class
}
// Automatically show the alert when the page loads
window.onload = showAlert;
// Functions
function showSection(id) {
document.querySelectorAll('.content').forEach(section => {
section.classList.remove('active');
});
const targetSection = document.getElementById(id);
targetSection.classList.add('active');
// Custom smooth scroll behavior
const yOffset = -50; // Optional: Offset to account for fixed headers
const yPosition = targetSection.getBoundingClientRect().top + window.pageYOffset + yOffset;
window.scrollTo({
top: yPosition,
behavior: 'smooth'
});
}
function toggleMenu() {
document.querySelector('.navbar').classList.toggle('active');
}
// Click animation effect
document.addEventListener('click', function(e) {
let x = e.clientX;
let y = e.clientY;
let clickEffect = document.createElement('div');
clickEffect.className = 'click-animation';
clickEffect.style.left = `${x}px`;
clickEffect.style.top = `${y}px`;
document.body.appendChild(clickEffect);
setTimeout(() => {
clickEffect.classList.add('active');
setTimeout(() => {
clickEffect.remove();
}, 300);
}, 0);
});
document.getElementById("fullscreen-btn").addEventListener("click", function() {
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) { // Firefox
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) { // Chrome, Safari and Opera
document.documentElement.webkitRequestFullscreen();
} else if (document.documentElement.msRequestFullscreen) { // IE/Edge
document.documentElement.msRequestFullscreen();
}
});
const keys = document.querySelectorAll('.key');
const inputField = document.getElementById('keyboard-input');
// Handle clicks from the virtual keyboard
// Show section with smooth scroll behavior
function showSection(id) {
document.querySelectorAll('.content').forEach(section => {
section.classList.remove('active');
});
const targetSection = document.getElementById(id);
targetSection.classList.add('active');
// Custom smooth scroll behavior
const yOffset = -50; // Optional: Offset for fixed header
const yPosition = targetSection.getBoundingClientRect().top + window.pageYOffset + yOffset;
window.scrollTo({
top: yPosition,
behavior: 'smooth'
});
}
// Toggle navigation menu
function toggleMenu() {
document.querySelector('.navbar').classList.toggle('active');
}
// Scroll indicator logic
window.onscroll = function() {
updateScrollIndicator();
};
function updateScrollIndicator() {
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
const scrollHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
const scrollPercentage = (scrollTop / scrollHeight) * 100;
document.getElementById("scrollIndicator").style.width = scrollPercentage + "%";
}
// Handle key presses from the physical keyboard
// Make sure to refocus input on fullscreen change if needed
document.addEventListener('fullscreenchange', () => {
if (document.fullscreenElement) {
inputField.focus(); // Refocus the input field when entering fullscreen
}
});
// Optional: Check for fullscreen API compatibility
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
}
const fullscreenBtn = document.getElementById('fullscreen-btn');
// Function to toggle fullscreen mode
function toggleFullscreen() {
if (!document.fullscreenElement) {
document.documentElement.requestFullscreen();
} else {
if (document.exitFullscreen) {
document.exitFullscreen();
}
}
}
// Event listener for button click
fullscreenBtn.addEventListener('click', toggleFullscreen);
// Event listener for key press
document.addEventListener('keydown', (event) => {
if (event.key === 'f' || event.key === 'F') {
toggleFullscreen();
}
});
const terminalContent = document.getElementById('terminal-content');
const terminalInput = document.getElementById('terminal-input');
const terminal = document.getElementById('terminal');
// List of available commands with their responses
const commands = {
help: 'Available commands: help, clear, about, exit, ipconfig, git status, ls, pwd, echo, whoami, date, uname',
clear: '',
about: 'This is a simple hacker-themed terminal. Author: Joe6905',
exit: 'Closing terminal...',
ipconfig: `IP Configuration:
IPv4 Address: 192.168.1.2
Subnet Mask: 255.255.255.0
Default Gateway: 192.168.1.1`,
'git status': `On branch main
Your branch is up to date with 'origin/main'.
Nothing to commit, working tree clean`,
ls: `file1.txt
file2.txt
directory1/
directory2/`,
pwd: '/home/user/projects',
echo: 'Echo is a command used to display a line of text.',
whoami: 'You are user.',
date: new Date().toLocaleString(),
uname: 'Operating System: Linux 5.4.0-42-generic'
};
// Function to process and display terminal commands
function processCommand(command) {
let response = '';
// Check if the command exists
if (commands[command]) {
response = commands[command];
// Clear the terminal if 'clear' is entered
if (command === 'clear') {
terminalContent.innerHTML = '';
return;
}
// Close the terminal if 'exit' is entered
if (command === 'exit') {
terminal.style.display = 'none';
return;
}
} else {
// Unknown command
response = `Unknown command: ${command}`;
}
// Append the new command and response to the terminal
appendToTerminal(`$ ${command}`);
appendToTerminal(response);
}
// Function to append new content to the terminal
function appendToTerminal(text) {
const newLine = document.createElement('p');
newLine.classList.add('command-line');
newLine.textContent = text;
terminalContent.appendChild(newLine);
terminalContent.scrollTop = terminalContent.scrollHeight; // Scroll to bottom
}
// Handle Enter key press to display terminal on 'cmd'
document.getElementById('command').addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
const inputValue = event.target.value.toLowerCase();
if (inputValue === 'cmd') {
// Show the terminal
terminal.style.display = 'block';
appendToTerminal('$ Welcome to the hacker terminal.');
event.target.value = ''; // Clear input field
}
}
});
// Handle terminal input and execute commands
document.addEventListener('keydown', function(event) {
if (terminal.style.display === 'block') {
// Capture command input inside the terminal
if (event.key === 'Enter') {
const command = terminalInput.textContent.trim();
if (command) {
processCommand(command);
terminalInput.textContent = ''; // Clear the input line
}
} else if (event.key === 'Backspace') {
terminalInput.textContent = terminalInput.textContent.slice(0, -1); // Handle backspace
} else if (event.key.length === 1) {
terminalInput.textContent += event.key; // Append characters to terminal input
}
}
});
// Make the terminal draggable
const header = document.querySelector(".terminal-header");
let isDragging = false;
let offsetX = 0;
let offsetY = 0;
header.addEventListener('mousedown', function(e) {
isDragging = true;
offsetX = e.clientX - terminal.offsetLeft;
offsetY = e.clientY - terminal.offsetTop;
});
document.addEventListener('mousemove', function(e) {
if (isDragging) {
terminal.style.left = (e.clientX - offsetX) + 'px';
terminal.style.top = (e.clientY - offsetY) + 'px';
}
});
document.addEventListener('mouseup', function() {
isDragging = false;
});