代码拉取完成,页面将自动刷新
var jstz = require('jstz')
/*
Loosely checks if someone's in Europe based on their timezone or locale.
This is not a perfect implementation, as it would potentially
catch folks that aren't necessarily in the EU, but checking
the timezone is still a lot cheaper and less invasive than
using people's IPs to determine their location.
*/
module.exports = function isInEU() {
return isInEUTimezone() || isEULocale()
}
module.exports.isInEUTimezone = isInEUTimezone
module.exports.isEULocale = isEULocale
/*
Loosely checks that a given locale partially matches an EU country code.
This won't work perfect for every language, but it should give us some
extra signal.
http://ec.europa.eu/eurostat/statistics-explained/index.php?title=Glossary:Country_codes
*/
function isEULocale() {
var locale = browserLocale()
var code = locale
if (locale.indexOf('-') >= 0) {
code = locale.split('-')[1]
}
return !!countryCodes[code.toUpperCase()]
}
function isInEUTimezone() {
var tz = browserTimezone()
return tz && tz.indexOf('Europe') >= 0
}
var countryCodes = {
BE: 'Belgium',
EL: 'Greece',
LT: 'Lithuania',
PT: 'Portugal',
BG: 'Bulgaria',
ES: 'Spain',
LU: 'Luxembourg',
RO: 'Romania',
CZ: 'Czech Republic',
FR: 'France',
RE: 'Reunion',
GP: 'Guadeloupe',
MQ: 'Martinique',
GF: 'French Guiana',
YT: 'Mayotte',
BL: 'Saint Barthelemy',
MF: 'Saint Martin',
PM: 'Saint Pierre and Miquelon',
WF: 'Wallis and Futuna',
PF: 'French Polynesia',
NC: 'New Caledonia',
HU: 'Hungary',
SI: 'Slovenia',
DK: 'Denmark',
FO: 'Faroe Islands',
GL: 'Greenland',
HR: 'Croatia',
MT: 'Malta',
SK: 'Slovakia',
DE: 'Germany',
IT: 'Italy',
NL: 'Netherlands',
AW: 'Aruba',
CW: 'Curacao',
SX: 'Sint Maarten',
FI: 'Finland',
AX: 'Aland Islands',
EE: 'Estonia',
CY: 'Cyprus',
AT: 'Austria',
SE: 'Sweden',
IE: 'Ireland',
LV: 'Latvia',
PL: 'Poland',
UK: 'United Kingdom',
GB: 'United Kingdom',
AI: 'Anguilla',
BM: 'Bermuda',
IO: 'British Indian Ocean Territory',
VG: 'British Virgin Islands',
KY: 'Cayman Islands',
FK: 'Falkland Islands',
GI: 'Gibraltar',
MS: 'Montserrat',
PN: 'Pitcairn, Henderson, Ducie and Oeno Islands',
SH: 'Saint Helena, Ascension and Tristan da Cunha',
TC: 'Turks and Caicos Islands',
GG: 'Guernsey',
JE: 'Jersey',
IM: 'Isle of Man'
}
function browserTimezone() {
var timezone = jstz.determine()
return timezone.name()
}
function browserLocale() {
if (window.navigator.languages && window.navigator.languages.length > 0) {
// Latest versions of Chrome and Firefox set this correctly
return navigator.languages[0]
}
if (navigator.userLanguage) {
// IE only
return navigator.userLanguage
}
return navigator.language
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。