-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
232 lines (207 loc) · 9.08 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Number Extractor</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.wrapper {
padding: 10px;
}
.sent {
text-decoration: none;
color: gray;
font-style: italic;
}
.button {
background-color: deepskyblue;
border: none;
color: white;
padding: 8px 12px;
margin-top: 10px;
margin-bottom: 10px;
border-radius: 6px;
}
.button:disabled {
background-color: gray;
}
</style>
</head>
<body>
<div class="wrapper">
<div style="width: 100%;">
<textarea id="editor" placeholder="Paste Your Log.html content" style="width: 100%; height: 250px; border-radius: 6px; padding: 8px;"></textarea>
</div>
<div style="display: flex; gap: 8px;">
<button class="button" id="btn" onclick="fetchServerText()">Get Server Text</button>
<button class="button" id="copy-btn" onclick="initCopy()">Copy Numbers</button>
</div>
<div id="unique-phones-counter"></div>
<div id="sent-numbers-counter"></div>
<div id="whatsapp"></div>
</div>
<script>
const btn = document.getElementById("btn");
const copyBtn = document.getElementById("copy-btn");
const textArea = document.getElementById("editor");
const output = document.getElementById("whatsapp");
const totalCustomers = document.getElementById("unique-phones-counter");
const sentNumbers = document.getElementById("sent-numbers-counter");
let sentPhoneNumbers = [];
const PHONE_STORAGE_KEY = "sentPhoneNumbers"
const phoneStorage = localStorage.getItem(PHONE_STORAGE_KEY);
if(phoneStorage) {
sentPhoneNumbers = JSON.parse(phoneStorage);
}
let allPhonesArray = [];
textArea.addEventListener("input", (e)=> {
const value = e.target.value.trim();
if(value.length > 0) {
const itemsArray = value.split("====================Log Message Ends====================");
let phonesObj = {};
itemsArray.forEach((singleItem, index)=> {
const itemSplit = singleItem.split("Click here to clear everything");
if(itemSplit.length > 0) {
const firstItem = itemSplit[0];
const nameAndNumberSplit = firstItem.split("Message:");
if(nameAndNumberSplit.length > 1) {
const nameAndNumber = nameAndNumberSplit[1];
const initialPhoneZeroIndex = nameAndNumber.indexOf(" 0");
const initialPhonePlusIndex = nameAndNumber.indexOf(" +");
let phoneStartIndex = 0;
if(initialPhoneZeroIndex > -1) {
//it starts with 0
phoneStartIndex = initialPhoneZeroIndex;
} else {
//it starts with +
phoneStartIndex = initialPhonePlusIndex
}
const name = nameAndNumber.substring(0, phoneStartIndex).trim();
const phoneString = nameAndNumber.substring(phoneStartIndex, nameAndNumber.length).trim();
const phonesArray = phoneString.split("/");
let phonesWithCountryCode = [];
phonesArray.forEach((phone)=> {
//only take phone numbers when they start with 0 or + sign
if(phone.startsWith("0")) {
phonesWithCountryCode.push(phone.replace("0", "+255"))
allPhonesArray.push(phone.replace("0", "+255"));
} else if(phone.startsWith("+")) {
phonesWithCountryCode.push(phone)
allPhonesArray.push(phone);
}
});
if(phonesWithCountryCode.length > 0) {
phonesObj[name] = {
name,
phone: phonesWithCountryCode
}
}
}
}
});
const uniqueCustomers = [];
for(let key in phonesObj) {
uniqueCustomers.push(phonesObj[key]);
}
output.innerHTML = "";
//create HTML
uniqueCustomers.forEach((item)=> {
const divWrapper = document.createElement("div");
divWrapper.style.paddingTop = "30px";
const nameDiv = document.createElement("div");
nameDiv.innerHTML = item.name;
divWrapper.append(nameDiv);
item.phone.forEach((phone)=> {
const link = document.createElement("a");
link.style.display = "block";
link.style.paddingTop = "2px";
link.style.paddingBottom = "2px";
link.innerText = `Send WhatsApp To ${phone}`;
const messageToCustomer = `Habari yako ${item.name}? Karibu uendelee kusafirisha mizigo yako nasi kwa ndege ✈️ toka China 🇨🇳 kuja Tanzania 🇹🇿 kwa Haraka ⚡️ Na Nafuu 💰. Flight ✈️ yetu inayofuata ni hii hapa https://www.umojaexpresscargo.com/single-post?id=6wk56sark3
Ukitaka kijifunza jinsi ya kutumia Alibaba kununua bidhaa kwa rejareja kwa nafuu fungua link hii https://www.umojaexpresscargo.com/single-post?id=e7tyr6tmp6`;
link.setAttribute("href",`https://api.whatsapp.com/send/?phone=${phone}&text=${encodeURIComponent(messageToCustomer)}`);
link.setAttribute("target", "_blank");
if(sentPhoneNumbers.indexOf(phone) > -1) {
link.classList.add("sent");
}
link.addEventListener("click", () => {
sentPhoneNumbers.push(phone);
localStorage.setItem(PHONE_STORAGE_KEY, JSON.stringify(sentPhoneNumbers));
link.classList.add("sent");
sentNumbers.innerText = `Messaged Phone Numbers = ${sentPhoneNumbers.length}`;
})
divWrapper.append(link);
})
output.append(divWrapper);
});
totalCustomers.innerText = `Total Customers = ${uniqueCustomers.length}`;
sentNumbers.innerText = `Messaged Phone Numbers = ${sentPhoneNumbers.length}`;
} else {
output.innerHTML = "";
totalCustomers.innerText = `Total Customers = 0`;
sentNumbers.innerText = `Messaged Phone Numbers = 0`;
}
});
const fetchServerText = () => {
btn.setAttribute("disabled", true);
btn.innerText = "Please Wait...";
copyBtn.setAttribute("disabled", true);
fetch('https://api.umojaexpresscargo.com/address-log.html') // api for the get request
.then(response => response.text())
.then(html => {
const wrapper = document.createElement("div");
wrapper.innerHTML = html;
textArea.innerText = wrapper.innerText.trim();
textArea.dispatchEvent(new Event("input"));
btn.innerText = "Get Server Text";
btn.removeAttribute("disabled");
copyBtn.removeAttribute("disabled");
}).catch(()=> {
btn.innerText = "Get Server Text";
btn.removeAttribute("disabled");
copyBtn.removeAttribute("disabled");
});
}
const initCopy = () => {
const phonesString = allPhonesArray.join("\n");
copyText(phonesString);
}
const copyText = (phrase) => {
try {
if (!navigator || !navigator.clipboard || !navigator.clipboard.writeText) {
const textArea = document.createElement("textarea");
textArea.value = phrase;
// Avoid scrolling to bottom
textArea.style.top = "-400px";
textArea.style.left = "-400px";
textArea.style.position = "fixed";
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
const successful = document.execCommand("copy");
alert("Copied");
} catch (err) {
}
document.body.removeChild(textArea);
return;
}
navigator.clipboard
.writeText(phrase)
.then(() => {
alert("Copied");
})
.catch(() => {
});
} catch (e) {
//it will never go in here
}
}
</script>
</body>
</html>