function GCB_main() {
    console.log('%c------ Blocky: Fraud Country Blocker by Effective Apps is Initializing ------', 'color: cyan');
    console.log('%c------ Contact us at support@effectify.co for help and questions about the app ------', 'color: cyan');
    if (window.GCB_SCRIPT_INJECTED === undefined) {
        window.isLs = GCB_isLSAvailable();
        window.GCB_SCRIPT_INJECTED = true;
        window.EFFECTIVE_APPS_GCB_BLOCKED_MESSAGE = `<head></head><body style="background-color: #FFFFFF;"><p style="text-align:center;"><span style="font-size: 18px;">Sorry, you cannot visit our store from your current location, if you believe you have reached this message in error please try turning off your VPN and trying again</span></p>
</body>`;
        if ('5' === '7' && null === GCB_getLsWithExpiry('gcb_payg_i')) {
            jQuery.get('https://app.blocky-app.com/ri/ecac316ce6a311ec9a56e2f98a6f9353.js');
            GCB_setLsWithExpiry('gcb_payg_i', 'true', 604800000);
        }

        if (location.href.indexOf('gcb_preview=true') > -1) {
            GCB_blockPage();
            return;
        }

        if (location.href.indexOf('gcb_override=true') > -1 && 'True' === 'True') {
            GCB_setLsWithExpiry('gcb_override', 'true', 300000);
        }

        if ('True' === 'True' && (GCB_getLsWithExpiry('gcb_override') === 'true' || (typeof Shopify !== 'undefined' && Shopify.designMode === true) || document.getElementById('admin-bar-iframe') !== null)) {
            return;
        }

        GCB_getIPAddress(function(ipAddress, geolocationCountry) { GCB_lIp(ipAddress, geolocationCountry, true); })
        GCB_blockPage();
    }
}

function GCB_getIPAddress(callback) {
    jQuery.getJSON('https://ipv4.json.wtfismyip.com', function(result) {
        callback(result.YourFuckingIPAddress, result.YourFuckingCountryCode);
    });
}

function GCB_getBrowserType() {
    try {
        const userAgent = navigator.userAgent.toLowerCase();
        if (userAgent.includes("chrome") && !userAgent.includes("edg") && !userAgent.includes("opr") && !userAgent.includes("brave")) {
            if (navigator.brave) {
                return "b";
            }

            return "c";
        } else if (userAgent.includes("brave")) {
            return "b";
        } else if (userAgent.includes("firefox")) {
            return "ff";
        } else if (userAgent.includes("safari") && !userAgent.includes("chrome") && !userAgent.includes("chromium")) {
            return "s";
        } else if (userAgent.includes("edg")) {
            return "e";
        } else if (userAgent.includes("opr") || userAgent.includes("opera")) {
            return "o";
        } else if (userAgent.includes("trident") || userAgent.includes("msie")) {
            return "ie";
        }

        return "ot";
    }
    catch(err) {
        return "ot";
    }
}

function GCB_setLsWithExpiry(key, value, ttl) {
    if (window.isLs === false) {
        return false;
    }

	const now = new Date()
	const item = {
		value: value,
		expiry: now.getTime() + ttl,
	}
	localStorage.setItem(key, JSON.stringify(item))
}

function GCB_getLsWithExpiry(key) {
    if (window.isLs === false) {
        return null;
    }

	const itemStr = localStorage.getItem(key)
	if (!itemStr) {
		return null
	}

	const item = JSON.parse(itemStr)
	const now = new Date()
	if (now.getTime() > item.expiry) {
		localStorage.removeItem(key)
		return null
	}

	return item.value
}

function GCB_blockPage() {
    window.GCB_BLOCKED_PAGE_INTERVAL = setInterval(function() {
        document.querySelector("html").innerHTML = window.EFFECTIVE_APPS_GCB_BLOCKED_MESSAGE;
    }, 1000);
}

function GCB_lIp(ip_address, country_code, was_blocked) {
    if ('False' === 'True' && GCB_getLsWithExpiry('already_reported') === null) {
        browser = GCB_getBrowserType();
        jQuery.post('https://app.blocky-app.com/li/ecac316ce6a311ec9a56e2f98a6f9353', {"browser": browser, "ip_address": ip_address, "country_code": country_code, "was_blocked": was_blocked });
        GCB_setLsWithExpiry('already_reported', 'true', 3600000);
    }
}

function GCB_isLSAvailable() {
    var test = 'test';
    try {
        localStorage.setItem(test, test);
        localStorage.removeItem(test);
        return true;
    } catch(e) {
        return false;
    }
}

function GCB_loadScript(url, success) {
     var script = document.createElement('script');
     script.src = url;
     var head = document.getElementsByTagName('head')[0],
     done = false;
     head.appendChild(script);
     script.onload = script.onreadystatechange = function() {
        if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
             done = true;
             success();
             script.onload = script.onreadystatechange = null;
             head.removeChild(script);
        }
    };
}

if (typeof jQuery === 'undefined') {
    GCB_loadScript('https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js', GCB_main);
}
else {
    GCB_main();
}