<commit_before>var _requestQueue = {};
var _coreFrameHost = 'core.base.network';
var _coreFrameURL = location.protocol + '//' + _coreFrameHost + '/';
var _cache = {};

base.site = {

    isCore: false, // is core frame

    fatal: function(err) {
        if(this.isCore && window.parent !== window) {
            window.parent.postMessage(JSON.stringify({
                command: 'fatal',
                data: err
            }), '*');
        } else {
            document.body.innerHTML = '<div class="alert alert-danger">' +
                '<h3>base.network FATAL:</h3>' +
                '<pre>' + err + '</pre>' +
                '<button class="btn btn-danger" onclick="location.reload()">RELOAD PAGE</button>' +
            '</div>';
            throw err;
        }
    },

    init: function() {
        if(document.readyState !== 'complete') {
            return setTimeout(arguments.callee.bind(this));
        }
        this.isCore = _coreFrameHost === location.host;// && parent && parent !== window;

        if(this.isCore) {
            window.base = base;
            base.core.init();

        } else {
            this.initSite();
        }
    },

    initSite: function() {
        // listen messages from base-core-frame
        window.addEventListener("message", this.onCoreResponse.bind(this));

        // append base-core-frame
        this.baseCoreFrame = _.element("IFRAME", document.body, {
            id: 'base-core-frame',
            name: 'base-core-frame',
            src: _coreFrameURL
        });
        this.ex_setStyle();
    },

    requestToCore: function(command, data, callback) {
        if(this.isCore) {
            base.core[command].call(base.core, data, callback);
        } else {
            var id = (Math.random()*0x7fffffff|0).toString(36);
            _requestQueue[id] = callback;
            window.frames["base-core-frame"].postMessage({
                id: id,
                command: command,
                data: data
            }, _coreFrameURL);
        }
    },

    onCoreResponse: function(event) {
        if(event.origin !== location.protocol+'//'+_coreFrameHost) return;

        var resp = event.data, fn;
        if(resp && resp.id && (fn = _requestQueue[resp.id])) {
            delete _requestQueue[resp.id];
            fn.apply(this, resp.args || []);
        }
        if(resp && (fn=this['ex_'+resp.command])) {
            fn.apply(this, resp.args || []);
        }
    },

    ex_reload: function() {
        window.location.reload();
    },

    ex_onNodesInfo: function(nodes) {
        base.site.nodes = nodes;
    },

    ex_onInitCore: function() {
        if(/[?&]_clearcache\b/.test(location.search)) {
            trace('Clear cache');
            delete localStorage.domainInfo;
            delete localStorage.siteInfo;
        }
        this.loadDomainInfo(function(domainInfo) {
            trace('Downloaded Domain info: ', domainInfo);
            base.domainInfo = domainInfo;
            base.domainInfo.cert = base.Certificate.parsePublicCertificate(domainInfo.owner);

            this.loadSiteInfo(function(siteInfo){
                trace('Downloaded Site info: ', siteInfo);
                base.siteInfo = siteInfo;

                if(localStorage.testJS) {
                    trace('!!! INCLUDE TEST JavaScript by URL: ', localStorage.testJS);
                    _.element('script', document.head, {
                        type: "text/javascript",
                        src: localStorage.testJS
                    });
                } else {
                    var jsLib = siteInfo.js; // || "D/...."  - todo: by default jsLib should be link on default js-file
                    // todo: if siteInfo.js is Array then download sequentially
                    trace('loading js-script... ', jsLib);
                    this.requestToCore('requestFile', jsLib, function(err, content, info) {
                        trace('include js-script.', 'err:',err, 'info:', info,'cont:', content);
                        content && _.element('script', document.head, {
                            type:"text/javascript",
                            innerHTML:content
                        });
                    });
                }
            }.bind(this));
        }.bind(this));
    },

    ex_fatal: function(err) {
        this.fatal(err);
    },
<commit_msg>improve css, html-templates<commit_after>var _requestQueue = {};
var _coreFrameHost = 'core.base.network';
var _coreFrameURL = location.protocol + '//' + _coreFrameHost + '/';
var _cache = {};

base.site = {

    isCore: false, // is core frame

    fatal: function(err) {
        if(this.isCore && window.parent !== window) {
            window.parent.postMessage(JSON.stringify({
                command: 'fatal',
                data: err
            }), '*');
        } else {
            document.body.innerHTML = '<div class="alert alert-danger">' +
                '<h3>base.network FATAL:</h3>' +
                '<pre>' + err + '</pre>' +
                '<button class="btn btn-danger" onclick="location.reload()">RELOAD PAGE</button>' +
            '</div>';
            throw err;
        }
    },

    init: function() {
        if(document.readyState !== 'complete') {
            return setTimeout(arguments.callee.bind(this));
        }
        this.isCore = _coreFrameHost === location.host;// && parent && parent !== window;

        if(this.isCore) {
            window.base = base;
            base.core.init();

        } else {
            this.initSite();
        }
    },

    initSite: function() {
        // listen messages from base-core-frame
        window.addEventListener("message", this.onCoreResponse.bind(this));

        // append base-core-frame
        this.baseCoreFrame = _.element("IFRAME", document.body, {
            id: 'base-core-frame',
            name: 'base-core-frame',
            src: _coreFrameURL
        });
        this.ex_setStyle();
    },

    requestToCore: function(command, data, callback) {
        if(this.isCore) {
            base.core[command].call(base.core, data, callback);
        } else {
            var id = (Math.random()*0x7fffffff|0).toString(36);
            _requestQueue[id] = callback;
            window.frames["base-core-frame"].postMessage({
                id: id,
                command: command,
                data: data
            }, _coreFrameURL);
        }
    },

    onCoreResponse: function(event) {
        if(event.origin !== location.protocol+'//'+_coreFrameHost) return;

        var resp = event.data, fn;
        if(resp && resp.id && (fn = _requestQueue[resp.id])) {
            delete _requestQueue[resp.id];
            fn.apply(this, resp.args || []);
        }
        if(resp && (fn=this['ex_'+resp.command])) {
            fn.apply(this, resp.args || []);
        }
    },

    ex_reload: function() {
        window.location.reload();
    },

    ex_onNodesInfo: function(nodes) {
        base.site.nodes = nodes;
    },

    ex_onInitCore: function() {
        if(/[?&]_clearcache\b/.test(location.search)) {
            trace('Clear cache');
            delete localStorage.domainInfo;
            delete localStorage.siteInfo;
        }
        this.loadDomainInfo(function(domainInfo) {
            trace('Downloaded Domain info: ', domainInfo);
            base.domainInfo = domainInfo;
            base.domainInfo.cert = base.Certificate.parsePublicCertificate(domainInfo.owner);

            this.loadSiteInfo(function(siteInfo){
                trace('Downloaded Site info: ', siteInfo);
                base.siteInfo = siteInfo;

                if(localStorage.testJS) {
                    trace('!!! INCLUDE TEST JavaScript by URL: ', localStorage.testJS);
                    _.element('script', document.head, {
                        type: "text/javascript",
                        src: localStorage.testJS
                    });
                } else {
                    var jsLib = siteInfo.js; // || "D/...."  - todo: by default jsLib should be link on default js-file
                    jsLib = jsLib || "F/9eef42c1f935a27533d676b0983ecc19b24ccaec18967b308227dcd799c4dc5b.js";
                    // todo: if siteInfo.js is Array then download sequentially
                    trace('loading js-script... ', jsLib);
                    this.requestToCore('requestFile', jsLib, function(err, content, info) {
                        trace('include js-script.', 'err:',err, 'info:', info,'cont:', content);
                        content && _.element('script', document.head, {
                            type:"text/javascript",
                            innerHTML:content
                        });
                    });
                }
            }.bind(this));
        }.bind(this));
    },

    ex_fatal: function(err) {
        this.fatal(err);
    },

{'fraction_non_alphanumeric': 0.14070238631247187, 'fraction_numerical': 0.005965781179648807, 'mean_word_length': 1.6140041188584877, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2307747', 'n_tokens_mistral': 2504, 'n_tokens_neox': 2377, 'n_words': 443}