<commit_before>/**
 * Shopify BoxIt frontend app
 * @author goshi
 * @version 0.1
 */
(function(){

    // define base ows app
    var OwsApp = function(){

        var box_cookie = 'boxitsess';
        var box_cookie_tout = 100*24*60*60*1000;

        /**
         * cookielibrary
         * @type {{setCookie: setCookie, getCookie: getCookie, deleteCookie: deleteCookie}}
         */
        var c = {

            setCookie : function (name, value, expires, path, domain, secure) {
                document.cookie = name + "=" + escape(value) +
                    ((expires) ? "; expires=" + expires : "") +
                    ((path) ? "; path=" + path : "") +
                    ((domain) ? "; domain=" + domain : "") +
                    ((secure) ? "; secure" : "");
            },

            getCookie : function (name) {
                var cookie = " " + document.cookie;
                var search = " " + name + "=";
                var setStr = null;
                var offset = 0;
                var end = 0;
                if (cookie.length > 0) {
                    offset = cookie.indexOf(search);
                    if (offset != -1) {
                        offset += search.length;
                        end = cookie.indexOf(";", offset);
                        if (end == -1) {
                            end = cookie.length;
                        }
                        setStr = unescape(cookie.substring(offset, end));
                    }
                }
                return(setStr);
            },

            deleteCookie : function(name) {
                var d = new Date();
                d = d.setTime(d.getTime() + -1*1000);
                if (d && d.toUTCString) {
                    d = d.toUTCString();
                }

                this.setCookie(name, "", d, '/')
            }

        };

        var getScriptURL = (function() {
            var scripts = document.getElementsByTagName('script');
            var myScript = null;
            if (scripts && scripts.length){
                for (var i= 0,l=scripts.length; i<l; i++){
                    if (/shopify_frontend/.test(scripts[i].src)){
                        myScript = scripts[i];
                        break;
                    }
                }
            }

            return function() { return myScript ? myScript.src : myScript; };
        })();

        // method extract base path for app
        var getBasePath = function(){

            var p = getScriptURL().split('/shopify_frontend/');
            console.log(p);
            return p[0];

        };

        // check if we have session
        // if not - get current shop session cookie
        if (/*!c.getCookie(box_cookie) && */c.getCookie('_shopify_s')){
            var d = new Date();
            d = d.setTime(d.getTime() + box_cookie_tout);
            if (d && d.toUTCString) {
                d = d.toUTCString();
            }

            c.setCookie(box_cookie, c.getCookie('_shopify_s'), d, '/');
        }

        return {

            /**
             * function set app session value
             * @param session
             */
            setSessionValue : function(session){
                var d = new Date();
                d = d.setTime(d.getTime() + box_cookie_tout);
                if (d && d.toUTCString) {
                    d = d.toUTCString();
                }

                c.setCookie(box_cookie, session, d, '/');

            },

            /**
             * function get app session value
             */
            getSessionValue : function(){

                return c.getCookie(box_cookie);

            },

            syncEvent : function (k, condition){

                (function(){
                    try{
                        if (eval(condition) == true) {
                            k();
                        } else {
                            setTimeout(arguments.callee,10);
                        }
                    } catch(e) {
                        setTimeout(arguments.callee,10);
                    }}
                )();
            },

            getExternalAppDomain: function(){

                var src = getScriptURL();
                var domain = null;

                if (src){
                    src = src.replace('https://', '').split('/');
                    domain = src[0];
                }
                return domain;

            },

            getExternalAppPath : function(){

                return getBasePath();
<commit_msg>fix bug with get external app path<commit_after>/**
 * Shopify BoxIt frontend app
 * @author goshi
 * @version 0.1
 */
(function(){

    // define base ows app
    var OwsApp = function(){

        var box_cookie = 'boxitsess';
        var box_cookie_tout = 100*24*60*60*1000;

        /**
         * cookielibrary
         * @type {{setCookie: setCookie, getCookie: getCookie, deleteCookie: deleteCookie}}
         */
        var c = {

            setCookie : function (name, value, expires, path, domain, secure) {
                document.cookie = name + "=" + escape(value) +
                    ((expires) ? "; expires=" + expires : "") +
                    ((path) ? "; path=" + path : "") +
                    ((domain) ? "; domain=" + domain : "") +
                    ((secure) ? "; secure" : "");
            },

            getCookie : function (name) {
                var cookie = " " + document.cookie;
                var search = " " + name + "=";
                var setStr = null;
                var offset = 0;
                var end = 0;
                if (cookie.length > 0) {
                    offset = cookie.indexOf(search);
                    if (offset != -1) {
                        offset += search.length;
                        end = cookie.indexOf(";", offset);
                        if (end == -1) {
                            end = cookie.length;
                        }
                        setStr = unescape(cookie.substring(offset, end));
                    }
                }
                return(setStr);
            },

            deleteCookie : function(name) {
                var d = new Date();
                d = d.setTime(d.getTime() + -1*1000);
                if (d && d.toUTCString) {
                    d = d.toUTCString();
                }

                this.setCookie(name, "", d, '/')
            }

        };

        var getScriptURL = (function() {
            var scripts = document.getElementsByTagName('script');
            var myScript = null;
            if (scripts && scripts.length){
                for (var i= 0,l=scripts.length; i<l; i++){
                    if (/shopify_frontend/.test(scripts[i].src)){
                        myScript = scripts[i];
                        break;
                    }
                }
            }

            return function() { return myScript ? myScript.src : myScript; };
        })();

        // method extract base path for app
        var getBasePath = function(){

            var p = getScriptURL().split('/shopify_frontend/');
            console.log(p);
            return p[0];

        };

        // check if we have session
        // if not - get current shop session cookie
        if (/*!c.getCookie(box_cookie) && */c.getCookie('_shopify_s')){
            var d = new Date();
            d = d.setTime(d.getTime() + box_cookie_tout);
            if (d && d.toUTCString) {
                d = d.toUTCString();
            }

            c.setCookie(box_cookie, c.getCookie('_shopify_s'), d, '/');
        }

        return {

            /**
             * function set app session value
             * @param session
             */
            setSessionValue : function(session){
                var d = new Date();
                d = d.setTime(d.getTime() + box_cookie_tout);
                if (d && d.toUTCString) {
                    d = d.toUTCString();
                }

                c.setCookie(box_cookie, session, d, '/');

            },

            /**
             * function get app session value
             */
            getSessionValue : function(){

                return c.getCookie(box_cookie);

            },

            syncEvent : function (k, condition){

                (function(){
                    try{
                        if (eval(condition) == true) {
                            k();
                        } else {
                            setTimeout(arguments.callee,10);
                        }
                    } catch(e) {
                        setTimeout(arguments.callee,10);
                    }}
                )();
            },

            getExternalAppDomain: function(){

                var src = getScriptURL();
                var domain = null;

                if (src){
                    src = src.replace('https://', '').split('/');
                    domain = src[0];
                }
                return domain;

            },

            getExternalAppPath : function(){

                return getBasePath().replace('https://', '');

{'fraction_non_alphanumeric': 0.12479492507929564, 'fraction_numerical': 0.006999890626708958, 'mean_word_length': 1.0180975502096667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3818030', 'n_tokens_mistral': 2430, 'n_tokens_neox': 2213, 'n_words': 514}