tools/generateCssFile.js
function buildJsFileContent(lines) {
    var ls = lines
        .map(l => l
            // remove space at beginning of line
            .replace(/^\s*/g, "")
            // remove space at end of line
            .replace(/\s*$/g, "")
            // convert \ to \\
            .replace(/\\/g, "\\\\")
            // convert " to \"
            .replace(/"/g, "\\\"")
            // convert " { " to "{"
            .replace(/\s*\{\s*/g, "{")
            // convert " : " to ":"
            .replace(/\s*:\s*/g, ":"))
        .join("")
        // remove comments
        .replace(/\/\*.+?\*\//g, "");

    return [
        // add css string
        `var css = "${ls}";`,
        "var enabled = false;",
        "",
        // add function which injects css into page
        "function enable () {",
        "\tif (enabled) return;",
        "\tenabled = true;",
        "",
        "\tvar el = document.createElement('style');",
        "\tel.innerHTML = css;",
        "",
        "\tvar parent = document.head || document.body;",
        "\tparent.firstChild ?",
        "\t\tparent.insertBefore(el, parent.firstChild) :",
        "\t\tparent.appendChild(el);",
        "}",
        "",
        "export {",
        "\tenable",
        "}"
    ].join("\n");
}
function buildJsFileContent(lines) {
    var ls = lines
        .map(l => l
            // remove space at beginning of line
            .replace(/^\s*/g, "")
            // remove space at end of line
            .replace(/\s*$/g, "")
            // convert \ to \\
            .replace(/\\/g, "\\\\")
            // convert " to \"
            .replace(/"/g, "\\\"")
            // convert " { " to "{"
            .replace(/\s*\{\s*/g, "{")
            // convert " : " to ":"
            .replace(/\s*:\s*/g, ":"))
        .join("")
        // remove comments
        .replace(/\/\*.+?\*\//g, "");

    return [
        // add css string
        `var css = "${ls}";`,
        "var enabled = false;",
        "",
        // add function which injects css into page
        "function enable () {",
        "\tif (enabled) return;",
        "\tenabled = true;",
        "",
        "\tvar el = document.createElement('style');",
        "\tel.innerHTML = css;",
        "",
        "\tvar parent = document.head || document.body;",
        "\tparent.firstChild ?",
        "\t\tparent.insertBefore(el, parent.firstChild) :",
        "\t\tparent.appendChild(el);",
        "}",
        "",
        "export {",
        "\tenable",
        "}"
    ].join("\n");
}
function buildJsFileContent ( lines ) { var ls = lines . map ( l => l // remove space at beginning of line . replace ( / ^\s* / g , "" ) // remove space at end of line . replace ( / \s*$ / g , "" ) // convert \ to \\ . replace ( / \\ / g , "\\\\" ) // convert " to \" . replace ( / " / g , "\\\"" ) // convert " { " to "{" . replace ( / \s*\{\s* / g , "{" ) // convert " : " to ":" . replace ( / \s*:\s* / g , ":" ) ) . join ( "" ) // remove comments . replace ( / \/\*.+?\*\/ / g , "" ) ; return [ // add css string ` ${ ls } ` , "var enabled = false;" , "" , // add function which injects css into page "function enable () {" , "\tif (enabled) return;" , "\tenabled = true;" , "" , "\tvar el = document.createElement('style');" , "\tel.innerHTML = css;" , "" , "\tvar parent = document.head || document.body;" , "\tparent.firstChild ?" , "\t\tparent.insertBefore(el, parent.firstChild) :" , "\t\tparent.appendChild(el);" , "}" , "" , "export {" , "\tenable" , "}" ] . join ( "\n" ) ; }
Create the js content of the file to add css
Create the js content of the file to add css