"use strict"; var FF; (function (FF) { var Geo = /** @class */ (function () { function Geo() { var _this = this; this.now = new Date(); if (navigator.userAgent.indexOf("Syncbot-") >= 0 || navigator.userAgent.indexOf("Googlebot") >= 0) return; var parameter = JSON.parse(document.querySelector("[data-js-parameter]").innerHTML); if (!parameter.country_code) return; this.currentCountryCord = parameter.country_code.toUpperCase(); this.getCountryCord(function (countryCode) { _this.userCountryCord = countryCode.toUpperCase(); _this.checkCountrySelector(); _this.checkFda(); }); } /** * */ Geo.prototype.checkCountrySelector = function () { var _this = this; try { if (document.head.querySelector("[name=\"x-page-country-selector-flag\"]").getAttribute("content").toLowerCase() != "true") return; } catch (e) { return; } var key = "country-selector-show"; var before = new Date(localStorage.getItem(key)); if (this.now.getTime() - before.getTime() > 1000 * 60 * 60 * 24) { //24h after user selection if (this.currentCountryCord != this.userCountryCord) { var currentCountry_1 = Geo.countryList[this.currentCountryCord]; var userCountry_1 = Geo.countryList[this.userCountryCord]; // init var req_1 = new XMLHttpRequest(); req_1.onreadystatechange = function () { if (req_1.readyState == 4 && req_1.status == 200) { var div = document.createElement("div"); div.innerHTML = req_1.responseText; var element_1 = div.firstElementChild; if (userCountry_1) { element_1.innerHTML = element_1.innerHTML .replace("{{ current-country-name }}", currentCountry_1.label) .replace("{{ user-country-name }}", userCountry_1.label); element_1.querySelector("[data-js-country-selector=\"visit\"]").addEventListener("click", function () { localStorage.setItem(key, _this.now.toUTCString()); location.href = userCountry_1.url; }); } else { //The user's IP does not exist in the list element_1.innerHTML = element_1.innerHTML .replace("{{ current-country-name }}", currentCountry_1.label); var btn = element_1.querySelector("[data-js-country-selector=\"all\"]"); btn.className = "btn btn-primary"; var visit = element_1.querySelector("[data-js-country-selector=\"visit\"]"); visit.setAttribute("style", "display:none"); //visit.parentNode!.removeChild(visit); } document.body.appendChild(element_1); // close element_1.querySelector("[data-js-country-selector=\"close\"]").addEventListener("click", function () { localStorage.setItem(key, _this.now.toUTCString()); element_1.addEventListener("transitionend", function () { return element_1.parentNode.removeChild(element_1); }); element_1.classList.add("m-country-selector--hide"); }); // sp action element_1.addEventListener("click", function () { element_1.setAttribute("data-js-country-selector", "opend"); }); // @ts-ignore FF.FontLoader.partsLoad([element_1]); } }; // @ts-ignore req_1.open("GET", "/" + FF.Common.parameter.site_code + "/themes/custom/fujifilm_com/common/template/country-selector/index.html", true); req_1.send(null); } } }; /** * */ Geo.prototype.checkFda = function () { try { if (document.head.querySelector("[name=\"x-page-fda-flag\"]").getAttribute("content").toLowerCase() != "true") return; } catch (e) { return; } if (this.userCountryCord == "US" && this.currentCountryCord != "US") { // if (this.userCountryCord == "JP" && this.currentCountryCord != "US") { var req_2 = new XMLHttpRequest(); req_2.onreadystatechange = function () { if (req_2.readyState == 4 && req_2.status == 200) { var div = document.createElement("div"); div.innerHTML = req_2.responseText; var element = div.firstElementChild; document.body.insertBefore(element, document.body.firstChild); // @ts-ignore FF.FontLoader.partsLoad([element]); // FF.Common.DispatchComponentInitialize(); } }; // @ts-ignore req_2.open("GET", "/" + FF.Common.parameter.site_code + "/themes/custom/fujifilm_com/common/template/fda/index.html", true); req_2.send(null); } }; /** * c&p > src/_theme/6100_global-site/molle/module/custom/AreaSelecter.vue * @param callBack * @private */ Geo.prototype.getCountryCord = function (callBack) { var _this = this; var key = "geo"; var val; try { val = JSON.parse(localStorage.getItem(key)); } catch (e) { } if (!val || !val.date) val = {}; var before = new Date(val.date); if (!val.code || (this.now.getTime() - before.getTime() > 1000 * 60 * 60 * 24 * 7)) { var el = document.createElement("script"); el.src = "//js.maxmind.com/js/apis/geoip2/v2.1/geoip2.js"; document.body.appendChild(el); var loop_1 = function () { try { // @ts-ignore geoip2.country(function (e) { // console.log(e.country.iso_code, e.country.names); val.code = e.country.iso_code; val.date = _this.now.toUTCString(); localStorage.setItem(key, JSON.stringify(val)); callBack(val.code); }, function (e) { console.log(e); }); } catch (e) { requestAnimationFrame(function () { return loop_1(); }); } }; loop_1(); } else { callBack(val.code); } }; Geo.countryList = { "JP": { "label": "Japan", "url": "https://www.fujifilm.com/jp/" }, "DE": { "label": "Germany", "url": "https://www.fujifilm.com/de/" }, "FR": { "label": "France", "url": "https://www.fujifilm.com/fr/" }, "GB": { "label": "United Kingdom", "url": "https://www.fujifilm.com/uk/" }, "IT": { "label": "Italy", "url": "https://www.fujifilm.com/it/" }, "NL": { "label": "Netherlands", "url": "https://www.fujifilm.com/nl/" }, "ES": { "label": "Spain", "url": "https://www.fujifilm.com/es/" }, "IE": { "label": "Ireland", "url": "https://www.fujifilm.com/ie/" }, "BE": { "label": "Belgium", "url": "https://www.fujifilm.com/be/" }, "RU": { "label": "Russia", "url": "https://www.fujifilm.com/ru/" }, "TR": { "label": "Turkey", "url": "https://www.fujifilm.com/tr/" }, "CH": { "label": "Switzerland", "url": "https://www.fujifilm.com/ch/" }, "AT": { "label": "Austria", "url": "https://www.fujifilm.com/at/" }, "PL": { "label": "Poland", "url": "https://www.fujifilm.com/pl/" }, "SE": { "label": "Sweden", "url": "https://www.fujifilm.com/se/" }, "PT": { "label": "Portugal", "url": "https://www.fujifilm.com/pt/" }, "HU": { "label": "Hungary", "url": "https://www.fujifilm.com/hu/" }, "DK": { "label": "Denmark", "url": "https://www.fujifilm.com/dk/" }, "FI": { "label": "Finland", "url": "https://www.fujifilm.com/fi/" }, "RO": { "label": "Romania", "url": "https://www.fujifilm.com/ro/" }, "GR": { "label": "Greece", "url": "https://www.fujifilm.com/gr/" }, "SK": { "label": "Slovakia", "url": "https://www.fujifilm.com/sk/" }, "ZA": { "label": "South Africa", "url": "https://www.fujifilm.com/za/" }, "LT": { "label": "Lithuania", "url": "https://www.fujifilm.com/lt/" }, "HR": { "label": "Croatia", "url": "https://www.fujifilm.com/hr/" }, "NO": { "label": "Norway", "url": "https://www.fujifilm.com/no/" }, "UA": { "label": "Ukraine", "url": "https://www.fujifilm.com/ua/" }, "KZ": { "label": "Kazakhstan", "url": "https://www.fujifilm.com/kz/" }, "BY": { "label": "Belarus", "url": "https://www.fujifilm.com/by/" }, "AL": { "label": "Albania", "url": "https://www.fujifilm.com/al/" }, "EE": { "label": "Estonia", "url": "https://www.fujifilm.com/ee/" }, "MT": { "label": "Malta", "url": "https://www.fujifilm.com/mt/" }, "LV": { "label": "Latvia", "url": "https://www.fujifilm.com/lv/" }, "CZ": { "label": "Czech Republic", "url": "https://www.fujifilm.com/cz/" }, "AM": { "label": "Armenia", "url": "https://www.fujifilm.com/am/" }, "US": { "label": "United States", "url": "https://www.fujifilm.com/us/" }, "CA": { "label": "Canada", "url": "https://www.fujifilm.com/ca/" }, "BR": { "label": "Brazil", "url": "https://www.fujifilm.com/br/" }, "CO": { "label": "Colombia", "url": "https://www.fujifilm.com/co/" }, "CL": { "label": "Chile", "url": "https://www.fujifilm.com/cl/" }, "AR": { "label": "Argentina", "url": "https://www.fujifilm.com/ar/" }, "PE": { "label": "Peru", "url": "https://www.fujifilm.com/pe/" }, "EC": { "label": "Ecuador", "url": "https://www.fujifilm.com/ec/" }, "BO": { "label": "Bolivia", "url": "https://www.fujifilm.com/bo/" }, "UY": { "label": "Uruguay", "url": "https://www.fujifilm.com/uy/" }, "PY": { "label": "Paraguay", "url": "https://www.fujifilm.com/py/" }, "VE": { "label": "Venezuela", "url": "https://www.fujifilm.com/ve/" }, "MX": { "label": "Mexico", "url": "https://www.fujifilm.com/mx/" }, "KR": { "label": "South Korea", "url": "https://www.fujifilm.com/kr/" }, "SG": { "label": "Singapore", "url": "https://www.fujifilm.com/sg/" }, "IN": { "label": "India", "url": "https://www.fujifilm.com/in/" }, "AU": { "label": "Australia", "url": "https://www.fujifilm.com/au/" }, "TH": { "label": "Thailand", "url": "https://www.fujifilm.com/th/" }, "MY": { "label": "Malaysia", "url": "https://www.fujifilm.com/my/" }, "ID": { "label": "Indonesia", "url": "https://www.fujifilm.com/id/" }, "PH": { "label": "Philippines", "url": "https://www.fujifilm.com/ph/" }, "VN": { "label": "Vietnam", "url": "https://www.fujifilm.com/vn/" }, "NZ": { "label": "New Zealand", "url": "https://www.fujifilm.com/nz/" }, "MM": { "label": "Myanmar", "url": "https://www.fujifilm.com/mm/" }, "CN": { "label": "China", "url": "https://www.fujifilm.com.cn/cn" }, "AE": { "label": "United Arab Emirates", "url": "https://www.fujifilm.eu/mea" }, }; return Geo; }()); FF.Geo = Geo; })(FF || (FF = {})); new FF.Geo();