-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
37 lines (31 loc) · 1.08 KB
/
popup.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
'use strict';
let changeQuote = document.getElementById('changeQuote');
let quoteBox = document.getElementById('quote');
function randomNumber(max) {
return Math.floor(Math.random(0) * Math.floor(max));
}
function renderQuote(quoteBox, quote, author) {
quoteBox.innerHTML = `<h1 class="quote">${quote}</h1> <p class="author">${author}</p>`;
}
function getNewRandomQuote(quoteBox, result) {
let randomIndex = randomNumber(result.quotes.quotes.length);
let { quote, author } = result.quotes.quotes[randomIndex];
renderQuote(quoteBox, quote, author);
chrome.storage.local.set({
quoteIndex: randomIndex,
});
}
chrome.storage.local.get(['quotes'], function(result) {
chrome.storage.local.get(['quoteIndex'], function(quoteIndex) {
console.log(result, quoteIndex);
let { quote, author } = result.quotes.quotes[quoteIndex.quoteIndex];
renderQuote(quoteBox, quote, author);
});
});
changeQuote.onclick = function() {
chrome.storage.local.get(['quotes'], function(result) {
getNewRandomQuote(quoteBox, result);
});
window.scrollTo(0, 0);
changeQuote.blur();
};