-
Notifications
You must be signed in to change notification settings - Fork 0
/
clientside.js
57 lines (42 loc) · 1.52 KB
/
clientside.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
const getQuote = async () => {
const api = "https://type.fit/api/quotes";
const data = await fetch(api);
const allQuotes = await data.json();
var rnum = Math.floor(Math.random() * allQuotes.length);
var quote = `${allQuotes[rnum].text}`;
var author = allQuotes[rnum].author.split(',')[0];
var quoteInfo = { quote: quote, author: author };
return quoteInfo;
};
const updateData = () => {
chrome.storage.local.get(["myData"], async function (result) {
var myData = result.myData || [];
const quoteInfo = await getQuote();
myData.push(quoteInfo);
chrome.storage.local.set({ myData: myData }, function (result) {
console.log("Data has been updated successfully");
});
});
};
const displayData = () => {
chrome.storage.local.get(["myData"], function (result) {
var dataList = document.getElementById("data-list");
if(result.myData && result.myData.length < 10){
result.myData.forEach(function (item) {
var listItem = document.createElement("li");
listItem.innerHTML = item.quote + " - " + item.author;
dataList.appendChild(listItem);
});
}
});
};
const clearData = () => {
chrome.storage.local.clear(function () {
console.log("Data has been cleared from local storage");
del.style.padding = "4px 8px";
del.style.fontSize = "12px";
});
};
document.getElementById("del").addEventListener("click", clearData);
updateData();
displayData();