   shipgraph[ship.api_filename] = ship.api_id for ship in body.api_mst_shipgraph
   getSubtitles()
 
-show = (text, prior, stickyFor) ->
+alert = (text, prior, stickyFor) ->
   window.log "#{text}",
     priority : prior,
     stickyFor: stickyFor

  voiceId = voiceMap[apiId][fileName]
  return if not voiceId
  console.log "#{apiId} #{voiceId}" if dbg.extra('subtitlesAudioResponse').isEnabled()
  subtitle = subtitles[apiId]?[voiceId]
  console.log "i18n: #{__(apiId+'.'+voiceId)}" if dbg.extra('subtitlesAudioResponse').isEnabled()
  prior = 0 if 8 < voiceId < 11

  # Current not supprot for en-US and ja-JP, set default to zh-TW
  if i18n["poi-plugin-subtitle"].locale == 'en-US' or i18n["poi-plugin-subtitle"].locale == 'ja-JP'
    i18n["poi-plugin-subtitle"].locale = 'zh-TW'

  if voiceId < 30
    if subtitle
      show "#{$ships[apiId].api_name}：#{__(apiId+'.'+voiceId)}", prior, 5000
    else
      show "本【#{$ships[apiId].api_name}】的台词字幕缺失的说，来舰娘百科（http://zh.kcwiki.moe/）帮助我们补全台词吧！", prior, 5000
  else
    now = new Date()
    sharpTime = new Date()


__ = i18n["poi-plugin-subtitle"].__.bind(i18n["poi-plugin-subtitle"])

loadSubtitles = async (_path) ->
  err = yield fs.ensureFileAsync _path
  data = yield fs.readFileAsync _path
  data = "{}" if not data or data.length is 0
  JSON.parse data

loadBackupSubtitles = async () ->
  dataBackup = yield fs.readFileAsync subtitlesBackupPath
  subtitlesBackup = JSON.parse dataBackup
  if not subtitles['zh-CN']?.version or +subtitles['zh-CN']?.version < +subtitlesBackup?.version
    data = dataBackup
    subtitles['zh-CN'] = subtitlesBackup
    err = yield fs.writeFileAsync subtitlesI18nPath['zh-CN'], data
    # Convert backup subtitle to zh-TW and save
    for shipIdOrSth, value of subtitlesBackup
      if typeof value isnt 'object'
        subtitles['zh-TW'][shipIdOrSth] = value
      else
        subtitles['zh-TW'][shipIdOrSth] = {} unless subtitles['zh-TW'][shipIdOrSth]
        subtitles['zh-TW'][shipIdOrSth][voiceId] = Traditionalized(text) for voiceId, text of value
    err = yield fs.writeFileAsync subtitlesI18nPath['zh-TW'], JSON.stringify(subtitles['zh-TW'], null, '\t')
    console.error err if err
  dataBackup

getSubtitles = async () ->
  # Load I18n Data
  subtitles[lang] = loadSubtitles(subtitlesI18nPath[lang]) for lang in langs
  # Load backup subtitle
  data = loadBackupSubtitles()
  # Update subtitle data from remote server
  try
    [response, repData] = yield request.getAsync "#{REMOTE_HOST}/#{subtitles['zh-CN'].version}"
    throw "获取字幕数据失败" unless repData
    rep = JSON.parse repData
    throw "字幕数据异常：#{rep.error}" if rep.error
    return unless rep.version
    for shipIdOrSth,value of rep
      if typeof value isnt "object"
        subtitles[lang][shipIdOrSth] = value for lang in langs
      else
        for lang in langs
          subtitles[lang][shipIdOrSth] = {} unless subtitles[lang][shipIdOrSth]
        for voiceId, text of value
          subtitles['zh-CN'][shipIdOrSth][voiceId] = text 
          subtitles['zh-TW'][shipIdOrSth][voiceId] = Traditionalized(text)
    for lang in langs
      err = yield fs.writeFileAsync subtitlesI18nPath[lang], JSON.stringify(subtitles[lang], null, '\t')
      throw err if err
  catch e
    if e instanceof Error
      console.error "#{e.name}: #{e.message}"
    else
      console.error e
    err = yield fs.writeFileAsync subtitlesI18nPath['zh-CN'], data
    console.error err if err
    subtitles['zh-CN'] = JSON.parse data
    # window.warn "语音字幕自动更新失败，请联系有关开发人员，并手动更新插件以更新字幕数据",
    #   stickyFor: 5000
    return
  window.success "语音字幕数据更新成功(#{subtitles['zh-CN'].version})",
    stickyFor: 3000

initialize = (e) ->
