-
Notifications
You must be signed in to change notification settings - Fork 12
/
helpers.ts
67 lines (60 loc) · 1.41 KB
/
helpers.ts
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
export function getUrl(base, page, calibre) {
let res = base
if (page >= 1) {
res += `?page=${page}`
}
if (calibre) {
if (page >= 1) {
res += '&'
} else {
res += '?'
}
res += `calibre=${calibre}`
}
return res
}
export function updateUrl(title, page, calibre) {
history.pushState({}, title, getUrl(window.location.pathname, page, calibre))
}
export function isCrawler(req) {
// let userAgent = 'No user agent (generated)'
// if (req && req.headers['user-agent']) {
// userAgent = req.headers['user-agent']
// } else if (typeof navigator !== 'undefined' && navigator.userAgent) {
// userAgent = navigator.userAgent
// }
// return [
// 'Googlebot',
// 'Bingbot',
// 'Slurp',
// 'DuckDuckBot',
// 'Yandex',
// 'w3m', // let elite haxors see all content b/c they are too cool for JS
// ].some(bot => userAgent.indexOf(bot) >= 0)
return false
}
export function provinceCodeToName(code) {
// todo implement
return code
}
declare const REGION: string
export function getCountry() {
switch (REGION) {
case 'CA':
return 'Canada'
case 'US':
return 'USA'
default:
throw new Error('unknown region: ' + REGION)
}
}
export function getNationality() {
switch (REGION) {
case 'CA':
return 'Canadian'
case 'US':
return 'American'
default:
throw new Error('unknown region: ' + REGION)
}
}