<commit_before>class JThreePreviewController
  @loadedScriptCount = 0;

  @initJThree:(config,codeKey)->
   JThreePreviewController.loadj3Script config,codeKey
    .then ()=>
     JThreePreviewController.checkFinalize config,codeKey
     promise = Promise.resolve()
     config.codes[codeKey].js.forEach (v,i)=>
       url = v
       if !/https?\:\/\//.exec(v)
         url = config.codes[codeKey].root + v
       promise = promise
        .then ()=>
          JThreePreviewController.loadjsScript url
        .then ()=>
          JThreePreviewController.checkFinalize config,codeKey
      promise

  @loadj3Script:(config,codeKey)->
    new Promise (resolve,reject)=>
      j3Tag = document.createElement('script');
      code = config.codes[codeKey]
      if codeKey? && code # Cookieに選択対象が残っていた場合
          j3Tag.setAttribute('x-goml',code.root+code.goml);
      else # Cookieに選択対象が残っていなかった場合、最初を選択とする
        for k,v of config.codes
          codeKey = k
          j3Tag.setAttribute('x-goml',v.root+v.goml)
          break
      j3Tag.setAttribute('type','text/javascript');
      j3Tag.setAttribute 'src',"/j3.js"
      j3Tag.setAttribute 'x-lateLoad','true'
      j3Tag.onload = ()->
        resolve()
      document.body.appendChild j3Tag

  @loadjsScript:(url)->
    new Promise (resolve,reject)=>
      jsTag = document.createElement 'script'
      jsTag.setAttribute 'type','text/javascript'
      jsTag.setAttribute 'src',url
      jsTag.onload = ()->
        resolve()
      document.body.appendChild jsTag

  @checkFinalize:(config,codeKey)->
    JThreePreviewController.loadedScriptCount++
    if !config.codes[codeKey].js || JThreePreviewController.loadedScriptCount == config.codes[codeKey].js.length+1
      window.j3.lateStart();

module.exports = JThreePreviewController;<commit_msg>add debug control support for debug.json<commit_after>class JThreePreviewController
  @initJThree:(config,codeKey)->
   JThreePreviewController.loadj3Script config,codeKey
    .then ()=>
     root = config.codes[codeKey].root
     promise = Promise.resolve()
     if config.codes[codeKey].html?
       promise = promise.then ()=>
         JThreePreviewController.loadDebuggerControl root + config.codes[codeKey].html
      if config.codes[codeKey].css?
        JThreePreviewController.loadStyle root + config.codes[codeKey].css
     config.codes[codeKey].js.forEach (v,i)=>
       url = v
       if !/https?\:\/\//.exec(v)
         url = root + v
       promise = promise
        .then ()=>
          JThreePreviewController.loadjsScript url
     promise = promise.then ()=>
       JThreePreviewController.loadCompleted config,codeKey
     promise

  @loadj3Script:(config,codeKey)->
    new Promise (resolve,reject)=>
      j3Tag = document.createElement('script');
      code = config.codes[codeKey]
      if codeKey? && code # Cookieに選択対象が残っていた場合
          j3Tag.setAttribute('x-goml',code.root+code.goml);
      else # Cookieに選択対象が残っていなかった場合、最初を選択とする
        for k,v of config.codes
          codeKey = k
          j3Tag.setAttribute('x-goml',v.root+v.goml)
          break
      j3Tag.setAttribute('type','text/javascript');
      j3Tag.setAttribute 'src',"/j3.js"
      j3Tag.setAttribute 'x-lateLoad','true'
      j3Tag.onload = ()->
        resolve()
      document.body.appendChild j3Tag

  @loadDebuggerControl:(url)->
    new Promise (resolve,reject)=>
      xhr = new XMLHttpRequest()
      xhr.open "GET",url,true
      xhr.responseType = "text"
      xhr.onload = () =>
        document.querySelector ".debugControl"
          .innerHTML = xhr.responseText
        resolve()
      xhr.onerror = (err) =>
        reject();
      xhr.send(null);

  @loadStyle:(url)->
    styleTag = document.createElement 'link'
    styleTag.setAttribute 'rel','stylesheet'
    styleTag.setAttribute 'type','text/css'
    styleTag.setAttribute 'href',url
    document.head.appendChild styleTag

  @loadjsScript:(url)->
    new Promise (resolve,reject)=>
      jsTag = document.createElement 'script'
      jsTag.setAttribute 'type','text/javascript'
      jsTag.setAttribute 'src',url
      jsTag.onload = ()->
        resolve()
      document.body.appendChild jsTag

  @loadCompleted:(config,codeKey)->
      window.j3.lateStart();

module.exports = JThreePreviewController;
{'fraction_non_alphanumeric': 0.12704726251754797, 'fraction_numerical': 0.006083294337856809, 'mean_word_length': 2.8863636363636362, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, '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': '5933045', 'n_tokens_mistral': 1338, 'n_tokens_neox': 1353, 'n_words': 215}