Last active
September 19, 2020 03:17
-
-
Save rmff/e47276bb2afdafdf35dafb4faa14a0fd to your computer and use it in GitHub Desktop.
Bookmarklet to direct chat or call a WhatsApp number. No need to save number before, number normalized for Brazilian format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function (loc, msgInput, msgCheck, msgDefault, reTest, reReplace, countryCode, areaCode, s, r) { | |
s = prompt(msgInput, ''); | |
while(!reTest.test(s) && s){ | |
s = s.replace(/\D/g, '').replace(reReplace, | |
function(match, p1, p2, p3, offset, string){ | |
r = p1 || '55'; | |
r += p2 || '11'; | |
r += p3; | |
return r; | |
}) | |
s = prompt(msgCheck, s); | |
} | |
if(s) { | |
open('https://wa.me/' + s + '?l='+ loc +'&text=' + encodeURIComponent(msgDefault) + '&r' + Math.floor(Math.random() * 100)).focus(); | |
} | |
})('ptbr', | |
'Enter WhatsApp Number to sanitize', | |
'Check formated WhatsApp Number (country code + area code + local number)', | |
'Default msg', | |
/^(55)(\d{2})(\d{8,9})$/g, | |
/^(55)?(\d{2})?(\d{8,9})$/g, | |
'55', | |
'11' | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(loc,msgInput,msgCheck,msgDefault,reTest,reReplace,countryCode,areaCode,s,r){s=prompt(msgInput,"");while(!reTest.test(s)&&s){s=s.replace(/\D/g,"").replace(reReplace,function(match,p1,p2,p3,offset,string){r=p1||"55";r+=p2||"11";r+=p3;return r});s=prompt(msgCheck,s)}if(s){open("https://wa.me/"+s+"?l="+loc+"&text="+encodeURIComponent(msgDefault)+"&r"+Math.floor(Math.random()*100)).focus()}})("ptbr","Enter WhatsApp Number to sanitize","Check formated WhatsApp Number (country code + area code + local number)","Default msg",/^(55)(\d{2})(\d{8,9})$/g,/^(55)?(\d{2})?(\d{8,9})$/g,"55","11"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment