-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
27 lines (23 loc) · 773 Bytes
/
popup.js
File metadata and controls
27 lines (23 loc) · 773 Bytes
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
let quotes = [];
let shownQuotes = [];
fetch('quotes.json')
.then(response => response.json())
.then(data => {
quotes = data;
displayQuote();
})
.catch(error => {
console.error('Error loading quotes:', error);
});
function displayQuote() {
if (shownQuotes.length === quotes.length) {
// If all quotes have been shown, reset the shownQuotes array
shownQuotes = [];
}
const remainingQuotes = quotes.filter(quote => !shownQuotes.includes(quote));
const randomIndex = Math.floor(Math.random() * remainingQuotes.length);
const quote = remainingQuotes[randomIndex];
// Add the quote to the shownQuotes array and display it
shownQuotes.push(quote);
document.getElementById('quote').innerText = quote;
}