forked from binary-com/binary-static
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path404.html
More file actions
107 lines (100 loc) · 3.79 KB
/
404.html
File metadata and controls
107 lines (100 loc) · 3.79 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html>
<head>
<title>Binary.com</title>
<meta charset="utf-8" />
<script type="text/javascript">
function getCookieItem(sKey) {
'use strict';
return decodeURIComponent(document.cookie.replace(new RegExp("(?:(?:^|.*;)\\s*" + encodeURIComponent(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*([^;]*).*$)|^.*$"), "$1")) || null;
}
var langs = {
'de': 'de|at|li',
'es': 'ar|bo|cl|co|cr|cu|do|ec|sv|gt|hn|mx|ni|pa|py|pr|es|uy|ve',
'fr': 'fr|ad|bj|bf|cf|cg|ga|gn|ml|mc|ne|sn|tg',
'id': 'id',
'it': 'it',
'ja': 'jp',
'ko': 'kr',
'pl': 'po',
'pt': 'br|mz|ao|pt|gw|pg|cv|st',
'ru': 'ru|ua|by|kz',
'th': 'th',
'vi': 'vn',
'zh_tw': 'tw|mo',
'zh_cn': 'cn|sg',
};
function getLanguage(country) {
var conLang = 'en';
if (country) {
var keys = Object.keys(langs);
for (var i = keys.length; i--; ) {
var l = keys[i];
if ((new RegExp(langs[l], 'i')).test(country)) {
return l;
}
}
}
return conLang;
}
function getRoot() {
var hostname = window.location.hostname;
var origin = window.location.origin;
return /^(.+?).github.io$/.test(hostname) ?
origin + '/binary-static' :
origin;
}
const all_languages = ['en'].concat(Object.keys(langs));
function redirect() {
var alternative_pages = ['home', 'why-us', 'tour', 'terms-and-conditions', 'signup', 'get-started'];
var redirect_to;
var alt_regex = new RegExp('(' + alternative_pages.map(function(page) { return page + '.html|' + page + '-jp.html' }).join('|') + ')', 'i');
if (alt_regex.test(href)) {
href = href.replace(alt_regex, function(match) {
if (/-jp/.test(match) && !/ja/i.test(lang)) {
redirect_to = match.replace(/-jp/i, '');
} else if (!/-jp/.test(match) && /ja/i.test(lang)) {
redirect_to = match.replace(/\.html/i, '-jp.html');
}
return redirect_to || match;
});
}
// if language is wrong, we need to rebuild the url
var lang_regex = new RegExp('/(' + all_languages.join('|') + ')/', 'i');
if (!lang_regex.test(href)) {
redirect_to = redirect_to || '404';
href = getRoot() + '/' + lang.toLowerCase() + '/' + redirect_to.replace(/\.html/i, '') + '.html';
}
// if not alternate page, redirect to 404 page
if (!redirect_to) {
href = href.replace(new RegExp('(/' + lang + '/).*', 'i'), '$1404.html');
}
window.location = href;
}
var href = window.location.href;
var lang = href.split('/').slice(3).find(function(language) { return all_languages.indexOf(language.toLowerCase()) > -1 }) || getCookieItem('language');
if (lang && all_languages.indexOf(lang.toLowerCase()) > -1) {
redirect();
} else {
var ws = new WebSocket('wss://ws.binaryws.com/websockets/v3?app_id=1');
ws.onopen = function(e) {
ws.send(JSON.stringify({'website_status': '1'}));
};
ws.onmessage = function(msg) {
var response = JSON.parse(msg.data);
if(response.msg_type === 'website_status') {
if(!response.error && response.hasOwnProperty('website_status')) {
lang = getLanguage(response.website_status.clients_country);
}
ws.close();
redirect();
}
};
}
</script>
</head>
<body>
<h1>404</h1>
<p style='font-size: 1.5em;'><a href='https://binary.com'>https://binary.com</a></p>
</body>
</html>