forked from Belupeti/scottgpt
175 lines
4.0 KiB
HTML
175 lines
4.0 KiB
HTML
<!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()" style="margin: 0; height: 100%; overflow: hidden;">
|
|
|
|
<div class="main-flexbox">
|
|
|
|
<header class="navbar">
|
|
<a href="https://sc0tt.org/" style="float: left" target="_blank">Sc0tt főoldal</a>
|
|
<a href="/about" style="float: left">About</a>
|
|
<button onclick="genZ()" style="float: left;">Gen Z compatible site</button>
|
|
|
|
<img src="resources/logo.png" alt=logo" style="float: right;">
|
|
|
|
<a href="javascript:void(0);"
|
|
class="icon"
|
|
onclick="toggleMenu()">
|
|
☰
|
|
</a>
|
|
</header>
|
|
|
|
<iframe width="420" height="315"
|
|
src="https://www.youtube.com/embed/mn-Tlb_wfjc"
|
|
id="funniez"
|
|
style="display: none;">
|
|
</iframe>
|
|
|
|
<div id="messages" class="messages">
|
|
|
|
</div>
|
|
|
|
<footer>
|
|
<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>
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script>
|
|
let id;
|
|
|
|
|
|
function genZ() {
|
|
var x = document.getElementById("funniez");
|
|
if (x.style.display === "none") {
|
|
x.style.display = "block";
|
|
} else {
|
|
x.style.display = "none";
|
|
}
|
|
}
|
|
|
|
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;
|
|
|
|
//if (route == "messages") url += '/u';
|
|
|
|
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(3000);
|
|
|
|
if (recursive) fetch_data("messages");
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|