Loot table generator (1.9 to 1.11)

Loot table generator compatible with minecraft version 1.9 to 1.11

by Mr Pingouin

HTML

<h3>Custom loot table generator (1.9 to 1.11)</h3>
    <div id="content" elem-type="obj" class="json-elem">
        <div key-name="pools" id="pools" elem-type="array" template="pool" class="pool json-elem">
        </div>
        <input type="button" id="addPool" value="Add pool" onclick="addTemplate(this.parentElement, 'pool');"> 
        <input type="text" id="table_input" value="Paste your loot table here" onFocus="this.value=''"> 
        <input type="button" id="import" value="Import" onclick="promptImport();"> 
    </div>
    
    <div>
        <label>Pretty print : <input id="prettyPrint" type="checkbox" checked onChange="rebuildOutput()"></label>
    </div>
    <div>
        <textarea id="output" rows="15" cols="80" readonly onClick="focusArea(this)"></textarea>
    </div>
    <div>
        <textarea id="error" rows="5" cols="80" class="hidden" readonly"></textarea>
    </div>

    <div id="templates">
        <div class="tpl-none">
        
        </div>
        
        <div class="tpl-pool-elem nest-obj h-space">
            <div elem-type="obj" class="json-elem">
                Pool : <input type="button" value="X" onClick="removeNode(this.parentElement)">
                <div key-name="rolls" elem-type="range" class="json-elem inline">
                    <label class="warp-skip">Min roll : <input type="text" key-name="min" elem-type="num" class="warp json-elem" value="1"></label>
                    <label class="warp-skip">Max roll : <input type="text" key-name="max" elem-type="num" class="warp json-elem" value="1"></label>
                </div>
                <div key-name="bonus_rolls" elem-type="range" data-default="0" class="json-elem inline">
                    <label class="warp-skip">Min bonus_roll : <input type="text" key-name="min" elem-type="float" class="warp json-elem" value="0"></label>
                    <label class="warp-skip">Max bonus_roll : <input type="text" key-name="max" elem-type="float" class="warp json-elem"...

CSS

#templates{
    display:none;
}

#error{
    color:red;
    resize: none;
}

.hidden{
    display:none;
}

.h-space{
    display:block;
    margin-left:50px;
}

.inline{
    display: inline;
}

.data-error{
    box-shadow: 0px 0px 10px red;
}

input[elem-type=num], input[elem-type=float]{
    width:50px;
}

.long-content{
    width:200px;
}

.short-content{
    width:50px;
}

div:first-child > .hideFirst{
    display:none;
}

JavaScript

var lootObj = {};
var hasError = false;
var importingProcess = false;
var importErrorList = [];

//Componenent
var templates = document.getElementById("templates");
var content = document.getElementById("content");
var pools = document.getElementById("pools");
var output = document.getElementById("output");
var importError = document.getElementById("error");

//Options
var prettyPrintChecbox = document.getElementById("prettyPrint");
var input = document.getElementById("table_input");

function addTemplate(node, clazz){
    var selectedNode = node.getElementsByClassName(clazz)[0];
    appendTemplate(selectedNode, clazz + "-elem");
    rebuildOutput();
}

function changeSelect(node){
    if(node.hasAttribute("update")){
        var clazz = node.getAttribute("update");
        var selectedNode = node.parentElement.getElementsByClassName(clazz)[0];
        emptyNode(selectedNode);
        appendTemplate(selectedNode, node.value);  
    }
    rebuildOutput(); 
}


function emptyNode(node){
    var lc;
    while(lc = node.lastChild){
        node.removeChild(lc);
    }
}


function rebuildOutput(){
    if(importingProcess){
        return;
    }
    hasError = false;
    lootObj = buildObject(content);
    
    if(hasError){
        setNodeError(output, "This table contains errors, fix them before copying this.");
    }else{
        clearNodeError(output);
    }
    
    if(prettyPrintChecbox.checked){
        output.value = JSON.stringify(lootObj, null, 4);
    }else{
        output.value = JSON.stringify(lootObj);
    }
}

function buildObject(mainNode){
    var obj = {}
    for(var i in mainNode.childNodes){
        var node = mainNode.childNodes[i];
        if(node.nodeType == 1){
            if(node.classList.contains("warp-skip")){
                node = node.getElementsByClassName("warp")[0];
                if(node == undefined){
                    continue;
                }
            }else if(node.classList.contains("nest-obj")){
                var ob =...