-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
843 lines (713 loc) · 38.8 KB
/
index.html
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
<html>
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-5SPBL5R3CE"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-5SPBL5R3CE');
</script>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>WhatSend</title>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Favicons -->
<link rel="apple-touch-icon" sizes="57x57" href="./favicon/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="./favicon/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="./favicon/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="./favicon/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="./favicon/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="./favicon/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="./favicon/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="./favicon/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="./favicon/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="./favicon/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="./favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="./favicon/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="./favicon/favicon-16x16.png">
<link rel="manifest" href="./favicon/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="theme-color" content="#ffffff">
<meta name="msapplication-TileImage" content="./favicon/ms-icon-144x144.png">
<!-- Primary Meta Tags -->
<meta name="title" content="WhatSend - Send a message to multiple people on WhatsApp automatically">
<meta name="description"
content="Send messages in bulk to multiple people from the comfort of a web browser for free.">
<!-- Open Graph / Facebook -->
<meta property="og:type" content="website">
<meta property="og:url" content="https://whatsend.defcon007.com/">
<meta property="og:title" content="WhatSend - Send a message to multiple people on WhatsApp automatically">
<meta property="og:description"
content="Send messages in bulk to multiple people from the comfort of a web browser for free.">
<meta property="og:image" content="https://raw.githubusercontent.com/DefCon-007/WhatSend/master/images/meta-tag-image.png?sanitize=true">
<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image">
<meta property="twitter:url" content="https://whatsend.defcon007.com/">
<meta property="twitter:title" content="WhatSend - Send a message to multiple people on WhatsApp automatically">
<meta property="twitter:description"
content="Send messages in bulk to multiple people from the comfort of a web browser for free.">
<meta property="twitter:image" content="https://raw.githubusercontent.com/DefCon-007/WhatSend/master/images/meta-tag-image.png?sanitize=true">
<!-- Latest compiled and minified Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"
integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"
integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/PapaParse/5.1.0/papaparse.js"
integrity="sha256-iAuxnf8Cwr0yrQkpf6oQG4PaL/oVmoer6V/RfX2KQws=" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"></script>
<!-- Sentry -->
<script src="https://browser.sentry-cdn.com/5.22.3/bundle.tracing.min.js"
integrity="sha384-HfEJlGrJtFM0B01Wt4sGzTbxWqLMcMeGAXCbyQyB+iK9BhnDmNAtIGovhekIQOa2"
crossorigin="anonymous"></script>
<!-- DataTable -->
<link rel="stylesheet" type="text/css"
href="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.21/b-1.6.3/b-flash-1.6.3/b-html5-1.6.3/b-print-1.6.3/r-2.2.5/datatables.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
<script type="text/javascript"
src="https://cdn.datatables.net/v/dt/jszip-2.5.0/dt-1.10.21/b-1.6.3/b-flash-1.6.3/b-html5-1.6.3/b-print-1.6.3/r-2.2.5/datatables.min.js"></script>
<!-- Toast notification https://github.com/kamranahmedse/jquery-toast-plugin -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-toast-plugin/1.3.2/jquery.toast.min.js"
integrity="sha512-zlWWyZq71UMApAjih4WkaRpikgY9Bz1oXIW5G0fED4vk14JjGlQ1UmkGM392jEULP8jbNMiwLWdM8Z87Hu88Fw=="
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-toast-plugin/1.3.2/jquery.toast.min.css"
integrity="sha512-wJgJNTBBkLit7ymC6vvzM1EcSWeM9mmOu+1USHaRBbHkm6W9EgM0HY27+UtUaprntaYQJF75rc8gjxllKs5OIQ=="
crossorigin="anonymous" />
<!-- Clusterize -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clusterize.js/0.18.0/clusterize.min.js"
integrity="sha512-J9kWigtolF+Ur3ozrZwj18sLPTeAFNiwLxFHaXtmjKao7MZ1g3UWnTn8y1ChS48V2JM7ErQV2r1uMeMaplN+EA=="
crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/clusterize.js/0.18.0/clusterize.min.css"
integrity="sha512-67r8GWGen3CmoHmvKJtZyf5xmDlPBeIGHB89/778A/L28BmcSc+AHwn/toK+nZFgwu5x9XLD/PunV4twUtkOLA=="
crossorigin="anonymous" />
<!-- Custom css file -->
<link rel="stylesheet" type="text/css" href="./styles.css" />
</head>
<body style="background-color: #f1f1f1;">
<nav class="navbar navbar-expand-lg navbar-light bg-light fixed-top">
<a href="https://whatsend.defcon007.com" class="navbar-brand">
<img src="./images/logo.png" alt="logo" width="40" height="40"/>
</a>
<button class="navbar-toggler navbar-toggle" type="button" data-toggle="collapse" data-target=".navbar-collapse"
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a href="#" class="nav-link active" style="color:#f8615a">Home</a>
</li>
<li class="nav-item">
<a href="https://github.com/DefCon-007/WhatSend-extension/archive/master.zip"
class="nav-link active">Download Extension</a>
</li>
<li class="nav-item">
<a href="#instructions" class="nav-link">Instructions</a>
</li>
<li class="nav-item">
<a href="#input_form" class="nav-link">Send Messages</a>
</li>
<li class="nav-item">
<a href="#result" class="nav-link">Result</a>
</li>
<li class="nav-item">
<a href="#lab_social_icon_footer" class="nav-link">Contact</a>
</li>
</ul>
</div>
</nav>
<div class="main">
<!-- <div style="padding-left: 10%;padding-right: 10%;padding-top: 5%;"> -->
<section id="about" align="center">
<h2>What is it?</h2>
<hr style="margin-left: 15%;margin-right: 15%;">
<iframe width="40%" height="30%" src="https://www.youtube.com/embed/tz088WQSjGw" frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen></iframe>
</section>
<section id="input_form">
<form style="padding-left: 10%;padding-right: 10%" onsubmit="formSubmit();return false;"
class="py-3"
name='specificationForm'>
<h2>Specifications</h2>
Upload a CSV file or add list of mobile numbers, if both present only CSV file will be used.<br /><br />
The numbers should either be in international format (91 appended
for India, 1 for US. If not found, Indian country code(i.e. 91) will be automatically appended)
<hr>
<div class="form-group border p-3">
<label for="csvFile">Upload a CSV file:</label><br>
<span><i class="fa fa-info-circle"></i></span> The CSV file should have a column for numbers.
<input type="file" id="csvFile" class="form-control" accept=".csv">
<label for="numberselect">Select column for number</label>
<select id="numberselect" class="form-control">
</select>
<br>
<hr class="hr-text" data-content="OR">
<br>
<label for="commaSeparatedNumbers">List of numbers separated by comma</label><br>
<span><i class="fa fa-info-circle"></i></span> The mobile numbers list should be <b>separated by
comma</b>. For eg.
9999999999, 123123123, 4321432112
<input type="text" class="form-control" id="commaSeparatedNumbers">
</div>
<div id="customInputs" class="form-group">
</div>
<div class="form-group">
<button onclick="addCustomField();" type="button" class="btn btn-info">Add custom field</button>
</div>
<div class="form-group">
<label for="message">Enter the message to send</label>
<textarea id="message" class="form-control" required> </textarea>
</div>
<div class="form-group">
<input type="submit" id="submit-file" class="btn btn-success" />
</div>
<hr>
</form>
</section>
<section id="result">
<div style="padding-left: 10%;padding-right: 10%;margin-top: 1%;">
<h3>Processed numbers</h3>
As soon as you start sending messages this table will get filled with the numbers to which the message
has been sent.
</div>
<br>
<div class="container">
<table class="table table-striped table-bordered" id="table-id">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Number</th>
<th data-type="@data-sort">Status</th>
</tr>
</thead>
<tbody>
<tbody>
</table>
</div>
</section>
<section id='instructions'>
<h3>Important instructions</h3>
Follow the below instructions to get started<br>
<ol class="list-group list-group-flush">
<li class="list-group-item">
<span class="badge badge-pill badge-danger">Important</span>
Make sure the all the popups are allowed for <span>
<u>https://whatsend.defcon007.com</u>
</span>. If you don't know how to do it, follow the steps mentioned <a
href="https://github.com/DefCon-007/WhatSend/wiki/Allow-popups-in-chrome"
target="_blank">here</a>.
</li>
<li class="list-group-item"><span class="badge badge-pill badge-danger">Important</span>
Make sure you can access WhatsApp web in the current browser.
<details>
<summary>Click here to know how to do it.</summary>
<ul>
<li>
Open WhatsApp web in a new tab by clicking <a href="https://web.whatsapp.com"
target="_blank">here</a>.
</li>
<li>
Log in with the account you wish to send message from, if not already logged in.
</li>
<li>
If you are logged in at other places too, you will see option to use WhatsApp web
here.
Click `Use here` option.
</li>
<li>
Close the tab.
</li>
</ul>
</details>
</li>
<li class="list-group-item">Download the helper chrome extension from <a target="_blank"
href="https://github.com/DefCon-007/WhatSend-extension/archive/master.zip">here</a> and load
it
in the browser by following the instructions from <a target="_blank"
href="https://github.com/DefCon-007/WhatSend-extension/wiki/Installation">here</a>.
</li>
<li class="list-group-item">
You are good to go now. Just select the corresponding CSV file and then select the column for
mobile number, type your message and click Submit. <br><br>
<b>Adding receiver's name to message</b><br>
<ul>
<li>Click on <i>Add custom field</i> to add a new custom field.</li>
<li>Select the column from the dropdown which has the names of the receivers.</li>
<li>In <i>Key to be replaced </i>box, type a unique key which will be present in the message.<br><b>Note: </b>All the instances of this key from the message will be replaced by the value from the column you selected.</li>
<li>The <i>key</i> is case sensitive and should be unique, Some examples keys could be <b>{NAME}</b>, <b>"NAME"</b>, etc. Using <i>{</i> and <i>"</i> toi provide uniqueness.</li>
</ul>
And Voilà! All your messages will now have the dynamic names.
<br><br>
The above method can be used to add any number of custom fields to create dynamic messages from the CSV file and add unique receiver specific attributes in the messages.
<br><br>For example, if the key you selected is <b>NAME</b> which maps to name column in the CSV file and the message you type is, <br>
<span style="color:grey">Hi NAME,<br>Thank you being a valuable customer. Please use the code NAME-123 as coupon code for 10% off.</span><br><br>If the name column has the value <i>John</i> for a customer, following will be the actual message that will be sent.<br>
<span style="color: #68d10d;">Hi John,<br>Thank you being a valuable customer. Please use the code John-123 as coupon code for 10% off.</span>
</li>
</ol>
</section>
<!-- </div> -->
<section id="lab_social_icon_footer">
<div class="container">
<div class="text-center center-block">
<a href="https://github.com/DefCon-007/WhatSend" target="_blank"><i id="social-fb"
class="fa fa-github fa-3x social"></i></a>
<a href="https://twitter.com/@defcon_007" target="_blank"><i id="social-tw"
class="fa fa-twitter fa-3x social"></i></a>
<a href="https://defcon007.com" target="_blank"><i id="social-gp"
class="fa fa-globe fa-3x social"></i></a>
<a href="mailto:[email protected]" target="_blank"><i id="social-em"
class="fa fa-envelope-square fa-3x social"></i></a>
</div>
<br>
<p class="footer-heart">
Made with <g-emoji class="g-emoji" alias="heart"
fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2764.png">
<img class="emoji" alt="heart" height="20" width="20"
src="https://github.githubassets.com/images/icons/emoji/unicode/2764.png"></g-emoji> by <a
href="https://defcon007.com" target="_blank">DefCon</a>
</p>
</div>
</section>
</div>
<script>
// Initialise Sentry
Sentry.init({
dsn: 'https://[email protected]/5418941',
});
var csvData = [];
var table_element = null;
$.fn.dataTable.ext.order['dom-image-check'] = function (settings, col) {
return this.api().column(col).nodes().map(function (td, i) {
if (td.getAttribute('data-sort') === "success") {
return '1'
} else {
return '0'
}
});
}
$(document).ready(function () {
table_element = $('#table-id').DataTable({
dom: 'Bfrtip',
buttons: [
'copy', 'csv', 'excel', 'pdf', 'print'
],
"columns": [
null,
null,
null,
{ "orderDataType": "dom-image-check" },
]
});
});
const CUSTOM_ELEMENT_CONTAINER_ID = 'customInputs'
let WINDOW_INTERVAL_IDS = []
function replaceAll(data, findStr, replaceStr){
if (data){
return data.replace(new RegExp(findStr, "g"), replaceStr)
} else {
return ""
}
}
function getCurrentCustomDataCount() {
const customElements = document.getElementById(CUSTOM_ELEMENT_CONTAINER_ID);
return customElements.childElementCount;
}
function addCustomField() {
const outerContainerDiv = document.getElementById(CUSTOM_ELEMENT_CONTAINER_ID)
const newElementUID = `${getCurrentCustomDataCount() + 1}-${new Date().getTime()}`
var id = `customInputData-${newElementUID}`
const lineBreak = document.createElement("br")
const customElemDiv = document.createElement('div')
customElemDiv.setAttribute('class', 'form-group border p-3')
customElemDiv.setAttribute('id', id)
// Input and remove element button container
const label = document.createElement('label')
const inputLabel = document.createElement('label')
const removeButton = document.createElement('button')
removeButton.innerText = "Remove field"
removeButton.setAttribute('type', 'button')
removeButton.setAttribute('class', 'btn btn-danger mt-2')
removeButton.setAttribute('onClick', `removeCustomField("${id}")`)
const SelectId = `customSelect-${newElementUID}`
label.setAttribute('for', SelectId)
label.innerText = "Select column for custom data"
const select = document.createElement('select')
select.setAttribute('id', SelectId)
select.setAttribute('class', 'form-control')
const input = document.createElement('input')
const inputId = `customInput-${newElementUID}`
input.setAttribute('type', 'text')
input.setAttribute('id', inputId)
input.setAttribute('class', 'form-control')
input.setAttribute('placeholder', 'Enter key to replace by')
inputLabel.innerText = "Key to be replaced from message"
inputLabel.setAttribute('for', inputId)
customElemDiv.appendChild(label)
customElemDiv.appendChild(select)
customElemDiv.appendChild(lineBreak)
customElemDiv.appendChild(inputLabel)
customElemDiv.appendChild(input)
customElemDiv.appendChild(removeButton)
outerContainerDiv.appendChild(customElemDiv);
updateSelectOptions(select)
$.toast({
heading: 'New custom text element added', // Optional heading to be shown on the toast
icon: 'success', // Type of toast icon
showHideTransition: 'slide', // fade, slide or plain
allowToastClose: false, // Boolean value true or false
hideAfter: 3000, // false to make it sticky or number representing the miliseconds as time after which toast needs to be hidden
stack: false, // false if there should be only one toast at a time or a number representing the maximum number of toasts to be shown at a time
position: 'bottom-left', // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values
textAlign: 'left', // Text alignment i.e. left, right or center
loader: false
});
}
function removeCustomField(elementId) {
const element = document.getElementById(elementId);
element.parentNode.removeChild(element);
$.toast({
heading: 'Custom text element removed', // Optional heading to be shown on the toast
icon: 'error', // Type of toast icon
showHideTransition: 'slide', // fade, slide or plain
allowToastClose: false, // Boolean value true or false
hideAfter: 3000, // false to make it sticky or number representing the miliseconds as time after which toast needs to be hidden
stack: false, // false if there should be only one toast at a time or a number representing the maximum number of toasts to be shown at a time
position: 'bottom-left', // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values
textAlign: 'left', // Text alignment i.e. left, right or center
loader: false
});
}
function addCustomFieldDataToMessage(message){
const container = document.getElementById(CUSTOM_ELEMENT_CONTAINER_ID);
const customElements = container.childNodes;
}
function removeOptions(selectElement) {
var i, L = selectElement.options.length - 1;
for (i = L; i >= 0; i--) {
selectElement.remove(i);
}
}
function updateSelectOptions(selectElement) {
const keys = _.keys(_.first(csvData));
const numberSelectElement = document.getElementById('numberselect');
var all_options = []
_.forEach(keys, key => {
// Add dropdown options of table columns
var opt = document.createElement("option");
opt.text = key;
opt.value = key;
all_options.push(opt)
});
let customElements = []
if (selectElement){
customElements = [selectElement]
} else {
customElements.push(numberSelectElement)
customElementsContainer = document.getElementById(CUSTOM_ELEMENT_CONTAINER_ID).getElementsByTagName('div')
_.forEach(customElementsContainer, customElement => {
const selectElement = customElement.getElementsByTagName('select')[0]
customElements.push(selectElement)
})
}
_.forEach(customElements, selectElement => {
removeOptions(selectElement)
_.forEach(all_options, option => {
selectElement.options.add(option.cloneNode(true));
})
})
}
$('#csvFile').change(function (event) {
// File changed, parse it
$('#csvFile').parse({
config: {
header: true,
complete: (results) => {
csvData = results['data'];
updateSelectOptions();
}
},
before: function (file, inputElem) {
},
error: function (err, file) {
Swal.fire({
icon: 'error',
title: 'Unable to process file, please try with different file'
}
);
},
complete: function () {
$.toast({
heading: 'File parsing complete', // Optional heading to be shown on the toast
text: `CSV file successfully parsed with ${_.size(csvData)} rows.`,
icon: 'info', // Type of toast icon
showHideTransition: 'slide', // fade, slide or plain
allowToastClose: true, // Boolean value true or false
hideAfter: 4000, // false to make it sticky or number representing the miliseconds as time after which toast needs to be hidden
stack: false, // false if there should be only one toast at a time or a number representing the maximum number of toasts to be shown at a time
position: 'bottom-left', // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values
textAlign: 'left', // Text alignment i.e. left, right or center
loader: false
});
}
});
})
function getCleanNumber(num) {
const digitRegex = /\d+/g;
matches = digitRegex.exec(num)
var num_clean = ""
_.forEach(matches, function (match) {
num_clean += match
})
if (num_clean.length == 10) {
num_clean = "91" + num_clean;
}
return num_clean;
}
function titleCase(str) {
str = str.toLowerCase().split(' ');
for (var i = 0; i < str.length; i++) {
str[i] = str[i].charAt(0).toUpperCase() + str[i].slice(1);
}
return str.join(' ');
}
function getListOfCleanMobileNumbers(){
const validNumbers = []
const invalidNumbers = []
let totalNumbers = []
// Returns the array of mobile numbers to which the message will be sent
if (specificationForm.csvFile.value) {
// Get mobile number list from CSV
const numberCol = document.getElementById("numberselect").value;
totalNumbers = _.map(csvData, numberCol)
} else if (specificationForm.commaSeparatedNumbers.value) {
// Get mobile number list from input field
totalNumbers = _.split(specificationForm.commaSeparatedNumbers.value, ',')
}
_.forEach(totalNumbers, number => {
let cleanNumber = getCleanNumber(number);
if (cleanNumber) {
validNumbers.push(cleanNumber);
} else {
invalidNumbers.push(number)
}
})
return { invalidNumbers, validNumbers, totalNumbers}
}
var urlsList = [];
var timer = null;
window.tabWindows = false;
function openURLinWindow(item) {
var win = window.open(item['url'], "com_defcon007_whatsSend");
addToProcessedTable(item);
return win;
}
function addToProcessedTable(item) {
var row_node = table_element.row.add([
item['index'],
item['name'],
item['number'],
' ',
]).draw(false).node();
var tds = row_node.getElementsByTagName("td");
tds[3].setAttribute('data', item['number']);
tds[3].setAttribute('data-type', 'status');
}
async function polling() {
if (urlsList.length == 0) {
// Make status of all empty as warning now!
var elems = document.querySelectorAll("td[data-type='status']")
for (var i = 0; i < elems.length; i++) {
elem = elems[i];
if (!(elem.innerHTML.toString().trim())) {
// No status added right now add one
elem.innerHTML = "<img src='https://raw.githubusercontent.com/DefCon-007/WhatSend/master/images/Warning.svg?sanitize=true' />"
}
}
Swal.fire({
icon: 'success',
title: 'All messages sent!'
}
);
_.forEach(WINDOW_INTERVAL_IDS, intervalId => {
clearInterval(intervalId);
clearTimeout();
})
return;
}
if (window.tabWindow && window.tabWindow.closed) {
window.tabWindow = openURLinWindow(urlsList.pop())
}
}
function formSubmit() {
if (!specificationForm.csvFile.value && !specificationForm.commaSeparatedNumbers.value) {
// Neither csv file nor mobile number list provided
$.toast({
heading: 'Essential data missing', // Optional heading to be shown on the toast
text: 'Either upload a CSV file with numbers column or add a list of mobile numbers',
icon: 'error', // Type of toast icon
showHideTransition: 'slide', // fade, slide or plain
allowToastClose: true, // Boolean value true or false
hideAfter: false, // false to make it sticky or number representing the miliseconds as time after which toast needs to be hidden
stack: false, // false if there should be only one toast at a time or a number representing the maximum number of toasts to be shown at a time
position: 'bottom-left', // bottom-left or bottom-right or bottom-center or top-left or top-right or top-center or mid-center or an object representing the left, right, top, bottom values
textAlign: 'left', // Text alignment i.e. left, right or center
loader: false
});
return false;
}
var messageStr = document.getElementById("message").value;
// Get preview message
const dataToUpdate = getListOfValuesToReplace();
var previewMessage = messageStr;
var messageToSend = messageStr
_.forEach(dataToUpdate, dataToReplace => {
previewMessage = replaceAll(previewMessage, dataToReplace.keyToReplace, `<i><b>${dataToReplace.columnName}</b></i>`)
if (!specificationForm.csvFile.value && specificationForm.commaSeparatedNumbers.value) {
// Sending message to list of numbers, replace numbers
messageToSend = replaceAll(messageToSend, dataToReplace.keyToReplace, "");
}
})
previewMessage = replaceAll(previewMessage, '\r\n', '<br>')
previewMessage = replaceAll(previewMessage, '\n', '<br>')
previewMessage = replaceAll(previewMessage, '\r', '<br>')
const {invalidNumbers, validNumbers, totalNumbers} = getListOfCleanMobileNumbers()
const sweetAlertQueue = []
let progressSteps = ['1', '2']
if (_.size(invalidNumbers) > 0){
const invalidNumberList = _.join(_.map(invalidNumbers, number => {
return `<li>${number}</li>`
}), "")
const alertText = `Following ${_.size(invalidNumbers)} out of ${_.size(csvData)} number(s) are invalid for which message cannot be sent. Either update them after clicking Cancel or click Next to continue<br />
<div class="clusterize-scroll px-5 py-2">
<ol class="clusterize-content">${invalidNumberList}</ol>
</div>
`
sweetAlertQueue.push({
title: 'Invalid Numbers',
html: alertText,
})
progressSteps = ['1', '2', '3']
}
// List of valid numbers
const validNumberList = _.join(_.map(validNumbers, number => {
return `<li>${number}</li>`
}), "")
const validNumberAlertText = `Message will be sent to the following ${_.size(validNumbers)} out of ${_.size(csvData)} number(s).<br />
<div class="clusterize-scroll px-5 py-2">
<ol class="clusterize-content">${validNumberList}</ol>
</div>
`
sweetAlertQueue.push({
title: 'Valid Numbers',
html: validNumberAlertText
})
sweetAlertQueue.push(
{
title: 'Message preview',
html: previewMessage,
showCancelButton: true,
confirmButtonColor: '#25cf19',
confirmButtonText: 'Start Sending'
}
)
Swal.mixin({
confirmButtonText: 'Next →',
showCancelButton: true,
progressSteps: progressSteps
}).queue(sweetAlertQueue).then((result) => {
if (result.value) {
if (!specificationForm.csvFile.value && specificationForm.commaSeparatedNumbers.value){
startMessageSending(validNumbers, messageToSend);
} else {
// Sending to list of numbers from CSV file
startMessageSending(null, messageToSend);
}
}
})
}
function getListOfValuesToReplace(){
const dataToUpdate = [];
let customElementsContainer = document.getElementById(CUSTOM_ELEMENT_CONTAINER_ID).getElementsByTagName('div')
_.forEach(customElementsContainer, customElement => {
try {
const selectElement = customElement.getElementsByTagName('select')[0]
const replacementKey = customElement.getElementsByTagName('input')[0]
if (selectElement.value && replacementKey.value) {
dataToUpdate.push({
columnName: selectElement.value,
keyToReplace: replacementKey.value
})
}
} catch(e) {
}
})
return dataToUpdate;
}
function getWhatsAppAPIURL(number, message){
return `https://web.whatsapp.com/send?phone=${number}&text=${encodeURIComponent(message)}`;
}
function startMessageSending(numbersToSend, messageToSend) {
const numberCol = document.getElementById("numberselect").value;
var messageStr = document.getElementById("message").value;
if (numbersToSend){
// CSV file was not added, send message directly
_.forEachRight(numbersToSend, function(number, index) {
let url = getWhatsAppAPIURL(number, messageToSend);
urlsList.push({
url: url,
name: "",
index: index + 1,
number: number
});
})
} else {
// Parse CSV file to send
const dataToUpdate = getListOfValuesToReplace();
_.forEachRight(csvData, function (data, index) {
const clean_number = getCleanNumber(data[numberCol]);
if (!clean_number) {
return;
}
// Replace variable in message
let clean_message = messageToSend
_.forEach(dataToUpdate, dataToReplace => {
clean_message = replaceAll(clean_message, dataToReplace.keyToReplace, _.get(data, dataToReplace.columnName));
});
var url = getWhatsAppAPIURL(clean_number, clean_message)
urlsList.push({
url: url,
name: name,
index: index + 1,
number: clean_number
});
})
}
window.tabWindow = openURLinWindow(urlsList.pop())
var intervalId = setInterval('polling()', 1000);
WINDOW_INTERVAL_IDS.push(intervalId);
}
window.addEventListener("message", function (event) {
// We only accept messages from ourselves
console.log("Listening msg from webspage");
console.log(event)
if (event.source != window)
return;
if (event.data.type && (event.data.type == "FROM_PAGE")) {
console.log("Content script received message: " + event.data.text);
}
});
</script>
</body>
</html>