-
Notifications
You must be signed in to change notification settings - Fork 31
/
deeplink.js
45 lines (43 loc) · 1.14 KB
/
deeplink.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
37
38
39
40
41
42
43
44
45
(function (window) {
const HOST = window.location.hostname;
const PORT = window.location.port;
const TARGET_URL = `//${HOST}:${PORT}`;
function sendDeepLink() {
const intentURI = [
`intent:${TARGET_URL}/wedding#Intent`,
'scheme=https',
`S.browser_fallback_url=${TARGET_URL}/wedding`,
'end',
].join(';');
window.location.href = intentURI;
}
function isLatestWebView() {
return /Version\/[.0-9]* Chrome\/[.0-9]*/.test(navigator.userAgent);
}
function isAndroidDevice() {
return /Android/.test(navigator.userAgent);
}
function isSamsungBrowser() {
return /SamsungBrowser/.test(navigator.userAgent);
}
function isChrome() {
return /Chrome/.test(navigator.userAgent);
}
function goToWeddingSite() {
window.location.href = `${TARGET_URL}/wedding`;
}
const deeplink = {
createBrowser() {
if (isAndroidDevice()) {
if (isLatestWebView() || (!isSamsungBrowser() && !isChrome())) {
sendDeepLink();
} else {
goToWeddingSite();
}
} else {
goToWeddingSite();
}
},
};
window.deeplink = deeplink;
}(window));