forked from mukulhase/WebWhatsapp-Wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
contactfromnumber.js
36 lines (36 loc) · 974 Bytes
/
contactfromnumber.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
function match(pno, id){
return lcs(pno, id).length > (pno.length - 2)
}
function lcs(lcstest, lcstarget) {
matchfound = 0;
lsclen = lcstest.length;
for(lcsi=0; lcsi<lcstest.length; lcsi++){
lscos=0;
for(lcsj=0; lcsj<lcsi+1; lcsj++){
re = new RegExp("(?:.{" + lscos + "})(.{" + lsclen + "})", "i");
temp = re.test(lcstest);
re = new RegExp("(" + RegExp.$1 + ")", "i");
if(re.test(lcstarget)){
matchfound=1;
result = RegExp.$1;
break;
}
lscos = lscos + 1;
}
if(matchfound==1){return result; break;}
lsclen = lsclen - 1;
}
result = "";
return result;
}
function getContactName(pno){
var contacts = window.Store.Contact.models;
for(var i in contacts){
console.log(i, Number.isInteger(i));
if(i!="remove"){
if(match(pno,contacts[i]._values.id))
return [contacts[i]._values.id, contacts[i]._values.name];
}
}
return false;
}