-
Notifications
You must be signed in to change notification settings - Fork 0
/
lndex.html
132 lines (119 loc) · 4.24 KB
/
lndex.html
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
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1 maximum-scale=1" />
<title>L</title>
<style>
input {
background-color: transparent;
color: white;
border: none;
outline: none;
width: 100%;
}
.user-command::before {
content: '';
color: green;
}
.response::before {
content: 'robin@webserver01:~$ ';
color: white;
}
</style>
<link rel="stylesheet" type="text/css" media="screen" href="css/style_coral.css" />
<link rel="icon" type="image/x-icon" href="imgs/icon.png" />
</head>
<span tabindex="0" id="prevent-outside-tab"></span>
<body>
<div id="terminal">
<a id="before"></a>
</div>
<div id="command" onclick="$('promptInput').focus();">
<textarea
type="text"
id="texter"
onkeyup="typeIt(this, event)"
onkeydown="typeIt(this, event);
moveIt(this.value.length, event)"
onkeypress="typeIt(this, event);"
autofocus
></textarea>
<div id="liner">
<!--<span id="typer"></span><b class="cursor" id="cursor">█</b>-->
</div>
</div>
<a id="after"></a>
<script src="js/github.js"></script>
<script src="js/caret.js"></script>
<script src="js/commands.js"></script>
<script src="js/main.js"></script>
<div id="terminal">
<div class="user-command" id="userCommand"></div>
<div class="response" id="response"></div>
<input type="text" id="promptInput" onkeydown="handleInput(event)">
</div>
<script>
const apiKey = "";
const initialPrompt = "";
document.getElementById('userCommand').innerText = '' + initialPrompt;
function generateResponse() {
const promptInput = document.getElementById('promptInput');
const userCommandDiv = document.getElementById('texter');
const responseDiv = document.getElementById('response');
const userPrompt = promptInput.value;
userCommandDiv.innerHTML += '<div class="texter">' + '</div>';
fetch('/generate-response', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': `Bearer ${apiKey}`,
},
body: `prompt=${encodeURIComponent(userPrompt)}`,
})
.then(response => response.text())
.then(data => {
const formattedResponse = '<div class="response">' + data + '</div>';
responseDiv.innerHTML += formattedResponse;
promptInput.value = '';
scrollToBottom(responseDiv);
})
.catch(error => {
console.error('Error fetching response:', error);
});
}
function handleInput(event) {
if (event.key === 'Enter') {
event.preventDefault();
generateResponse();
logInput(); // Call the logInput function when Enter is pressed
}
}
function scrollToBottom(element) {
element.scrollTop = element.scrollHeight;
}
function logInput() {
const userInput = document.getElementById("promptInput").value;
fetch('/logInput', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ input: userInput })
})
.then(response => {
if (response.ok) {
console.log('User input logged successfully');
} else {
console.error('Error logging user input');
}
})
.catch(error => {
console.error('Error:', error);
});
}
</script>
</body>
<!-- To disable tabbing into the address bar -->
<span tabindex="0" onfocus="focusTextArea()"></span>
</html>