-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (30 loc) · 1.58 KB
/
script.js
File metadata and controls
42 lines (30 loc) · 1.58 KB
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
import { fetchData, timeout, handleDialog, makingBox, modifyFilledAndNearBoxes, getData, getUpdates, makingUpdates, runDialogForFirstTime, showDialog } from "./module.js"
const main = async () => {
const targetAmount = 1390;
const oneBoxValue = 25;
const progress = document.getElementById("progress")
// If it is first time of visitor, show dialog or else no
runDialogForFirstTime(showDialog)
// Getting correct data, in which splitting >25 into 25s.
const data = await getData(fetchData, oneBoxValue)
const totalAmount = data.reduce((sum, item) => sum + item.amount, 0);
const filledBoxes = Math.floor(totalAmount / oneBoxValue);
// Getting updates
const updates = await getUpdates()
// Each value info
const eachBoxValueElement = document.getElementsByClassName("eachBoxValue")[0]
eachBoxValueElement.innerText = `Each Box Value: $${oneBoxValue}`
// All about dialog
handleDialog(showDialog)
// Money Breakdown
document.getElementsByClassName("totalMoney")[0].innerText = `$${targetAmount}`
document.getElementsByClassName("collected")[0].innerText = `$${totalAmount}`
// Making boxes dynamically according to the numbers. Giving img layer upon box.
makingBox(targetAmount, oneBoxValue, progress)
await timeout(10) // adding a timeout because for closed image removing with style need little gap.
// Modifying boxes such that if it is filled box so add id with tooltip, if it is near so add near class.
modifyFilledAndNearBoxes(filledBoxes, data)
// Make updates
makingUpdates(updates)
}
main()