-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
95 lines (86 loc) · 3.1 KB
/
script.js
File metadata and controls
95 lines (86 loc) · 3.1 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
let members = []; // グローバルにメンバーの配列を保持
const terminal = document.getElementById('terminal');
const output = document.getElementById('output');
const input = document.getElementById('input');
// JSONファイルからメンバーデータを読み込む
fetch('./API/members.json')
.then(response => response.json())
.then(data => {
members = data; // データをグローバル変数に格納
console.log('Members data loaded:', members); // デバッグ情報
})
.catch(error => {
console.error('Failed to load members data:', error);
});
input.addEventListener('keyup', function(event) {
if (event.ctrlKey && event.key === 'l') {
event.preventDefault();
output.innerHTML = '';
return;
}
if (event.key === 'Enter') {
event.preventDefault();
const cmd = input.value.trim();
if (cmd !== '') {
const commandOutput = `$ ${cmd}`;
processCommand(cmd, commandOutput);
}
input.value = '';
}
});
function processCommand(cmd, commandOutput) {
let response = '';
const args = cmd.split(' ');
const command = args[0].toLowerCase();
const name = args.slice(1).join(' ');
if (command == 'git') {
response = 'There is not your terminal ;)';
output.innerHTML += `\n${commandOutput}\n${response}`;
return;
}
switch (command) {
case 'help':
response = help.join('\n');
break;
case 'info':
response = info;
break;
case 'qiita':
response = qiita
break
case 'github':
response = github
break
case 'members':
response = members.map(m => m.name).join(', ');
break;
case 'member':
if (name) {
const member = members.find(m => m.name.toLowerCase() === name.toLowerCase());
if (member) {
response = createMemberDetailHTML(member);
output.innerHTML += `\n${commandOutput}\n${response}`;
return;
} else {
response = 'Member not found';
}
} else {
response = 'Please specify a member name.';
}
break;
case 'git':
response = members.map(m => m.name).join(', ');
break;
default:
response = `${cmd}: command not found. Please use help command`;
break;
}
output.innerHTML += `\n${commandOutput}\n${response}`;
}
function createMemberDetailHTML(member) {
return `Name: ${member.name}<br>Twitter: <a href="${member.twitterUrl}" target="_blank">${member.twitterUrl}</a><br>GitHub: <a href="${member.githubUrl}" target="_blank">${member.githubUrl}</a><br>Platforms: ${member.platforms}<br>Bio: ${member.bio}<br><img src="${member.icon}" alt="Icon" style="width: 100px; height: 100px;"><br>`;
}
window.onload = function() {
output.innerHTML = welcomMessage;
input.focus(); // Automatically focus the input field
};