PluginProbe ʕ •ᴥ•ʔ
Automation Web Platform – Notifications and OTP for WooCommerce, Advanced Country Code / 4.8.6
Automation Web Platform – Notifications and OTP for WooCommerce, Advanced Country Code v4.8.6
4.8.6 4.8.5 4.8.4 trunk 4.8.3
automation-web-platform / assets / js / script.js
automation-web-platform / assets / js Last commit date
admin 1 week ago resources 1 week ago block-checkout-intl-tel.js 1 week ago index.php 1 month ago phone-verification-bar.js 1 week ago script.js 1 week ago wawp-otp-frontend.js 1 week ago wawp-recaptcha-frontend.js 1 month ago wawp-send-msg.js 1 month ago wawp-signup.js 1 week ago
script.js
250 lines
1 jQuery( document ).ready(
2 function ($) {
3
4 // Track Impression — once per browser session to avoid hammering the server
5 var impressionKey = 'wawp_impression_sent';
6 if (wawp_ajax_obj.rest_url && ! sessionStorage.getItem( impressionKey )) {
7 var impressionPayload = JSON.stringify(
8 {
9 page_id: wawp_ajax_obj.current_pid,
10 device: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test( navigator.userAgent ) ? 'Mobile' : 'Desktop',
11 os: getOS()
12 }
13 );
14 var impressionUrl = wawp_ajax_obj.rest_url + '/impression';
15 var sent = false;
16 if (navigator.sendBeacon) {
17 var blob = new Blob( [impressionPayload], {type: 'application/json'} );
18 sent = navigator.sendBeacon( impressionUrl, blob );
19 }
20 if ( ! sent) {
21 fetch(
22 impressionUrl,
23 {
24 method: 'POST',
25 headers: {
26 'Content-Type': 'application/json',
27 'X-WP-Nonce': wawp_ajax_obj.nonce
28 },
29 body: impressionPayload
30 }
31 );
32 }
33 sessionStorage.setItem( impressionKey, '1' );
34 }
35
36 function getOS() {
37 let userAgent = window.navigator.userAgent,
38 platform = window.navigator.platform,
39 macosPlatforms = ['Macintosh', 'MacIntel', 'MacPPC', 'Mac68K'],
40 windowsPlatforms = ['Win32', 'Win64', 'Windows', 'WinCE'],
41 iosPlatforms = ['iPhone', 'iPad', 'iPod'],
42 os = null;
43
44 if (macosPlatforms.indexOf( platform ) !== -1) {
45 os = 'Mac OS';
46 } else if (iosPlatforms.indexOf( platform ) !== -1) {
47 os = 'iOS';
48 } else if (windowsPlatforms.indexOf( platform ) !== -1) {
49 os = 'Windows';
50 } else if (/Android/.test( userAgent )) {
51 os = 'Android';
52 } else if ( ! os && /Linux/.test( platform )) {
53 os = 'Linux';
54 }
55 return os || 'Unknown';
56 }
57
58 $( document ).on(
59 'click',
60 '#wawp-whatsapp-button',
61 function () {
62 if (wawp_ajax_obj.rest_url) {
63 fetch(
64 wawp_ajax_obj.rest_url + '/increment-clicks',
65 {
66 method: 'POST',
67 headers: {
68 'Content-Type': 'application/json',
69 'X-WP-Nonce': wawp_ajax_obj.nonce
70 },
71 body: JSON.stringify(
72 {
73 page_id: wawp_ajax_obj.current_pid
74 }
75 )
76 }
77 );
78 }
79 $( '#wawp-chat-window' ).toggleClass( 'scale-toggle' );
80 }
81 );
82
83 $( document ).on(
84 'click',
85 '#wawp-minimize-icon',
86 function () {
87 $( '#wawp-chat-window' ).toggleClass( 'scale-toggle' );
88 }
89 );
90
91 let originalIconHTML = null;
92 $( document ).on(
93 'mouseenter',
94 '#wawp-whatsapp-button',
95 function () {
96 let $btn = $( this );
97 let $icon = $btn.find( 'i, svg, .wawp-custom-svg, img' );
98 if ($icon.length) {
99 originalIconHTML = $icon[0].outerHTML;
100 $icon.remove();
101 }
102 if ( ! $btn.find( '.wawp-typing-dots' ).length) {
103 $btn.append(
104 `<div class="wawp-typing-dots">
105 <span class="dot"></span>
106 <span class="dot"></span>
107 <span class="dot"></span>
108 </div>`
109 );
110 }
111 }
112 );
113
114 $( document ).on(
115 'mouseleave',
116 '#wawp-whatsapp-button',
117 function () {
118 let $btn = $( this );
119 $btn.find( '.wawp-typing-dots' ).remove();
120 if (originalIconHTML) {
121 $btn.append( originalIconHTML );
122 }
123 }
124 );
125
126 $( document ).on(
127 'click touchstart',
128 '.wawp-qr-chat-icon',
129 function (e) {
130 e.preventDefault();
131 let waLink = $( this ).data( 'wawp-link' );
132 if ( ! waLink) {
133 return;
134 }
135 let phoneMatch = waLink.match( /phone=(\d+)/ );
136 let phone = phoneMatch ? phoneMatch[1] : '';
137 let name = $( this ).find( '.wawp-contact-name' ).text() || 'Unknown';
138 if (wawp_ajax_obj.rest_url) {
139 fetch(
140 wawp_ajax_obj.rest_url + '/contact-click',
141 {
142 method: 'POST',
143 headers: {
144 'Content-Type': 'application/json',
145 'X-WP-Nonce': wawp_ajax_obj.nonce
146 },
147 body: JSON.stringify(
148 {
149 phone: phone,
150 name: name,
151 page_id: wawp_ajax_obj.current_pid
152 }
153 )
154 }
155 );
156 }
157 $( '#wawp-contact-list' ).hide();
158 $( '.wawp-social-container' ).hide();
159 $( '#wawp-qr-card' ).css( 'display', 'flex' ).show();
160 $( '#wawp-dynamic-qr' ).empty();
161 setTimeout( function () {
162 if (typeof QRCode !== 'undefined') {
163 try {
164 new QRCode(
165 "wawp-dynamic-qr",
166 {
167 text: waLink,
168 width: 150,
169 height: 150,
170 colorDark: "#000000",
171 colorLight: "#ffffff",
172 correctLevel: QRCode.CorrectLevel.H
173 }
174 );
175 } catch (e) {
176 console.error("QR Error:", e);
177 }
178 }
179 }, 100 );
180 $( '#wawp-open-whatsapp' ).attr( 'href', waLink ).data( 'phone', phone );
181 }
182 );
183
184 $( document ).on(
185 'click',
186 '#wawp-open-whatsapp',
187 function () {
188 let phone = $( this ).data( 'phone' ) || '';
189 if (phone) {
190 if (wawp_ajax_obj.rest_url) {
191 fetch(
192 wawp_ajax_obj.rest_url + '/open-whatsapp',
193 {
194 method: 'POST',
195 headers: {
196 'Content-Type': 'application/json',
197 'X-WP-Nonce': wawp_ajax_obj.nonce
198 },
199 body: JSON.stringify(
200 {
201 phone: phone,
202 page_id: wawp_ajax_obj.current_pid
203 }
204 )
205 }
206 );
207 }
208 }
209 }
210 );
211
212 // Track Social Link Clicks
213 $( document ).on(
214 'click',
215 '.wawp-social-link',
216 function () {
217 let icon = $( this ).find( 'i' ).attr( 'class' );
218 if (wawp_ajax_obj.rest_url) {
219 fetch(
220 wawp_ajax_obj.rest_url + '/social-click',
221 {
222 method: 'POST',
223 headers: {
224 'Content-Type': 'application/json',
225 'X-WP-Nonce': wawp_ajax_obj.nonce
226 },
227 body: JSON.stringify(
228 {
229 icon: icon
230 }
231 )
232 }
233 );
234 }
235 }
236 );
237
238 $( document ).on(
239 'click',
240 '#wawp-qr-back',
241 function () {
242 $( '#wawp-qr-card' ).hide();
243 $( '.wawp-chat-header' ).show();
244 $( '#wawp-contact-list' ).show();
245 $( '.wawp-social-container' ).show();
246 }
247 );
248 }
249 );
250