refactor code i wrote while drunk, new api version, skibid toilet slop removed (kino code)

This commit is contained in:
elijah 2024-06-09 20:47:41 +02:00
parent d00387a87a
commit c9dc28a935
4 changed files with 21 additions and 35 deletions

View File

@ -1,12 +1,10 @@
document.addEventListener('contextmenu', function(event) { document.addEventListener('contextmenu', function(event) {
event.preventDefault(); event.preventDefault();
}); });
async function fetchTemperature() { async function fetchTemperature() {
const response = await fetch('https://language.apis.zhr1.infra.elia.network/v1/thoughts/temperature'); const response = await fetch('https://language.apis.zhr1.infra.elia.network/v2/infra/temperature');
return response.text(); return response.text();
} }
async function fetchAndDisplay() { async function fetchAndDisplay() {
const responseDiv = document.querySelector('.response'); const responseDiv = document.querySelector('.response');
const statsDiv = document.querySelector('.stats'); const statsDiv = document.querySelector('.stats');
@ -16,45 +14,34 @@ async function fetchAndDisplay() {
let initialText = responseDiv.textContent; let initialText = responseDiv.textContent;
const eraseDelay = 100; const eraseDelay = 100;
const printDelay = 50; const printDelay = 50;
const statsEraseDelay = 20; const statsEraseDelay = 15;
const statsPrintDelay = 40; const statsPrintDelay = 30;
let lastTemperature = "..."; let lastTemperature = "...";
let lastTemperatureUpdateTime = 0; let lastTemperatureUpdateTime = 0;
const response = await fetch('https://language.apis.zhr1.infra.elia.network/v2/text/generate');
const response = await fetch('https://language.apis.zhr1.infra.elia.network/v1/thoughts/retrieve');
const reader = response.body.getReader(); const reader = response.body.getReader();
const decoder = new TextDecoder('utf-8'); const decoder = new TextDecoder('utf-8');
while (initialText.length > 0) { while (initialText.length > 0) {
initialText = initialText.slice(0, -1); initialText = initialText.slice(0, -1);
responseDiv.textContent = initialText; responseDiv.textContent = initialText;
await new Promise(resolve => setTimeout(resolve, eraseDelay)); await new Promise(resolve => setTimeout(resolve, eraseDelay));
} }
async function updateStatsAndTemperature() { async function updateStatsAndTemperature() {
statsDiv.style.display = 'block';
let currentTime = (performance.now() - startTime) / 1000; let currentTime = (performance.now() - startTime) / 1000;
let charsPerSecond = charCount / currentTime; let charsPerSecond = charCount / currentTime;
if (currentTime - lastTemperatureUpdateTime >= 3) { if (currentTime - lastTemperatureUpdateTime >= 3) {
try { try {
lastTemperature = await fetchTemperature(); lastTemperature = await fetchTemperature();
lastTemperatureUpdateTime = currentTime; lastTemperatureUpdateTime = currentTime;
} catch (error) { } catch (error) {
lastTemperature = "None"; lastTemperature = "...";
} }
} }
statsDiv.textContent = `${charsPerSecond.toFixed(1)} chars/s, ${charCount} chars, ${currentTime.toFixed(1)}s, Temp: ${lastTemperature}°C`; statsDiv.textContent = `${charsPerSecond.toFixed(1)} chars/s, ${charCount} chars, ${currentTime.toFixed(1)}s, Temp: ${lastTemperature}°C`;
} }
async function appendTextSmoothly(textPart) { async function appendTextSmoothly(textPart) {
buffer += textPart; buffer += textPart;
while (buffer.length > 0) { while (buffer.length > 0) {
let pos = buffer.indexOf('**'); let pos = buffer.indexOf('**');
if (pos === 0) { if (pos === 0) {
@ -88,18 +75,14 @@ async function fetchAndDisplay() {
const text = decoder.decode(value, { stream: true }); const text = decoder.decode(value, { stream: true });
await appendTextSmoothly(text); await appendTextSmoothly(text);
} }
let statsText = statsDiv.textContent; let statsText = statsDiv.textContent;
while (statsText.length > 0) { while (statsText.length > 0) {
statsText = statsText.slice(0, -1); statsText = statsText.slice(0, -1);
statsDiv.textContent = statsText; statsDiv.textContent = statsText;
await new Promise(resolve => setTimeout(resolve, statsEraseDelay)); await new Promise(resolve => setTimeout(resolve, statsEraseDelay));
} }
await new Promise(resolve => setTimeout(resolve, 200)); await new Promise(resolve => setTimeout(resolve, 200));
const message = '// video from hartnett media \\\\'; const message = '// credit to hartnett media \\\\';
let messageIndex = 0; let messageIndex = 0;
while (messageIndex < message.length) { while (messageIndex < message.length) {
statsDiv.textContent += message[messageIndex]; statsDiv.textContent += message[messageIndex];
@ -107,9 +90,7 @@ async function fetchAndDisplay() {
await new Promise(resolve => setTimeout(resolve, statsPrintDelay)); await new Promise(resolve => setTimeout(resolve, statsPrintDelay));
} }
} }
document.addEventListener('DOMContentLoaded', fetchAndDisplay); document.addEventListener('DOMContentLoaded', fetchAndDisplay);
console.log(`      ___ console.log(`      ___
         
    | _ _|     | _ _|
@ -120,4 +101,4 @@ console.log(`      ___
|  | | |   |  | | |  
| (_ヽ_)_)  | (_ヽ_)_) 
二つ`); 二つ`);
console.log("hello"); console.log("hello");

Binary file not shown.

View File

@ -39,8 +39,8 @@
} }
.logo { .logo {
font-size: 1.5rem; font-size: 1.5rem;
color: #D68FD6; color: #db7bdb;
text-shadow: 0 0 10px #D68FD6; text-shadow: 0 0 10px #db7bdb;
} }
.nav-links { .nav-links {
list-style: none; list-style: none;
@ -54,10 +54,10 @@
} }
.nav-links a { .nav-links a {
font-size: 1.2rem; font-size: 1.2rem;
color: #D68FD6; color: #db7bdb;
text-decoration: none; text-decoration: none;
transition: color 0.2s ease; transition: color 0.2s ease;
text-shadow: 0 0 3px #D68FD6; text-shadow: 0 0 3px #db7bdb;
pointer-events: initial; pointer-events: initial;
letter-spacing: 1px; letter-spacing: 1px;
} }
@ -91,8 +91,13 @@
transform: translateX(-50%); transform: translateX(-50%);
pointer-events: none; pointer-events: none;
white-space: nowrap; white-space: nowrap;
display: block; display: none;
animation: fadeIn 1s;
} }
@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}
@media (max-width: 600px) { @media (max-width: 600px) {
.navbar { .navbar {
flex-direction: column; flex-direction: column;

View File

@ -20,11 +20,11 @@
<meta property="og:description" content="swiss hosted services"> <meta property="og:description" content="swiss hosted services">
<meta property="og:url" content="https://elia's website"> <meta property="og:url" content="https://elia's website">
<meta property="og:site_name" content="elia's website"> <meta property="og:site_name" content="elia's website">
<meta property="og:image" content="https://elia.li/icons/android-chrome-256x256.png"> <meta property="og:image" content="https://elia.li/icons/favicon-32x32.png">
<meta property="twitter:title" content="elia's website"> <meta property="twitter:title" content="elia's website">
<meta property="twitter:description" content="swiss hosted services"> <meta property="twitter:description" content="swiss hosted services">
<meta property="twitter:card" content="summary_large_image"> <meta property="twitter:card" content="summary_large_image">
<meta property="twitter:image" content="https://elia.li/icons/android-chrome-256x256.png"> <meta property="twitter:image" content="https://elia.li/icons/favicon-32x32.png">
<link rel="icon" type="image/png" href="favicon.png"> <link rel="icon" type="image/png" href="favicon.png">
<link rel="stylesheet" href="assets/style.css"> <link rel="stylesheet" href="assets/style.css">
<title>elia's website</title> <title>elia's website</title>
@ -55,5 +55,5 @@
<span id="temperature">Temp: ...</span> <span id="temperature">Temp: ...</span>
</div> </div>
</body> </body>
<script src="assets/retrieve.js"></script> <script src="assets/api.js"></script>
</html> </html>