-
Notifications
You must be signed in to change notification settings - Fork 0
/
popup.js
110 lines (87 loc) · 3.38 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
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
// import fontawesome from '@fortawesome/fontawesome'
// import faFreeSolid from '@fortawesome/fontawesome-free-solid'
// import faProSolid from '@fortawesome/fontawesome-pro-solid'
/*================================*/
// Load in the Scripture References
/*================================*/
var __ScriptureRefs__ = __verses__
var volume
/*================================*/
// Get a Random Number!
/*================================*/
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
// console.log(getRandomInt(3));
// // expected output: 0, 1 or 2
function logBool(b) {
var bkg = chrome.extension.getBackgroundPage();
bkg.console.log(b)
}
function generateNewScripture() {
var bkg = chrome.extension.getBackgroundPage();
let numVerses = __ScriptureRefs__.data.length
bkg.console.log("Number of Verses :: " + numVerses)
var randVerseIdx = getRandomInt(numVerses)
bkg.console.log("Show the random verse IDX!! :: " + randVerseIdx)
let verseRefObj = __ScriptureRefs__.data[randVerseIdx]
linkElm = document.getElementById("verse-name")
linkElm.innerText = verseRefObj.humanName
linkElm.href = verseRefObj.url
contentElm = document.getElementById("verse-content")
contentElm.innerHTML = verseRefObj.content
bookVolume = document.getElementById("book-volume")
bookVolume.innerText = determineBook(verseRefObj.url)
// SAVE the newly generated scripture as the lastScripture
chrome.storage.local.set({"lastScripture": randVerseIdx}, (items) => {
var bkg = chrome.extension.getBackgroundPage();
bkg.console.log("Saved as LASTSCRIPTURE:: " + randVerseIdx)
});
}
document.getElementById("newScripture").addEventListener("click",generateNewScripture);
/* Load Scriptures */
function loadInScripture(scriptureIdx) {
let verseRefObj = __ScriptureRefs__.data[scriptureIdx]
linkElm = document.getElementById("verse-name")
linkElm.innerText = verseRefObj.humanName
linkElm.href = verseRefObj.url
contentElm = document.getElementById("verse-content")
contentElm.innerHTML = verseRefObj.content
bookVolume = document.getElementById("book-volume")
bookVolume.innerText = determineBook(verseRefObj.url)
// var icon = fontawesome.icon(faFreeSolid)
// $('#replace-icon').html(icon.html)
// // the following work as well
// // $('#replace-icon').replaceWith(icon.node[0])
}
function determineBook(url) {
console.log(url)
if(url.includes("/bofm/")) {
return "Book of Mormon"
} else if(url.includes("/dc-testament/")) {
return "Doctrine and Covenants"
} else if(url.includes("/pgp/")) {
return "Pearl of Great Price"
} else if (url.includes("/nt/")) {
return "New Testament"
} else if (url.includes("/ot/")) {
return "Old Testament"
}
}
// Local storage && Load in scripture on Startup
var LASTSCRIPTURE = 0;
window.onload = () => {
chrome.storage.local.get(["lastScripture"], (items) => {
// Create a variable if one does not exist
if (!items["lastScripture"]) {
LASTSCRIPTURE = 0;
}
// Reassign or manipulate data
else {
LASTSCRIPTURE = items.lastScripture
}
loadInScripture(LASTSCRIPTURE)
var bkg = chrome.extension.getBackgroundPage();
bkg.console.log("Loaded in LASTSCRIPTURE:: " + LASTSCRIPTURE)
});
};