This repository has been archived by the owner on May 11, 2018. It is now read-only.
forked from kcwikizh/poi-plugin-subtitle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.cjsx
62 lines (60 loc) · 2.71 KB
/
index.cjsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
{_, SERVER_HOSTNAME} = window
Promise = require 'bluebird'
path = require 'path'
async = Promise.coroutine
fs = Promise.promisifyAll require 'fs-extra'
PLUGIN_VERSION = '0.1.7'
webview = $('kan-game webview')
shipgraph = {}
voiceMap = {}
voiceKey = [604825,607300,613847,615318,624009,631856,635451,637218,640529,643036,652687,658008,662481,669598,675545,685034,687703,696444,702593,703894,711191,714166,720579,728970,738675,740918,743009,747240,750347,759846,764051,770064,773457,779858,786843,790526,799973,803260,808441,816028,825381,827516,832463,837868,843091,852548,858315,867580,875771,879698,882759,885564,888837,896168]
convertFilename = (shipId, voiceId) ->
return (shipId + 7) * 17 * (voiceKey[voiceId] - voiceKey[voiceId - 1]) % 99173 + 100000
for shipNo in [1..500]
voiceMap[shipNo] = {}
voiceMap[shipNo][convertFilename(shipNo,i)] = i for i in [1..voiceKey.length]
subtitles = {}
subtitlesFile = path.join __dirname, 'subtitles.json'
fs.readFileAsync subtitlesFile, (err, data) ->
subtitles = JSON.parse data unless err?
console.log 'Subtitles.json is not exist' if err?.code is 'ENOENT'
console.error err.code if err?.code isnt 'ENOENT' and err?.code
if config.get('plugin.Subtitle.enable', true)
window.addEventListener 'game.response', (e) ->
{method, path, body, postBody} = e.detail
{_ships, _decks, _teitokuLv} = window
switch path
when '/kcsapi/api_start2'
shipgraph[ship.api_filename] = ship.api_id for ship in body.api_mst_shipgraph
# Adjust animation duation
$('poi-alert #alert-area')?.style?.animationDuration="20s"
return
webview.addEventListener 'did-get-response-details', (e) ->
prior = 5
match = /kcs\/sound\/kc(.*?)\/(.*?).mp3/.exec(e.newURL)
return if not match? or match.length < 3
console.log e.newURL if process.env.DEBUG
[..., shipCode, fileName] = match
apiId = shipgraph[shipCode]
return if not apiId
voiceId = voiceMap[apiId][fileName]
return if not voiceId
console.log "#{apiId} #{voiceId}" if process.env.DEBUG
subtitle = subtitles[apiId]?[voiceId]
prior = 0 if 8 < voiceId < 11
if subtitle
window.log "#{$ships[apiId].api_name}:#{subtitle}",
priority : prior,
stickyFor: 5000
else
window.log "本【#{$ships[apiId].api_name}】的台词字幕缺失的说,来舰娘百科(http://zh.kcwiki.moe/)帮助我们补全台词吧!",
priority : prior,
stickyFor: 5000
return
module.exports =
name: 'Subtitle'
author: [<a key={0} href="https://github.com/grzhan">grzhan</a>]
displayName: <span><FontAwesome key={0} name='microphone' /> kcwiki语音字幕</span>
description: '语音字幕插件(舰娘百科支持)'
show: false
version: PLUGIN_VERSION