new Promise(()=>{
 "use strict";

window.nl_watch.nl_itab = function(aThis, aClassName) {
  const
    itab = document.getElementById('nl_itab_Frame')
    ,elem = itab.getElementsByClassName('active');
  
  Array.from(elem).forEach(e => e.classList.remove('active'));
  itab.getElementsByClassName(`nl_itab_Bodies ${aClassName}`)[0].classList.add('active');
  aThis.classList.add('active');
};

window.nl_watch.create_nl_itab = function(){
  if (document.getElementsByClassName('VideoDescription-plain').item(0)) {
    const
      evt = document.createEvent("event")
      ,E = document.getElementsByClassName('VideoDescriptionExpander-switch')[0];
    evt.initEvent("click", true, false);
    E.dispatchEvent(evt);
    return requestAnimationFrame(F);
  } else if (!document.getElementsByClassName('VideoDescription-html').item(0)) {
    return requestAnimationFrame(F);
  }
  
  const elem = document.getElementsByClassName('VideoDescription-html')[0];
  var size = '';
  
  elem.classList.add('nl_itab_Bodies', 'active');
  
  const id = window.nl_watch.apiData.video.id;
  if (!id.indexOf('sm') && (id.slice(2) -0) >= 16371888) size = '.L';
  /* nl_itab生成 */
  elem.outerHTML = 
    '<div id="nl_itab_Container">'
      + `<div id="nl_itab_Thumb"><img id="nl_itab_Img" src="${window.nl_watch.apiData.video.thumbnailURL}${size}"></div>`
      + '<div id="nl_itab_Frame">'
        + '<div id="nl_itab_Header">'
          + `<a href="javascript:void(0)" id="nl_itab_description" onClick="nl_watch.nl_itab(this, 'VideoDescription-html')" class="active">動画説明</a>`
        +'</div>'
        + elem.outerHTML
      + '</div>'
    + '</div>';
  /**/
  
};

//window.WatchJsApi.video.onVideoChanged(new Promise(window.nl_watch.create_nl_itab));
window.nl_watch.eventListenerMap.add(window.nl_watch.create_nl_itab);

});