-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
73 lines (62 loc) · 2.5 KB
/
script.js
File metadata and controls
73 lines (62 loc) · 2.5 KB
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
const terminal = document.getElementById('terminal');
function addStartupHeader() {
const header = document.createElement('div');
header.innerHTML = `Microsoft Windows [Version 10.0.19045.6036]<br>(c) Microsoft Corporation. All rights reserved.<br><br>`;
terminal.appendChild(header);
}
function createNewLine() {
const line = document.createElement('div');
line.className = 'line';
const prompt = document.createElement('span');
prompt.className = 'prompt';
prompt.textContent = 'C:\\Windows\\System32>';
const input = document.createElement('input');
input.type = 'text';
line.appendChild(prompt);
line.appendChild(input);
terminal.appendChild(line);
input.focus();
input.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
const command = input.value.trim();
handleCommand(command);
input.disabled = true;
createNewLine();
}
});
}
function handleCommand(cmd) {
const output = document.createElement('div');
switch (cmd.toLowerCase()) {
case 'test':
output.textContent = 'This is a test command!';
break;
case 'help':
output.textContent = `---------- Windows CMD Simulator ----------
A simple command prompt simulator styled like the classic Windows CMD interface, built using HTML, CSS, and JavaScript. Type custom commands and see responses inside a terminal-like UI.
Here is a list of all available commands:
| test | Prints a test message |
| help | Shows available commands |
| clear | Clears the terminal |
| time | Returns the current time |
| date | Returns the current date |`;
break;
case 'time':
const time = new Date().toLocaleTimeString('en-US', { hour: '2-digit', minute: '2-digit', second: '2-digit' });
output.textContent = `Current time: ${time} (UTC)`;
break;
case 'date':
const date = new Date().toLocaleDateString('en-US', { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' });
output.textContent = `Current date: ${date} (UTC)`;
break;
case 'clear':
terminal.innerHTML = '';
return;
default:
output.textContent = `'${cmd}' is not recognized as an internal or external command, operable program or batch file.`;
}
terminal.appendChild(output);
terminal.appendChild(document.createElement('br'));
}
addStartupHeader();
createNewLine();