forked from Belupeti/scottgpt
init commit
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>ScottGPT</title>
|
||||
<link rel="icon" type="image/x-icon" href="/resources/favicon.ico">
|
||||
<link rel="stylesheet" href="/resources/style.css">
|
||||
|
||||
</head>
|
||||
<body onload="javascript:init()">
|
||||
|
||||
<div class="navbar" id="myNavbar">
|
||||
<a href="#" style="float: left">ScottGPT</a>
|
||||
<a href="https://sc0tt.org/" style="float: left" target="_blank">Sc0tt főoldal</a>
|
||||
<a href="#" style="float: left">About</a>
|
||||
|
||||
<img src="resources/logo.png" alt=logo" style="float: right;">
|
||||
|
||||
<a href="javascript:void(0);"
|
||||
class="icon"
|
||||
onclick="toggleMenu()">
|
||||
☰
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div class="main-content">
|
||||
<div id="messages" class="messages">
|
||||
|
||||
</div>
|
||||
<div class="textbox-parent">
|
||||
<div class="textbox">
|
||||
<input class="text_input" name="valami" type="text" id="promptText" placeholder="Kérdezz az OSI modellről... vagy idk...">
|
||||
<button class="send_button" onclick="send_data()">send</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let id;
|
||||
|
||||
function sleep(ms) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
async function init()
|
||||
{
|
||||
var oldid = localStorage['ID'] || 'gatya';
|
||||
|
||||
if (oldid != 'gatya')
|
||||
{
|
||||
id = oldid;
|
||||
|
||||
let url = "/api/reinit/" + id
|
||||
|
||||
fetch(url)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then(data => {
|
||||
|
||||
console.log(data.body)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
|
||||
await sleep(1000);
|
||||
fetch_data("all_messages")
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
fetch('/api/init')
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then(data => {
|
||||
|
||||
id = data.toString();
|
||||
|
||||
localStorage['ID'] = data;
|
||||
|
||||
console.log(data.body)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
|
||||
await sleep(1000);
|
||||
|
||||
fetch_data("messages");
|
||||
}
|
||||
}
|
||||
|
||||
async function send_data()
|
||||
{
|
||||
let text = document.getElementById("promptText").value;
|
||||
|
||||
let url = "/api/write/" + id
|
||||
|
||||
fetch(url, {
|
||||
method: "PUT",
|
||||
body: text,
|
||||
headers: {
|
||||
"Content-type": "application/json; charset=UTF-8"
|
||||
}
|
||||
});
|
||||
|
||||
//document.getElementById("promptText").value = "";
|
||||
|
||||
await sleep(10);
|
||||
fetch_data("messages", false);
|
||||
|
||||
}
|
||||
|
||||
async function fetch_data(route, recursive = true)
|
||||
{
|
||||
var url = '/api/' + route + '/' + id
|
||||
|
||||
fetch(url)
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.text();
|
||||
})
|
||||
.then(data => {
|
||||
|
||||
document.getElementById("messages").insertAdjacentHTML("afterbegin", data)
|
||||
|
||||
console.log(data.body)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
});
|
||||
|
||||
await sleep(6000);
|
||||
|
||||
if (recursive) fetch_data("messages");
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<script>
|
||||
function toggleMenu() {
|
||||
let navbar = document.getElementById("myNavbar");
|
||||
navbar.className = navbar.className === "navbar" ?
|
||||
"navbar responsive" : "navbar";
|
||||
}
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user