'use strict';
/** Utility function for determining brand from the URL
* @param {string} location - the domain
* @return {boolean}
*/
function _isGfDomain(location) {
let isGf = false;
// An array containing all GF domains
const gfDomainList = [
'goldenfrog.com',
'linkgf.com',
'goldenfrog.online',
'goldenfrog.biz',
'goldenfrog.company',
'goldenfrog.website',
'gf-official.com',
'jinwa-official.com'
];
gfDomainList.forEach((domain) => {
if (location === domain) {
isGf = true;
}
});
return isGf;
}
/** Utility function for determining brand from the URL
* @param {string} location - the domain
* @return {boolean}
*/
function _isUnbounceDomain(location) {
// An array containing all GF domains
const unbounceDomainList = [
'get.vyprvpn.com',
];
return unbounceDomainList.some(domain => location === domain);
}
/** An object that knows how to interpret the hostname of the current site.
*
* We serve our website on multiple domains, and we need to know information
* about our current host in order to enable/disable certain functionality.
*
* @todo Determine whether all properties must have `@type` set
*/
export class Host {
/** The domain portion of the current location
* @type {string}
*/
locationDomain = window.location.hostname.split('.').splice(-2, 2).join('.').toLowerCase();
/** A boolean indicating if we are on a goldenfrog domain
*/
isGfDomain = false;
/** A boolean indicating if we are on a unbounce domain
*/
isUnbounceDomain = false;
/** A boolean value indicating we are on a primary domain */
isPrimaryDomain = false;
/** A boolean indicating if this is the testing website
*/
environment = '';
/** A boolean indicating if this is a development VM
*/
isDevelopment = false;
/** A boolean indicating if this is the testing website
*/
isTesting = false;
/** A boolean indicating if this is the staging website
*/
isStaging = false;
/** A boolean indicating if this is the production website
*/
isProduction = false;
/** Site JS element
* @type {HTMLElement}
*/
siteJSLoadingElement = null;
/** Site JS location
* @type {string}
*/
siteJSLocation = null;
/** Set dynamic values for properties */
constructor() {
this.isDevelopment = /[0-2]?\d{1,2}\.[0-2]?\d{1,2}\.[0-2]?\d{1,2}\.[0-2]?\d{1,2}/.test(window.location.hostname);
// Whether `dev#` or `test#` is in the hostname
this.isTesting = window.location.hostname.includes('test');
// Whether `staging` is in the hostname
this.isStaging = window.location.hostname.includes('staging');
// Whether the hostname is `localhost`; some testing is done in this manner
this.isLocalhost = (window.location.hostname === 'localhost');
this.isProduction = !this.isDevelopment && !this.isTesting && !this.isStaging && !this.isLocalhost;
this.isGfDomain = _isGfDomain(this.locationDomain);
this.isUnbounceDomain = _isUnbounceDomain(this.locationDomain);
this.isPrimaryDomain = (this.locationDomain === 'goldenfrog.com')
|| (this.locationDomain === 'vyprvpn.com');
if (this.isDevelopment) {
this.environment = 'development';
} else if (this.isTesting) {
this.environment = 'testing';
} else if (this.isStaging) {
this.environment = 'staging';
} else {
this.environment = 'production';
}
this.siteJSLoadingElement = document.currentScript === undefined ?
document.querySelector('script[src*="gf-site-sync.js"]') : document.currentScript;
this.siteJSLocation = this.siteJSLoadingElement === null ? '' :
this.siteJSLoadingElement.getAttribute('src').replace(/gf-site-(sync|onload|legacy)\.js.*/, '');
}
}
/** Singleton instance */
export const host = new Host();