-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
122 lines (95 loc) · 2.88 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const celebrateBtn = document.getElementById('celebrateBtn');
const mainImg = document.getElementById("mainImg");
const text = document.querySelector('.typing-text');
const buttonAndText = document.getElementById("buttonAndText");
const lastMsg = document.getElementById('lastMsg');
celebrateBtn.addEventListener('click', () => {
//disable button
celebrateBtn.disabled = true;
buttonAndText.style.display = 'none';
// trigger confetti
confetti({
particleCount: 100,
spread: 70,
origin: { x: 0.5, y: 0.45 }
});
// button animation
celebrateBtn.style.transform = 'scale(0.95)';
setTimeout(() => {
celebrateBtn.style.transform = 'scale(1)';
}, 100);
zoomInOut();
setTimeout(async () => {
text.style.display = 'block';
setTyper(text, words);
}, 2000);
// text.style.display = 'none';
});
function zoomInOut() {
mainImg.style.display = 'inline';
mainImg.classList.add('zoomIn');
setTimeout(() => {
mainImg.classList.add('zoomOut');
setTimeout(() => {
celebrateBtn.disabled = false;
mainImg.style.display = 'none';
mainImg.classList.remove('zoomIn');
mainImg.classList.remove('zoomOut');
text.style.display = 'none';
lastMsg.style.display = 'block';
}, 1800);
}, 23000);
}
// typing effect
const words = [
"Shri Ganeshaya Namah 🙏",
"Lord Ganesha has blessed your new project! ✨",
"You must achieve great things! 💪"
];
function setTyper(element, words) {
const LETTER_TYPE_DELAY = 75;
const WORD_STAY_DELAY = 2000;
const DIRECTION_FORWARDS = 0;
const DIRECTION_BACKWARDS = 1;
var direction = DIRECTION_FORWARDS;
var wordIndex = 0;
var letterIndex = 0;
var wordTypeInterval;
startTyping();
function startTyping() {
wordTypeInterval = setInterval(typeLetter, LETTER_TYPE_DELAY);
}
function typeLetter() {
if (wordIndex == words.length) {
return;
}
const word = words[wordIndex];
if (direction == DIRECTION_FORWARDS) {
letterIndex++;
if (letterIndex == word.length) {
direction = DIRECTION_BACKWARDS;
clearInterval(wordTypeInterval);
setTimeout(startTyping, WORD_STAY_DELAY);
}
} else if (direction == DIRECTION_BACKWARDS) {
letterIndex--;
if (letterIndex == 0) {
nextWord();
}
}
const textToType = word.substring(0, letterIndex);
element.textContent = textToType;
}
function nextWord() {
letterIndex = 0;
direction = DIRECTION_FORWARDS;
wordIndex++;
if (wordIndex == words.length) {
return;
}
}
}
lastMsg.addEventListener('click', () => {
lastMsg.style.display = 'none';
buttonAndText.style.display = 'block';
})