Skip to content

Instantly share code, notes, and snippets.

@SergProduction
Last active July 28, 2016 17:12

Revisions

  1. SergProduction renamed this gist Jul 28, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. SergProduction created this gist Jul 28, 2016.
    40 changes: 40 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    let id = 0;
    let init = [];

    socket.ws.send('{"cmd":"GetScript"}');

    socket.onMessage( data => {
    if (data.cmd == 'SetScript') {
    Parse(data.script);
    }
    })


    function Parse(mod, parent = 0 ){
    let my = {};

    mod.forEach((el, i, arr) => {

    id+=1;

    my = {
    id: id,
    parent: parent,
    key: el.keyname,
    question: el.qwest,
    answer: el.ans,
    file: null,
    url: null
    };

    init.push(my);

    if (el.node.length) {
    Parse(el.node, id)
    }

    })
    return init
    }

    export default init