-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
116 lines (109 loc) · 4.03 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Wisedom</title>
<style>
body {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
transition: background-color 0.5s;
}
.quote-container {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
text-align: center;
}
.quote {
font-size: calc(1em + 2vw);
transition: color 0.5s;
}
footer {
font-size: 0.8em;
text-align: center;
width: 100%;
padding: 10px 0;
}
</style>
</head>
<body>
<div class="quote-container">
<div class="quote">Loading...</div>
</div>
<footer>
<p>Proudly Designed and Developed in Texas.</p>
</footer>
<script>
let lines = [];
let currentIndex = -1;
let displayInterval;
let fetchInterval;
async function fetchLines() {
try {
const response = await fetch('quotes.txt');
if (!response.ok) {
throw new Error('Network response was not ok ' + response.statusText);
}
const text = await response.text();
const newLines = text.split('\n').map(line => line.trim()).filter(line => line);
if (newLines.length > 0) {
lines = newLines;
shuffleLines();
currentIndex = -1; // Reset index to start fresh
} else {
document.querySelector('.quote').innerText = 'No quotes found in the file.';
}
} catch (error) {
document.querySelector('.quote').innerText = 'Error loading quotes: ' + error.message;
}
}
function shuffleLines() {
for (let i = lines.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[lines[i], lines[j]] = [lines[j], lines[i]];
}
}
function displayNextLine() {
if (lines.length === 0) return;
currentIndex = (currentIndex + 1) % lines.length;
document.querySelector('.quote').innerText = lines[currentIndex];
changeBackgroundColor();
}
function changeBackgroundColor() {
const randomColor = `#${Math.floor(Math.random() * 16777215).toString(16)}`;
document.body.style.backgroundColor = randomColor;
const contrastColor = getContrastColor(randomColor);
document.querySelector('.quote').style.color = contrastColor;
document.querySelector('footer p').style.color = contrastColor;
}
function getContrastColor(hexColor) {
const r = parseInt(hexColor.substr(1, 2), 16);
const g = parseInt(hexColor.substr(3, 2), 16);
const b = parseInt(hexColor.substr(5, 2), 16);
const brightness = (r * 299 + g * 587 + b * 114) / 1000;
return brightness > 125 ? 'black' : 'white';
}
function startIntervals() {
displayNextLine(); // Display the first quote immediately
displayInterval = setInterval(displayNextLine, 10000); // Display new quote every 10 seconds
fetchInterval = setInterval(async () => {
await fetchLines();
// Restart the display interval to avoid overlap
clearInterval(displayInterval);
displayInterval = setInterval(displayNextLine, 10000);
}, 1800000); // Re-fetch the quotes every 30 minutes
}
// Initial fetch and setup intervals
fetchLines().then(startIntervals);
</script>
</body>
</html>