Added 'QuoteMan' that will choose a random quote from ./assets/quotes and put it on aside's quoteblock.

This commit is contained in:
Adrian Victor 2024-04-05 12:48:40 -03:00
commit e77765a0ea
4 changed files with 51 additions and 2 deletions

View file

@ -13,9 +13,16 @@ class Header extends HTMLElement {
<p>Studying computing at <a href="http://ifc.edu.br/">IFC</a>, interessed in programming, hacking and security.</p>
</nav>
<div id="links" class="centerText box">
<blockquote id="random-quote">
The quote man is not working...
</blockquote>
<p id="random-quote-author">- Quote man</p>
</div>
<div id="links" class="centerText box">
<p>Links</p>
<p><a href="index.html">Home</a> - <a href="http://gallery.adrian.rf.gd/">Gallery</a> - <a href="http://vicc.rf.gd/gh">GitHub</a></p>
<p><a href="index.html">Home</a> - <a href="http://gallery.adrian.rf.gd/">Gallery</a> - <a href="http://vicc.rf.gd/gh">GitHub</a> - <a href="http://vicc.rf.gd/twitter">Twitter</a></p>
</div>
<div id="footer" class="box">
@ -27,6 +34,6 @@ class Header extends HTMLElement {
`;
}
}
customElements.define('header-component', Header);

39
assets/quoteman.js Normal file
View file

@ -0,0 +1,39 @@
document.addEventListener('DOMContentLoaded', () => {
fetch('./assets/quotes')
.then(response => {
if (!response.ok) {
throw new Error('Failed to load the quotes file.');
}
return response.text();
})
.then(data => {
const lines = data.split('\n');
const textLines = [];
const authorLines = [];
lines.forEach(line => {
if (line.trim().startsWith('!')) {
textLines.push(line.trim());
} else if (line.trim().startsWith('@')) {
authorLines.push(line.trim());
}
});
// Ensure that textLines and authorLines have the same length
const minLength = Math.min(textLines.length, authorLines.length);
if (minLength === 0) {
throw new Error('No matching text and author lines found.');
}
const randomIndex = Math.floor(Math.random() * minLength);
const randomTextLine = textLines[randomIndex];
const randomAuthorLine = authorLines[randomIndex];
document.getElementById('random-quote').textContent = randomTextLine.substring(1); // Remove '!' from the text
document.getElementById('random-quote-author').textContent = randomAuthorLine.substring(1); // Remove '@' from the author
})
.catch(error => {
console.error('Error:', error);
});
});

2
assets/quotes Normal file
View file

@ -0,0 +1,2 @@
!Fantasy is not a crime, find your castle in the sky
@DJ Satomi - Castle In The Sky

View file

@ -8,6 +8,7 @@
<link rel="stylesheet" type="text/css" media="screen" href="./assets/main.css">
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
<script src="./assets/main.js" type="text/javascript" defer></script>
<script src="./assets/quoteman.js" type="text/javascript" defer></script>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
</head>