<commit_before>//--
// Copyright (c) 2008-2020, Net-ng.
// All rights reserved.
//
// This software is licensed under the BSD License, as described in
// the file LICENSE.txt, which you should have received as part of
// this distribution.
//--

"use strict";

class Nagare {
    constructor (error) {
        document.addEventListener('click', evt => this.processClick(evt), true);
        this.nagare_loaded_named_js = {};

        if(error) this.error = error;
    }

    evalCSS(name, css, attrs) {
        if(css.length) {
            var style = document.createElement("style");

            style.setAttribute("type", "text/css");
            style.setAttribute("data-nagare-css", name);
            for(var name in attrs) style.setAttribute(name, attrs[name]);

            if(style.styleSheet) style.styleSheet.cssText = css;
            else style.appendChild(document.createTextNode(css));

            document.head.appendChild(style);
        }
    }

    evalJS(name, js, attrs) {
        if(!this.nagare_loaded_named_js[name]) setTimeout(js, 0);
        this.nagare_loaded_named_js[name] = true;
    }

    fetchCSS(url, attrs) {
        var link = document.createElement("link");

        link.setAttribute("rel", "stylesheet");
        link.setAttribute("type", "text/css");
        link.setAttribute("href", url);
        for(var name in attrs) link.setAttribute(name, attrs[name]);

        document.head.appendChild(link);
    }

    fetchJS(url, attrs) {
        var script = document.createElement("script");

        script.setAttribute("type", "text/javascript");
        script.setAttribute("src", url);
        for(var name in attrs) script.setAttribute(name, attrs[name]);

        document.head.appendChild(script);
    }

    loadAll(named_css, css, named_js, js) {
        for(var i=0; i<named_css.length; i++) {
            var name = named_css[i][0];
            var selector = "[data-nagare-css='" + name + "']";
            if(!document.head.querySelector(selector)) this.evalCSS(name, named_css[i][1], named_css[i][2]);
        }

        for(var i=0; i<named_js.length; i++) {
            var name = named_js[i][0];
            var selector = "[data-nagare-js='" + name + "']";
            if(!document.head.querySelector(selector)) this.evalJS(name, named_js[i][1], named_js[i][2]);
        }

        for(var i=0; i<css.length; i++) {
            var url = css[i][0];
            var a = document.createElement('a');
            var links = document.head.querySelectorAll("link[rel=stylesheet]");
            for(var j=0, found=false; !found && j<links.length; j++) {
                a.href = links[j].href;
                found = (a.host == window.location.host) && (a.pathname == url);
            }
            if(!found) this.fetchCSS(url, css[i[1]]);
        }

        for(var i=0; i<js.length; i++) {
            var url = js[i][0];
            var selector = "script[src='" + url + "']";
            if(!document.head.querySelector(selector)) this.fetchJS(url, css[i[1]]);
        }
    }

    replaceNode(id, html) {
        var node = document.getElementById(id);

        if(node && html) {
            var e = document.createElement("div");
            e.innerHTML = html;
            var new_node = e.children[0];

            new_node.querySelectorAll("script").forEach(
                js => {
                    if(js.getAttribute("src")) {
                        var script = document.createElement("script");<commit_msg>Parse the received HTML with the same tag than the destination<commit_after>//--
// Copyright (c) 2008-2020, Net-ng.
// All rights reserved.
//
// This software is licensed under the BSD License, as described in
// the file LICENSE.txt, which you should have received as part of
// this distribution.
//--

"use strict";

class Nagare {
    constructor (error) {
        document.addEventListener('click', evt => this.processClick(evt), true);
        this.nagare_loaded_named_js = {};

        if(error) this.error = error;
    }

    evalCSS(name, css, attrs) {
        if(css.length) {
            var style = document.createElement("style");

            style.setAttribute("type", "text/css");
            style.setAttribute("data-nagare-css", name);
            for(var name in attrs) style.setAttribute(name, attrs[name]);

            if(style.styleSheet) style.styleSheet.cssText = css;
            else style.appendChild(document.createTextNode(css));

            document.head.appendChild(style);
        }
    }

    evalJS(name, js, attrs) {
        if(!this.nagare_loaded_named_js[name]) setTimeout(js, 0);
        this.nagare_loaded_named_js[name] = true;
    }

    fetchCSS(url, attrs) {
        var link = document.createElement("link");

        link.setAttribute("rel", "stylesheet");
        link.setAttribute("type", "text/css");
        link.setAttribute("href", url);
        for(var name in attrs) link.setAttribute(name, attrs[name]);

        document.head.appendChild(link);
    }

    fetchJS(url, attrs) {
        var script = document.createElement("script");

        script.setAttribute("type", "text/javascript");
        script.setAttribute("src", url);
        for(var name in attrs) script.setAttribute(name, attrs[name]);

        document.head.appendChild(script);
    }

    loadAll(named_css, css, named_js, js) {
        for(var i=0; i<named_css.length; i++) {
            var name = named_css[i][0];
            var selector = "[data-nagare-css='" + name + "']";
            if(!document.head.querySelector(selector)) this.evalCSS(name, named_css[i][1], named_css[i][2]);
        }

        for(var i=0; i<named_js.length; i++) {
            var name = named_js[i][0];
            var selector = "[data-nagare-js='" + name + "']";
            if(!document.head.querySelector(selector)) this.evalJS(name, named_js[i][1], named_js[i][2]);
        }

        for(var i=0; i<css.length; i++) {
            var url = css[i][0];
            var a = document.createElement('a');
            var links = document.head.querySelectorAll("link[rel=stylesheet]");
            for(var j=0, found=false; !found && j<links.length; j++) {
                a.href = links[j].href;
                found = (a.host == window.location.host) && (a.pathname == url);
            }
            if(!found) this.fetchCSS(url, css[i[1]]);
        }

        for(var i=0; i<js.length; i++) {
            var url = js[i][0];
            var selector = "script[src='" + url + "']";
            if(!document.head.querySelector(selector)) this.fetchJS(url, css[i[1]]);
        }
    }

    replaceNode(id, html) {
        var node = document.getElementById(id);

        if(node && html) {
            var e = document.createElement(node.parentNode.tagName);
            e.innerHTML = html;
            var new_node = e.children[0];

            new_node.querySelectorAll("script").forEach(
                js => {
                    if(js.getAttribute("src")) {
                        var script = document.createElement("script");
{'fraction_non_alphanumeric': 0.15487544483985766, 'fraction_numerical': 0.0071174377224199285, 'mean_word_length': 2.2244148692060577, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '4391873', 'n_tokens_mistral': 2114, 'n_tokens_neox': 2108, 'n_words': 427}