-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcountry-restriction.js
96 lines (87 loc) · 2.9 KB
/
country-restriction.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
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
/* ------------------------------ */
/* FREE IP INFO API THIRD PARTIES */
/* ------------------------------ */
// -> https://ipapi.co/json
// -> https://ipinfo.io/json
// -> https://get.geojs.io/v1/ip/country.json
/* ------------------- */
/* ACCESS DENIED ERROR */
/* ------------------- */
function display_access_denied_error() {
document.body.innerHTML
= '<div id="access-denied-error">'
+ '<div class="middle-center">'
+ '<span class="pulsate-bck">'
+ '<i class="bi bi-exclamation-diamond-fill"></i>'
+ 'Access Denied'
+ '</span>'
+ '</div>'
+ '</div>'
}
/* ------------------------- */
/* BLOCK BLACKLIST COUNTRIES */
/* ------------------------- */
function block_blacklist_countries() {
// Blacklist countries
const blacklist_countries = [
"DE", // Germany
"US", // United States
"GB", // United Kingdom
"UA", // Ukraine
"AR", // Argentina
"FI", // Finland
"CA", // Canada
"JP", // Japan
"NO", // Norway
"RU" // Russia
]
// Detecting the users country
function get_country_code(api_url) {
fetch(api_url, { method: 'GET' })
.then(response => response.json()) // Getting ip info as json
.then(result => {
if (blacklist_countries.includes(result.country)) { // If my ip country code is in blacklist
display_access_denied_error() // Access denied error
}
})
.catch(error => console.log('error', error))
}
// Getting country code from third party api
get_country_code("https://get.geojs.io/v1/ip/country.json")
}
/* ------------------------- */
/* ALLOW WHITELIST COUNTRIES */
/* ------------------------- */
function allow_whitelist_countries() {
// Whitelist countries
const whitelist_countries = [
"DE", // Germany
"US", // United States
"GB", // United Kingdom
"UA", // Ukraine
"AR", // Argentina
"FI", // Finland
"CA", // Canada
"JP", // Japan
"NO", // Norway
"RU" // Russia
]
// Detecting the users country
function get_country_code(api_url) {
fetch(api_url, { method: 'GET' })
.then(response => response.json()) // Getting ip info as json
.then(result => {
if (!whitelist_countries.includes(result.country)) { // If my ip country code is not in whitelist
display_access_denied_error() // Access denied error
}
})
.catch(error => console.log('error', error))
}
// Getting country code from third party api
get_country_code("https://get.geojs.io/v1/ip/country.json")
}
/* -------------- */
/* CALL FUNCTIONS */
/* -------------- */
block_blacklist_countries() // Block blacklist countries
// allow_whitelist_countries() // Allow whitelist countries