-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
82 lines (76 loc) · 2.66 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<meta name="theme-color" content="#00ff00">
<link rel="stylesheet" href="assets/css/main.css">
<link rel="stylesheet" href="assets/css/intlTelInput.css">
<link rel="manifest" href="manifest.json">
</head>
<body>
<div class="wrapper">
<div class="form">
<input type="tel" id="phone">
<button id="openWApp">Go to Address</button>
</div>
</div>
<script src="assets/js/intlTelInput.js"></script>
<script>
let input = document.querySelector("#phone");
// window.intlTelInput(input,{
// // any initialisation options go here
// });
let inttel = window.intlTelInput(input, {
initialCountry: "auto",
geoIpLookup: function(success, failure) {
fetch('https://get.geojs.io/v1/ip/geo.js')
.then((response) => response.text())
.then((data) => {
success("us");
if(data && data.includes("geoip")){
let jsonStr = data.replace('geoip(','').replace('})','}');
if(isJsonString(jsonStr)){
let json = JSON.parse(jsonStr);
if(json.country_code){
success(json.country_code);
}
}
}
// const cc = data.match(/"country_code7":"([^"]+)"/)[1];
// const countryCode = data && cc ? cc : "us" ;
// button.html()
// const h = JSON.parse(data);
// console.log(data)
// success(countryCode);
});
},
});
function isJsonString(str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
document.getElementById("openWApp").addEventListener("click",function(){
// const code = document.querySelector(".iti__country iti__standard iti__active");
// console.log(inttel.selectedCountryData.dialCode);
const code = inttel.selectedCountryData.dialCode;
if(code && input.value.trim()){
window.location.href = "https://wa.me/"+code+input.value;
}
// navigator.serviceWorker.controller.postMessage({
// type: 'MESSAGE_IDENTIFIER',
// id: 'test',
// });
});
if("serviceWorker" in navigator){
navigator.serviceWorker.register("/sw.js")
}
</script>
</body>
</html>