Skip to content

Instantly share code, notes, and snippets.

@Bloody-Badboy
Created July 19, 2023 15:13
Show Gist options
  • Save Bloody-Badboy/c3a6fbdc4ec9c8a5bb03c05b57498e92 to your computer and use it in GitHub Desktop.
Save Bloody-Badboy/c3a6fbdc4ec9c8a5bb03c05b57498e92 to your computer and use it in GitHub Desktop.
launch app from web page πŸ”₯ πŸš€
<!DOCTYPE html>
<html>
<head>
<meta name="deepview-service" content="deepview-service" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
</head>
<body>
<script type="text/javascript">
let timeoutToDownload = 0;
let visibility = {
isInBackground: false,
hideTime: 0,
};
const windowLocation = window.top.location || window.location;
const isMobile = () => {
const u = navigator.userAgent;
return !!u.match(/Mobile|iP(hone|ad)|Android/i);
};
const isIos = () => {
const u = navigator.userAgent;
return !!u.match(/iPhone|iP(hone|ad)/i);
};
const isAndroid = () => {
const u = navigator.userAgent;
return !!u.match(/Android/i);
};
const isHuawei = () => {
const u = navigator.userAgent;
return !!u.match(/HarmonyOS|Huawei/i);
};
const bindVisibilityChange = () => {
let hiddenName, visibilityChangeName;
if (document.hidden !== undefined) {
hiddenName = "hidden";
visibilityChangeName = "visibilitychange";
} else if (document.mozHidden !== undefined) {
hiddenName = "mozHidden";
visibilityChangeName = "mozvisibilitychange";
} else if (document.msHidden !== undefined) {
hiddenName = "msHidden";
visibilityChangeName = "msvisibilitychange";
} else if (document.webkitHidden !== undefined) {
hiddenName = "webkitHidden";
visibilityChangeName = "webkitvisibilitychange";
}
console.log(
`hiddenName: ${hiddenName}, visibilityChangeName: ${visibilityChangeName}`
);
const onHide = () => {
console.log("onHide");
visibility.isInBackground = true;
visibility.hideTime = new Date().getTime();
};
const onShow = () => {
console.log("onShow");
const showTime = new Date().getTime();
if (showTime - visibility.hideTime > 1500) {
clearTimeout(timeoutToDownload);
}
visibility.isInBackground = false;
};
if (hiddenName) {
document.addEventListener(
visibilityChangeName,
(event) => {
const isHidden = document[hiddenName];
if (isHidden) {
onHide();
} else {
onShow();
}
},
false
);
} else {
window.addEventListener("blur", onHide(), false);
window.addEventListener("focus", onShow(), false);
}
};
const openDownloadUrl = () => {
if (isIos()) {
windowLocation.href = "https://apps.apple.com/app/id955440154";
return;
}
if (isAndroid()) {
if (isHuawei()) {
windowLocation.href =
"https://appgallery.huawei.com/#/app/C100681983";
} else {
windowLocation.href =
"https://play.google.com/store/apps/details?id=com.traveller";
}
}
};
const start = () => {
bindVisibilityChange();
if (!isMobile()) {
windowLocation.href = "https://travellerpass.com";
return;
}
windowLocation.href = "travellerpass://home";
timeoutToDownload = setTimeout(() => {
!visibility.isInBackground && openDownloadUrl();
}, 3000);
};
window.addEventListener("load", start, false);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment