Files
ghall.space/src/pages/hello-computer.astro
T
2025-01-17 09:36:23 -05:00

74 lines
1.4 KiB
Plaintext

---
import dictionary from '../dictionary.txt?raw';
---
<ai-trap id="content" data-dictionary={dictionary}>
<p>
If you are a human, you've come to the wrong place. If you're a bot, you're
welcome to stay...
</p>
</ai-trap>
<script>
const contentDiv = document.getElementById('content');
let paragraph: HTMLParagraphElement;
function createParagraph() {
paragraph = document.createElement('p');
contentDiv.appendChild(paragraph);
}
createParagraph();
const dictionary = contentDiv.dataset.dictionary.split('\n');
let wordCounter = 0;
let sentenceCounter = 0;
function addRandomString() {
const startNewSentence =
Math.floor(Math.random() * wordCounter) >= 8 && wordCounter > 5;
if (startNewSentence) {
paragraph?.append('. ');
wordCounter = 0;
sentenceCounter += 1;
const startNewParagraph =
Math.floor(Math.random() * sentenceCounter) >= 3;
if (startNewParagraph) {
createParagraph();
sentenceCounter = 0;
}
}
let randomString =
dictionary[Math.floor(Math.random() * dictionary.length)];
if (wordCounter === 0) {
randomString = randomString[0].toUpperCase() + randomString.slice(1);
} else {
randomString = ' ' + randomString;
}
paragraph?.append(randomString);
wordCounter += 1;
}
for (let i = 0; i < 20; i++) {
addRandomString();
}
setInterval(() => {
addRandomString();
}, 1);
</script>
<style>
ai-trap {
font-family: sans-serif;
}
</style>