Added 'QuoteMan' that will choose a random quote from ./assets/quotes and put it on aside's quoteblock.
This commit is contained in:
parent
61e0edfc05
commit
e77765a0ea
4 changed files with 51 additions and 2 deletions
|
|
@ -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>
|
<p>Studying computing at <a href="http://ifc.edu.br/">IFC</a>, interessed in programming, hacking and security.</p>
|
||||||
</nav>
|
</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">
|
<div id="links" class="centerText box">
|
||||||
<p>Links</p>
|
<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>
|
||||||
|
|
||||||
<div id="footer" class="box">
|
<div id="footer" class="box">
|
||||||
|
|
|
||||||
39
assets/quoteman.js
Normal file
39
assets/quoteman.js
Normal 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
2
assets/quotes
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
!Fantasy is not a crime, find your castle in the sky
|
||||||
|
@DJ Satomi - Castle In The Sky
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
<link rel="stylesheet" type="text/css" media="screen" href="./assets/main.css">
|
<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 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/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">
|
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue