-
Notifications
You must be signed in to change notification settings - Fork 1
/
whatsapp.js
147 lines (136 loc) · 5.15 KB
/
whatsapp.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
document.addEventListener('DOMContentLoaded', function() {
const whatsappButton = document.createElement('div');
whatsappButton.id = 'whatsapp-button';
const img = document.createElement('img');
// deve ser informado o link de uma expecífica
img.src = 'https://w7.pngwing.com/pngs/198/625/png-transparent-call-centre-customer-service-computer-icons-call-centre-miscellaneous-face-telephone-call-thumbnail.png';
img.alt = 'WhatsApp';
const container = document.createElement('div');
container.classList.add('atendente');
container.id = 'atendente';
const text = document.createElement('div');
text.id = 'texto';
// esse texto pode ser personalizado
text.textContent = 'Olá, eu sou a atendente! Precisa de ajuda?';
const openButton = document.createElement('button');
openButton.textContent = 'Iniciar Conversa';
openButton.addEventListener('click', function() {
// o numero de telefone precisa do codigo do país e do DDD
window.open('https://wa.me/5500999999999', '_blank');
});
const atendimentoText = document.createElement('div');
atendimentoText.id = 'atendimento-text';
atendimentoText.textContent = 'Atendimento';
atendimentoText.style.writingMode = 'vertical-rl';
atendimentoText.style.textOrientation = 'mixed';
atendimentoText.style.fontSize = '15px';
atendimentoText.style.color = '#fff';
atendimentoText.style.cursor = 'pointer';
atendimentoText.style.display = 'none';
atendimentoText.style.position = 'fixed';
atendimentoText.style.bottom = '13px';
atendimentoText.style.right = '2px';
atendimentoText.style.fontFamily = 'Segoe UI, Tahoma, Geneva, Verdana, sans-serif';
atendimentoText.style.zIndex = '9991';
atendimentoText.style.transform = 'translate(-50%, -50%) rotate(180deg)';
atendimentoText.addEventListener('click', function() {
container.style.display = 'flex';
atendimentoText.style.display = 'none';
whatsappButton.style.width = '200px';
container.style.transition = 'transform 0.5s ease-out-in';
container.style.transform = 'translateX(0%)';
openButton.style.transition = 'transform 0.5s ease-out-in';
openButton.style.transform = 'translateX(0%)';
whatsappButton.style.transition = 'width 0.5s ease-out-in';
whatsappButton.style.width = '200px';
closeButton.style.cursor = 'pointer';
setTimeout(function() {
closeButton.style.display = 'flex';
}, 500);
});
const closeButton = document.createElement('div');
closeButton.id = 'close-button';
closeButton.textContent = '✘';
closeButton.style.position = 'absolute';
closeButton.style.top = '6px';
closeButton.style.right = '190px';
closeButton.style.color = '#fff';
closeButton.style.cursor = 'pointer';
closeButton.addEventListener('click', function() {
container.style.transition = 'transform 0.5s ease-in-out';
container.style.transform = 'translateX(150%)';
openButton.style.transition = 'transform 0.5s ease-in-out';
openButton.style.transform = 'translateX(150%)';
whatsappButton.style.transition = 'width 0.5s ease-in-out';
whatsappButton.style.width = '30px';
closeButton.style.display = 'none';
setTimeout(function() {
atendimentoText.style.display = 'block';
}, 500);
});
container.appendChild(text);
container.appendChild(img);
whatsappButton.appendChild(container);
whatsappButton.appendChild(openButton);
whatsappButton.appendChild(closeButton);
document.body.appendChild(whatsappButton);
document.body.appendChild(atendimentoText);
const style = document.createElement('style');
style.textContent = `
#whatsapp-button {
position: fixed;
bottom: 20px;
right: 0;
padding: 5px;
border: none;
border-top-left-radius: 8px;
border-bottom-left-radius: 8px;
background-image: linear-gradient(to right, #461f79, #4c698b);
z-index: 9990;
display: flex;
flex-direction: column;
width: 200px;
height: 140px;
transition: max-width 0.5s ease-in-out;
justify-content: center;
}
#whatsapp-button .atendente {
display: flex;
margin-top: 7px;
}
#whatsapp-button img {
width: auto;
height: 95px;
transition: transform 0.2s ease;
}
#whatsapp-button #texto {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-weight: bold;
font-size: 12px;
display: flex;
text-align: center;
align-items: center;
justify-content: center;
color: #ffffff;
width: 110px;
height: 65px;
margin-top: 15px;
}
#whatsapp-button button {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
font-size: 12px;
background: #ffffff;
color: #1F4E79;
align-items: center;
justify-content: center;
border: none;
padding: 5px;
width: 200px;
cursor: pointer;
position: relative;
margin-bottom: 7px;
margin-inline: 7px;
}
`;
document.head.appendChild(style);
});