-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
150 lines (139 loc) · 4.75 KB
/
index.js
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Array of quotes
var quotes = [
// add your quotes here
{
text: "The greatest glory in living lies not in never falling, but in rising every time we fall.",
author: "Nelson Mandela"
},
{
text: "The way to get started is to quit talking and begin doing.",
author: "Walt Disney"
},
{
text: "If life were predictable it would cease to be life, and be without flavor.",
author: "Eleanor Roosevelt"
},
{
text: "Life is what happens when you're busy making other plans.",
author: "John Lennon"
},
{
text: "Spread love everywhere you go. Let no one ever come to you without leaving happier.",
author: "Mother Teresa"
},
// Continue adding more quotes...
{
text: "Success is not final, failure is not fatal: It is the courage to continue that counts.",
author: "Winston Churchill"
},
{
text: "Life is 10% what happens to us and 90% how we react to it.",
author: "Charles R. Swindoll"
},
{
text: "The only way to do great work is to love what you do.",
author: "Steve Jobs"
},
{
text: "Believe you can and you're halfway there.",
author: "Theodore Roosevelt"
},
// Additional quotes
{
text: "The only limit to our realization of tomorrow will be our doubts of today.",
author: "Franklin D. Roosevelt"
},
{
text: "In the end, it's not the years in your life that count. It's the life in your years.",
author: "Abraham Lincoln"
},
{
text: "The best time to plant a tree was 20 years ago. The second best time is now.",
author: "Chinese Proverb"
},
{
text: "Don't watch the clock; do what it does. Keep going.",
author: "Sam Levenson"
},
{
text: "Success usually comes to those who are too busy to be looking for it.",
author: "Henry David Thoreau"
},
{
text: "Life is really simple, but we insist on making it complicated.",
author: "Confucius"
},
{
text: "The secret of getting ahead is getting started.",
author: "Mark Twain"
},
{
text: "The only person you should try to be better than is the person you were yesterday.",
author: "Unknown"
},
{
text: "A champion is defined not by their wins but by how they can recover when they fall.",
author: "Serena Williams"
},
{
text: "You miss 100% of the shots you don't take.",
author: "Wayne Gretzky"
},
];
// Function to generate a random quote
function generateRandomQuote() {
var storedQuotes = JSON.parse(localStorage.getItem('seenQuotes')) || [];
var newQuotes = quotes.filter(function(quote) {
return !storedQuotes.includes(quote.text);
});
var quoteElement = document.getElementById("quote");
var authorElement = document.getElementById("author");
var messageElement = document.getElementById("message");
if (newQuotes.length > 0) {
// Display new quotes first
var randomIndex = Math.floor(Math.random() * newQuotes.length);
var quote = newQuotes[randomIndex];
// Display the quote and author
quoteElement.textContent = quote.text;
authorElement.textContent = "- " + quote.author;
// Add the quote to the stored quotes
storedQuotes.push(quote.text);
localStorage.setItem('seenQuotes', JSON.stringify(storedQuotes));
// Reset the message element
messageElement.innerHTML = "";
messageElement.style.fontSize = "";
} else {
// Check if all quotes have been seen
if (storedQuotes.length === quotes.length) {
// Display a random quote
var randomIndex = Math.floor(Math.random() * quotes.length);
var quote = quotes[randomIndex];
// Display the quote and author
quoteElement.textContent = quote.text;
authorElement.textContent = "- " + quote.author;
// Display the message and link in small text
messageElement.innerHTML = "All quotes have been shown to you.<br>Make sure to add more quotes <a href='https://github.com/Kendall-Does-Coding-Websites/ChatGPT-website/blob/main/index.js'>here</a>.";
messageElement.style.fontSize = "small";
} else {
// Display a previously seen quote
var randomIndex = Math.floor(Math.random() * storedQuotes.length);
var quote = quotes.find(function(quote) {
return quote.text === storedQuotes[randomIndex];
});
// Display the quote and author
quoteElement.textContent = quote.text;
authorElement.textContent = "- " + quote.author;
// Reset the message element
messageElement.innerHTML = "";
messageElement.style.fontSize = "";
}
}
}
// Wait for the document to load
document.addEventListener('DOMContentLoaded', function() {
// Add 'show' class to trigger the animation
var quoteContainer = document.getElementById("quote-container");
quoteContainer.classList.add('show');
// Generate a random quote
generateRandomQuote();
});