3DS object explorer

by AndyE

CSS

body { height: 212px; white-space: pre-wrap; font-family: monospace; }
.value { color: maroon; }

JavaScript

/*personalbar.visible = 
    locationbar.visible = 
    menubar.visible = false;
*/
function dir (obj, el) {
    Object.keys(obj).sort(function (a,b) {
        return a.toLowerCase().localeCompare(b.toLowerCase());
    }).forEach(function (val, index) {
        var div = document.createElement("div");
        div.innerText = val;
        el.appendChild(div);
        div.style.marginLeft = "25px"
            
        if (typeof obj[val] == "object" || typeof obj[val] == "function") {
            div.onclick = function (evt) {
                if (evt.target != this)
                    return;
                if (this.className == "open") {
                    this.innerText = val;
                    this.className = "";
                } else {
                    this.className = "open";
                    dir(obj[val], div);
                }
            }
            if (typeof obj[val] == "function") 
                div.innerHTML += ":\t\t\t<span class='value'>" + String(obj[val]).replace(/\n[\s\S]+/g, "") + "}</span>"        }
        else 
            div.innerHTML += ":\t\t\t<span class='value'>" + JSON.stringify(obj[val]) + "</span>";
    });
}

dir (window, document.body);