-
Notifications
You must be signed in to change notification settings - Fork 2
/
redir.html
65 lines (58 loc) · 2.82 KB
/
redir.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
<html>
<script src="https://cdn.jsdelivr.net/npm/mobile-detect@1.4.3/mobile-detect.min.js"></script>
<body>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
// Redirect to Apple App Store / Google Play Store / Web Browser apps depending on mobile/web platform
// with thanks to http://hgoebl.github.io/mobile-detect.js/
// Example usage (all available options shown):
// redir.html?app=donor&ln=en
// redir.html?app=admin&ln=zh-tw
// redir.html?app=stock&ln=en
// redir.html?app=browse&ln=zh-tw
var url_map = {
donor: {iOS: 'https://itunes.apple.com/in/app/goodcity.hk/id1012253845', AndroidOS: 'https://play.google.com/store/apps/details?id=hk.goodcity.app', web: 'https://app.goodcity.hk/'},
admin: {iOS: 'https://itunes.apple.com/in/app/goodcityadmin-hk/id1013288708', AndroidOS: 'https://play.google.com/store/apps/details?id=hk.goodcity.admin', web: 'https://admin.goodcity.hk/'},
stock: {iOS: 'https://itunes.apple.com/in/app/goodcitystock-hk/id1144806764', AndroidOS: 'https://play.google.com/store/apps/details?id=hk.goodcity.stock', web: 'https://stock.goodcity.hk/'},
browse: {iOS: 'https://browse.goodcity.hk/', AndroidOS: 'https://play.google.com/store/apps/details?id=hk.goodcity.browse', web: 'https://browse.goodcity.hk/'},
feedback: {iOS: 'https://crossroads-foundation.formstack.com/forms/goodcity_feedback', AndroidOS: 'https://crossroads-foundation.formstack.com/forms/goodcity_feedback', web: 'https://crossroads-foundation.formstack.com/forms/goodcity_feedback'},
a: {iOS: 'https://crossroads-foundation.formstack.com/forms/novemberfair', AndroidOS: 'https://crossroads-foundation.formstack.com/forms/novemberfair', web: 'https://crossroads-foundation.formstack.com/forms/novemberfair'}
}
function getParameterByName(name) {
var match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
}
// whitelist only 4 app options in query string
var query_string_app = getParameterByName('app');
switch(query_string_app) {
case 'admin':
app = 'admin';
break;
case 'stock':
app = 'stock';
break;
case 'browse':
app = 'browse';
break;
case 'feedback':
app = 'feedback';
break;
case 'a':
app = 'a';
break;
default:
app = 'donor';
}
// Explicitly 'zh-tw' or otherwise 'en'
var ln = (getParameterByName('ln') === 'zh-tw') ? 'zh-tw' : 'en';
var md = new MobileDetect(window.navigator.userAgent);
var os = md.os();
var url = url_map[app][os]
if (!url) {
url = url_map[app]['web'] + '?ln=' + ln
}
document.location = url;
});
</script>
</body>
</html>