-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathlive2d.core.js
More file actions
4955 lines (4893 loc) · 253 KB
/
live2d.core.js
File metadata and controls
4955 lines (4893 loc) · 253 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const VERSION = GM_info.script.version
const modelList = JSON.parse(GM_getResourceText('modelList'))
const live2d_conf = {
modelAPI: 'default', // 可根据https://github.com/HCLonely/live2d_api自建api
staticAPI: '',
tipsMessage: 'waifu-tips.json',
hitokotoAPI: 'rand',
modelId: 2,
modelTexturesId: 28,
showToolMenu: true,
canCloseLive2d: true,
canSwitchModel: true,
canSwitchTextures: true,
canSwitchHitokoto: true,
canTakeScreenshot: true,
canTurnToHomePage: true,
canTurnToAboutPage: true,
modelStorage: true,
modelRandMode: 'switch',
modelTexturesRandMode: 'rand',
showHitokoto: true,
showF12Status: true,
showF12Message: false,
showF12OpenMsg: true,
showCopyMessage: true,
showWelcomeMessage: true,
waifuSize: '280x250',
waifuTipsSize: '250x70',
waifuFontSize: '12px',
waifuToolFont: '14px',
waifuToolLine: '20px',
waifuToolTop: '0px',
waifuMinWidth: '768px',
waifuEdgeSide: 'right:15',
waifuDraggable: 'disable',
waifuDraggableRevert: true,
waifuDraggableSave: false,
waifuDraggableClear: false,
homePageUrl: 'auto',
aboutPageUrl: 'https://blog.hclonely.com/posts/f09c9fef/',
screenshotCaptureName: 'live2d.png'
}
const live2d_settings = GM_getValue('live2d_settings') || { ...live2d_conf }
if (live2d_settings.staticAPI.includes('hclonely')) {
live2d_settings.staticAPI = ''
GM_setValue('live2d_settings', live2d_settings)
}
if (live2d_settings.modelAPI === 'http://49.234.125.110:2333/' || live2d_settings.modelAPI === 'http://39.96.35.158:2333/') {
live2d_settings.modelAPI = 'default'
GM_setValue('live2d_settings', live2d_settings)
}
const setting_des = {
modelAPI: '自建 API 修改这里,默认为 \'default\'',
staticAPI: '模型 API 修改这里(不要带最后的"/"),如果 modelAPI 为\'default\', 则此选项无效',
tipsMessage: '同目录下可省略路径',
hitokotoAPI: '一言 API,可选 \'lwl12.com\', \'hitokoto.cn\', \'fghrsh.net\', \'jinrishici.com\'(古诗词), \'rand\'(随机)',
modelId: '默认模型 ID,可在 F12 控制台找到',
modelTexturesId: '默认材质 ID,可在 F12 控制台找到',
showToolMenu: '显示 工具栏 ,可选 true(真), false(假)',
canCloseLive2d: '显示 关闭看板娘 按钮,可选 true(真), false(假)',
canSwitchModel: '显示 模型切换 按钮,可选 true(真), false(假)',
canSwitchTextures: '显示 材质切换 按钮,可选 true(真), false(假)',
canSwitchHitokoto: '显示 一言切换 按钮,可选 true(真), false(假)',
canTakeScreenshot: '显示 看板娘截图 按钮,可选 true(真), false(假)',
canTurnToHomePage: '显示 返回首页 按钮,可选 true(真), false(假)',
canTurnToAboutPage: '显示 跳转关于页 按钮,可选 true(真), false(假)',
modelStorage: '记录 ID (刷新后恢复),可选 true(真), false(假)',
modelRandMode: '模型切换,可选 \'rand\'(随机), \'switch\'(顺序)',
modelTexturesRandMode: '材质切换,可选 \'rand\'(随机), \'switch\'(顺序)',
showHitokoto: '显示一言',
showF12Status: '显示加载状态',
showF12Message: '显示看板娘消息',
showF12OpenMsg: '显示控制台打开提示',
showCopyMessage: '显示 复制内容 提示',
showWelcomeMessage: '显示进入面页欢迎词',
waifuSize: '看板娘大小,例如 \'280x250\', \'600x535\'',
waifuTipsSize: '提示框大小,例如 \'250x70\', \'570x150\'',
waifuFontSize: '提示框字体,例如 \'12px\', \'30px\'',
waifuToolFont: '工具栏字体,例如 \'14px\', \'36px\'',
waifuToolLine: '工具栏行高,例如 \'20px\', \'36px\'',
waifuToolTop: '工具栏顶部边距,例如 \'0px\', \'-60px\'',
waifuMinWidth: '面页小于 指定宽度 隐藏看板娘,例如 \'disable\'(禁用), \'768px\'',
waifuEdgeSide: '看板娘贴边方向,例如 \'left:0\'(靠左 0px), \'right:30\'(靠右 30px)',
waifuDraggable: '拖拽样式,例如 \'disable\'(禁用), \'axis-x\'(只能水平拖拽), \'unlimited\'(自由拖拽)',
waifuDraggableRevert: '松开鼠标还原拖拽位置,可选 true(真), false(假)',
waifuDraggableSave: '是否保存拖拽后的位置,刷新后依然生效,需要将上面的选项和下面的选项都设置为false,可选 true(真), false(假)',
waifuDraggableClear: '清空上次保存的位置,可选 true(真), false(假)',
homePageUrl: '主页地址,可选 \'auto\'(自动), \'{URL 网址}\'',
aboutPageUrl: '关于页地址, \'{URL 网址}\'',
screenshotCaptureName: '看板娘截图文件名,例如 \'live2d.png\''
}
/****************************************************************************************************/
String.prototype.render = function (context) { // eslint-disable-line no-extend-native
const tokenReg = /(\\)?\{([^{}\\]+)(\\)?\}/g
return this.replace(tokenReg, function (word, slash1, token, slash2) {
if (slash1 || slash2) { return word.replace('\\', '') }
const variables = token.replace(/\s/g, '').split('.')
let currentObject = context
let i, length, variable
for (i = 0, length = variables.length; i < length; ++i) {
variable = variables[i]
currentObject = currentObject[variable]
if (currentObject === undefined || currentObject === null) return ''
}
return currentObject
})
}
const re = /x/
console.log(re)
const x = document.createElement('div')
console.debug(x)
function empty(obj) { return !!(typeof obj === 'undefined' || obj == null || obj === '') }
function getRandText(text) { return Array.isArray(text) ? text[Math.floor(Math.random() * text.length + 1) - 1] : text }
function showMessage(text, timeout, flag) {
if (flag || GM_getValue('waifu-text') === '' || GM_getValue('waifu-text') === null) {
if (Array.isArray(text)) text = text[Math.floor(Math.random() * text.length + 1) - 1]
if (live2d_settings.showF12Message) console.log('[Message]', text.replace(/<[^<>]+>/g, ''))
if (flag) GM_setValue('waifu-text', text)
$('.waifu-tips').stop()
$('.waifu-tips').html(text).fadeTo(200, 1)
if (timeout === undefined) timeout = 5000
hideMessage(timeout)
}
}
function hideMessage(timeout) {
$('.waifu-tips').stop().css('opacity', 1)
if (timeout === undefined) timeout = 5000
window.setTimeout(function () { GM_setValue('waifu-text', '') }, timeout)
$('.waifu-tips').delay(timeout).fadeTo(200, 0)
}
function dateFormat(fmt, date) {
let ret
const opt = {
'Y+': date.getFullYear().toString(), // 年
'm+': (date.getMonth() + 1).toString(), // 月
'd+': date.getDate().toString(), // 日
'H+': date.getHours().toString(), // 时
'M+': date.getMinutes().toString(), // 分
'S+': date.getSeconds().toString() // 秒
// 有其他格式化字符需求可以继续添加,必须转化成字符串
}
for (const k in opt) {
ret = new RegExp('(' + k + ')').exec(fmt)
if (ret) {
fmt = fmt.replace(ret[1], (ret[1].length === 1) ? (opt[k]) : (opt[k].padStart(ret[1].length, '0')))
};
};
return fmt
}
window.initModel = function initModel(waifuPath, type) {
/* console welcome message */
console.log('%c ' + { msg: "\n\nく__,.ヘヽ. / ,ー、 〉\n \ ', !-─‐-i / /´\n /`ー' L//`ヽ、\n / /, /| , , ',\n イ / /-‐/ i L_ ハ ヽ! i\n レ ヘ 7イ`ト レ'ァ-ト、!ハ| |\n !,/7 '0' ´0iソ| |\n |.从\" _ ,,,, / |./ |\n レ'| i>.、,,__ _,.イ / .i |\n レ'| | / k_7_/レ'ヽ, ハ. |\n | |/i 〈|/ i,.ヘ | i|\n .|/ / i: ヘ! \|\n kヽ>、ハ _,.ヘ、 /、!\n !'〈//`T´', \ `'7'ーr'\n レ'ヽL__|___i,___,ンレ|ノ\n ト-,/ |___./\n 'ー' !_,.:\nLive2D 看板娘 v" + GM_info.script.version + ' / HCLonely ' + dateFormat('YYYY-mm-dd', new Date(GM_info.script.lastModified || GM_info.script.lastUpdated)) + '\n' }.msg, 'color:#ff3d3d')
/* 判断 JQuery */
if (typeof ($.ajax) !== 'function') typeof (jQuery.ajax) === 'function' ? window.$ = jQuery : console.log('[Error] JQuery is not defined.')
/* 加载看板娘样式 */
live2d_settings.waifuSize = live2d_settings.waifuSize.split('x')
live2d_settings.waifuTipsSize = live2d_settings.waifuTipsSize.split('x')
live2d_settings.waifuEdgeSide = live2d_settings.waifuEdgeSide.split(':')
$('#live2d').attr('width', live2d_settings.waifuSize[0])
$('#live2d').attr('height', live2d_settings.waifuSize[1])
$('.waifu').css('width', live2d_settings.waifuSize[0])
$('.waifu').css('height', live2d_settings.waifuSize[1])
$('.waifu-tips').width(live2d_settings.waifuTipsSize[0])
$('.waifu-tips').height(live2d_settings.waifuTipsSize[1])
$('.waifu-tips').css('top', live2d_settings.waifuToolTop)
$('.waifu-tips').css('font-size', live2d_settings.waifuFontSize)
$('.waifu-tool').css('font-size', live2d_settings.waifuToolFont)
$('.waifu-tool span').css('line-height', live2d_settings.waifuToolLine)
if (live2d_settings.waifuEdgeSide[0] === 'left') $('.waifu').css('left', live2d_settings.waifuEdgeSide[1] + 'px')
else if (live2d_settings.waifuEdgeSide[0] === 'right') $('.waifu').css('right', live2d_settings.waifuEdgeSide[1] + 'px')
if (live2d_settings.waifuDraggableClear) GM_setValue('waifuPosition', false)
if (live2d_settings.waifuDraggableSave && GM_getValue('waifuPosition')) {
const position = GM_getValue('waifuPosition')
Object.keys(position).forEach(function (key) {
$('.waifu').css(key, position[key] + 'px')
})
}
window.waifuResize = function () { $(window).width() <= Number(live2d_settings.waifuMinWidth.replace('px', '')) ? $('.waifu').hide() : $('.waifu').show() }
if (live2d_settings.waifuMinWidth !== 'disable') { waifuResize(); $(window).resize(function () { waifuResize() }) }
try {
if (live2d_settings.waifuDraggable === 'axis-x') $('.waifu').draggable({ axis: 'x', revert: live2d_settings.waifuDraggableRevert, stop: function (event, ui) { if (!live2d_settings.waifuDraggableRevert && live2d_settings.waifuDraggableSave) GM_setValue('waifuPosition', ui.position) } })
else if (live2d_settings.waifuDraggable === 'unlimited') $('.waifu').draggable({ revert: live2d_settings.waifuDraggableRevert, stop: function (event, ui) { if (!live2d_settings.waifuDraggableRevert && live2d_settings.waifuDraggableSave) { GM_setValue('waifuPosition', ui.position) } } })
else $('.waifu').css('transition', 'all .3s ease-in-out')
} catch (err) { console.log('[Error] JQuery UI is not defined.') }
live2d_settings.homePageUrl = live2d_settings.homePageUrl === 'auto' ? window.location.protocol + '//' + window.location.hostname + '/' : live2d_settings.homePageUrl
if (window.location.protocol === 'file:' && live2d_settings.modelAPI.substr(0, 2) === '//') live2d_settings.modelAPI = 'http:' + live2d_settings.modelAPI
$('.waifu-tool .fui-home').click(function () {
window.location = window.location.origin
})
$('.waifu-tool .fui-info-circle').click(function () {
window.open(live2d_settings.aboutPageUrl)
})
if (typeof (waifuPath) === 'object') loadTipsMessage(waifuPath); else {
GM_xmlhttpRequest({
method: 'GET',
url: waifuPath === '' ? live2d_settings.tipsMessage : (waifuPath.substr(waifuPath.length - 15) === 'waifu-tips.json' ? waifuPath : waifuPath + 'waifu-tips.json'),
responseType: 'json',
anonymous: true,
onload: function (result) { loadTipsMessage(result.response) }
})
}
if (!live2d_settings.showToolMenu) $('.waifu-tool').hide()
if (!live2d_settings.canCloseLive2d) $('.waifu-tool .fui-cross').hide()
if (!live2d_settings.canSwitchModel) $('.waifu-tool .fui-eye').hide()
if (!live2d_settings.canSwitchTextures) $('.waifu-tool .fui-user').hide()
if (!live2d_settings.canSwitchHitokoto) $('.waifu-tool .fui-chat').hide()
if (!live2d_settings.canTakeScreenshot) $('.waifu-tool .fui-photo').hide()
if (!live2d_settings.canTurnToHomePage) $('.waifu-tool .fui-home').hide()
if (!live2d_settings.canTurnToAboutPage) $('.waifu-tool .fui-info-circle').hide()
if (waifuPath === undefined) waifuPath = ''
let modelId = GM_getValue('modelId') || live2d_settings.modelId
let modelTexturesId = GM_getValue('modelTexturesId') || live2d_settings.modelId
if (!live2d_settings.modelStorage || modelId == null) {
modelId = live2d_settings.modelId
modelTexturesId = live2d_settings.modelTexturesId
}
loadModel(modelId, modelTexturesId)
}
function loadModel(modelId, modelTexturesId = 0) {
if (live2d_settings.modelStorage) {
GM_setValue('modelId', modelId)
GM_setValue('modelTexturesId', modelTexturesId)
const setting = GM_getValue('live2d_settings') || live2d_settings
setting.modelId = modelId
setting.modelTexturesId = modelTexturesId
GM_setValue('live2d_settings', setting)
} else {
GM_setValue('modelId', null)
GM_setValue('modelTexturesId', null)
}
loadlive2d('live2d', live2d_settings.modelAPI + 'get/?id=' + modelId + '-' + modelTexturesId, (live2d_settings.showF12Status ? console.log('[Status]', 'live2d', '模型', modelId + '-' + modelTexturesId, '加载完成') : null))
}
function loadTipsMessage(result) {
window.waifu_tips = result
$.each(result.mouseover, function (index, tips) {
$(document).on('mouseover', tips.selector, function () {
if (!($(this)[0].tagName === 'A' && ($(this).text().trim() === ''))) {
let text = getRandText(tips.text)
text = text.render({ text: $(this).text() })
showMessage(text, 3000, true)
}
})
})
$.each(result.click, function (index, tips) {
$(document).on('click', tips.selector, function () {
let text = getRandText(tips.text)
text = text.render({ text: $(this).text() })
showMessage(text, 3000, true)
})
})
$.each(result.seasons, function (index, tips) {
const now = new Date()
const after = tips.date.split('-')[0]
const before = tips.date.split('-')[1] || after
if ((after.split('/')[0] <= now.getMonth() + 1 && now.getMonth() + 1 <= before.split('/')[0]) &&
(after.split('/')[1] <= now.getDate() && now.getDate() <= before.split('/')[1])) {
let text = getRandText(tips.text)
text = text.render({ year: now.getFullYear() })
showMessage(text, 6000, true)
}
})
if (live2d_settings.showF12OpenMsg) {
Object.defineProperty(x, 'id', {
get: function () {
showMessage(getRandText(result.waifu.console_open_msg), 5000, true)
}
})
re.toString = function () {
showMessage(getRandText(result.waifu.console_open_msg), 5000, true)
return ''
}
}
if (live2d_settings.showCopyMessage) {
$(document).on('copy', function () {
showMessage(getRandText(result.waifu.copy_message), 5000, true)
})
}
$('.waifu-tool .fui-photo').click(function () {
showMessage(getRandText(result.waifu.screenshot_message), 5000, true)
window.Live2D.captureName = live2d_settings.screenshotCaptureName
window.Live2D.captureFrame = true
})
$('.waifu-tool .fui-cross').click(function () {
GM_setValue('waifu-dsiplay', 'none')
showMessage(getRandText(result.waifu.hidden_message), 1300, true)
window.setTimeout(function () { $('.waifu').hide() }, 1300)
})
window.showWelcomeMessage = function (result) {
let text
if (window.location.href === live2d_settings.homePageUrl) {
const now = (new Date()).getHours()
if (now > 23 || now <= 5) text = getRandText(result.waifu.hour_tips['t23-5'])
else if (now > 5 && now <= 7) text = getRandText(result.waifu.hour_tips['t5-7'])
else if (now > 7 && now <= 11) text = getRandText(result.waifu.hour_tips['t7-11'])
else if (now > 11 && now <= 14) text = getRandText(result.waifu.hour_tips['t11-14'])
else if (now > 14 && now <= 17) text = getRandText(result.waifu.hour_tips['t14-17'])
else if (now > 17 && now <= 19) text = getRandText(result.waifu.hour_tips['t17-19'])
else if (now > 19 && now <= 21) text = getRandText(result.waifu.hour_tips['t19-21'])
else if (now > 21 && now <= 23) text = getRandText(result.waifu.hour_tips['t21-23'])
else text = getRandText(result.waifu.hour_tips.default)
} else {
const referrer_message = result.waifu.referrer_message
if (document.referrer !== '') {
const referrer = document.createElement('a')
referrer.href = document.referrer
const domain = referrer.hostname.split('.')[1]
if (window.location.hostname === referrer.hostname) { text = referrer_message.localhost[0] + document.title.split(referrer_message.localhost[2])[0] + referrer_message.localhost[1] } else if (domain === 'baidu') { text = referrer_message.baidu[0] + referrer.search.split('&wd=')[1].split('&')[0] + referrer_message.baidu[1] } else if (domain === 'so') { text = referrer_message.so[0] + referrer.search.split('&q=')[1].split('&')[0] + referrer_message.so[1] } else if (domain === 'google') { text = referrer_message.google[0] + document.title.split(referrer_message.google[2])[0] + referrer_message.google[1] } else {
$.each(result.waifu.referrer_hostname, function (i, val) { if (i === referrer.hostname) referrer.hostname = getRandText(val) })
text = referrer_message.default[0] + referrer.hostname + referrer_message.default[1]
}
} else text = referrer_message.none[0] + document.title.split(referrer_message.none[2])[0] + referrer_message.none[1]
}
showMessage(text, 6000, true)
}; if (live2d_settings.showWelcomeMessage) showWelcomeMessage(result)
const waifu_tips = result.waifu
function randId(id, length) {
const newId = parseInt(Math.random() * length + 1, 10)
return newId === id ? randId(id, length) : newId
}
function loadOtherModel() {
const modelId = parseInt(modelStorageGetItem('modelId'))
const modelRandMode = live2d_settings.modelRandMode
if (live2d_settings.modelAPI === 'default') {
if (modelRandMode === 'switch') {
const newId = modelId >= modelList.length ? 1 : (modelId + 1)
loadModel(newId)
let message = ''
$.each(waifu_tips.model_message, function (i, val) { if (i === newId) message = getRandText(val) })
showMessage(message, 3000, true)
} else {
const newId = randId(modelId, modelList.length)
loadModel(newId)
let message = ''
$.each(waifu_tips.model_message, function (i, val) { if (i === newId) message = getRandText(val) })
showMessage(message, 3000, true)
}
} else {
GM_xmlhttpRequest({
method: 'GET',
url: live2d_settings.modelAPI + modelRandMode + '/?id=' + modelId,
responseType: 'json',
anonymous: true,
onload: function (data) {
const result = data.response
loadModel(result.model.id)
let message = result.model.message
$.each(waifu_tips.model_message, function (i, val) { if (i === result.model.id) message = getRandText(val) })
showMessage(message, 3000, true)
}
})
}
}
function loadRandTextures() {
const modelId = parseInt(modelStorageGetItem('modelId'))
const modelTexturesId = parseInt(modelStorageGetItem('modelTexturesId'))
const modelTexturesRandMode = live2d_settings.modelTexturesRandMode
if (live2d_settings.modelAPI === 'default') {
const modelInfo = modelList[parseInt(modelId) - 1]
if (Array.isArray(modelInfo)) {
if (modelTexturesRandMode === 'switch') {
const newId = modelTexturesId >= modelInfo.length ? 1 : (modelTexturesId + 1)
showMessage(waifu_tips.load_rand_textures[1], 3000, true)
loadModel(modelId, newId)
} else {
const newId = randId(modelTexturesId, modelInfo.length)
showMessage(waifu_tips.load_rand_textures[1], 3000, true)
loadModel(modelId, newId)
}
} else {
showMessage(waifu_tips.load_rand_textures[0], 3000, true)
loadModel(modelId, 1)
}
} else {
GM_xmlhttpRequest({
method: 'GET',
url: live2d_settings.modelAPI + modelTexturesRandMode + '_textures/?id=' + modelId + '-' + modelTexturesId,
responseType: 'json',
anonymous: true,
onload: function (data) {
const result = data.response
if (result.textures.id === 1 && (modelTexturesId === 1 || modelTexturesId === 0)) {
showMessage(waifu_tips.load_rand_textures[0], 3000, true)
} else {
showMessage(waifu_tips.load_rand_textures[1], 3000, true)
}
loadModel(modelId, result.textures.id)
}
})
}
}
function modelStorageGetItem(key) { return live2d_settings.modelStorage ? GM_getValue(key) : GM_getValue(key) }
/* 检测用户活动状态,并在空闲时显示一言 */
if (live2d_settings.showHitokoto) {
window.getActed = true; window.hitokotoTimer = 30000; window.hitokotoInterval = true
$(document).mousemove(function (e) { getActed = true }).keydown(function () { getActed = true })
setInterval(function () { if (!getActed) ifActed(); else elseActed() }, 1000)
}
function ifActed() {
if (!hitokotoInterval) {
hitokotoInterval = true
hitokotoTimer = window.setInterval(showHitokotoActed, 30000)
}
}
function elseActed() {
getActed = hitokotoInterval = false
window.clearInterval(hitokotoTimer)
}
function showHitokotoActed() {
if ($(document)[0].visibilityState === 'visible') showHitokoto()
}
function showHitokoto(e = false) {
const api = e || live2d_settings.hitokotoAPI
switch (api) {
case 'lwl12.com':
GM_xmlhttpRequest({
method: 'GET',
url: 'https://api.lwl12.com/hitokoto/v1?encode=realjson',
responseType: 'json',
anonymous: true,
onload: function (data) {
const result = data.response
if (!empty(result.source)) {
let text = waifu_tips.hitokoto_api_message['lwl12.com'][0]
if (!empty(result.author)) text += waifu_tips.hitokoto_api_message['lwl12.com'][1]
text = text.render({ source: result.source, creator: result.author })
window.setTimeout(function () { showMessage(text + waifu_tips.hitokoto_api_message['lwl12.com'][2], 3000, true) }, 5000)
}
showMessage(result.text, 5000, true)
}
})
break
case 'fghrsh.net':
GM_xmlhttpRequest({
method: 'GET',
url: 'https://api.fghrsh.net/hitokoto/rand/?encode=jsc&uid=3335',
anonymous: true,
responseType: 'json',
onload: function (data) {
const result = data.response
if (!empty(result.source)) {
let text = waifu_tips.hitokoto_api_message['fghrsh.net'][0]
text = text.render({ source: result.source, date: result.date })
window.setTimeout(function () { showMessage(text, 3000, true) }, 5000)
showMessage(result.hitokoto, 5000, true)
}
}
})
break
case 'jinrishici.com':
GM_xmlhttpRequest({
method: 'GET',
url: 'https://v2.jinrishici.com/one.json',
responseType: 'json',
anonymous: true,
onload: function (data) {
const result = data.response
if (!empty(result.data.origin.title)) {
let text = waifu_tips.hitokoto_api_message['jinrishici.com'][0]
text = text.render({ title: result.data.origin.title, dynasty: result.data.origin.dynasty, author: result.data.origin.author })
window.setTimeout(function () { showMessage(text, 3000, true) }, 5000)
}
showMessage(result.data.content, 5000, true)
}
})
break
case 'hitokoto.cn':
GM_xmlhttpRequest({
method: 'GET',
url: 'https://v1.hitokoto.cn',
responseType: 'json',
anonymous: true,
onload: function (data) {
const result = data.response
if (!empty(result.from)) {
let text = waifu_tips.hitokoto_api_message['hitokoto.cn'][0]
text = text.render({ source: result.from, creator: result.creator })
window.setTimeout(function () { showMessage(text, 3000, true) }, 5000)
}
showMessage(result.hitokoto, 5000, true)
}
})
break
default:
showHitokoto(['lwl12.com', 'fghrsh.net', 'jinrishici.com', 'hitokoto.cn'][Math.floor((Math.random() * 4))])
}
}
let hidden, visibilityChange
if (typeof document.hidden !== 'undefined') {
hidden = 'hidden'
visibilityChange = 'visibilitychange'
} else if (typeof document.msHidden !== 'undefined') {
hidden = 'msHidden'
visibilityChange = 'msvisibilitychange'
} else if (typeof document.webkitHidden !== 'undefined') {
hidden = 'webkitHidden'
visibilityChange = 'webkitvisibilitychange'
}
function handleVisibilityChange() {
if (!document[hidden]) showMessage('主人,欢迎回来!', 4000, true)
}
if (!(typeof document.addEventListener === 'undefined' || typeof document[hidden] === 'undefined')) {
document.addEventListener(visibilityChange, handleVisibilityChange, false)
}
let videoStatus = false
$('video').on('timeupdate', function (e) {
if (this.paused) {
showMessage('你怎么暂停了呀', 4000, true)
} else if (videoStatus === false) {
showMessage('你在看什么啊,让我康康', 4000, true)
}
videoStatus = !this.paused
if (Math.abs(this.currentTime - this.duration / 2) < 1) {
showMessage('进度条已过半,且看且珍惜', 4000, true)
}
})
let audioStatus = false
$('audio').on('timeupdate', function (e) {
if (this.paused) {
showMessage('怎么不听了呀', 4000, true)
} else if (audioStatus === false) {
showMessage('你在听什么呀,这么好听', 4000, true)
}
audioStatus = !this.paused
})
$('.waifu-tool .fui-eye').click(function () { loadOtherModel() })
$('.waifu-tool .fui-user').click(function () { loadRandTextures() })
$('.waifu-tool .fui-chat').click(function () { showHitokoto() })
}
/* eslint-disable */
/** ********************************************live2d.js**************************************************************/
!(function (t) {
function i(r) {
if (e[r]) return e[r].exports
const o = e[r] = {
i: r,
l: !1,
exports: {}
}
return t[r].call(o.exports, o, o.exports, i), o.l = !0, o.exports
}
var e = {}
i.m = t, i.c = e, i.d = function (t, e, r) {
i.o(t, e) || Object.defineProperty(t, e, {
configurable: !1,
enumerable: !0,
get: r
})
}, i.n = function (t) {
const e = t && t.__esModule
? function () {
return t
.default
} : function () {
return t
}
return i.d(e, 'a', e), e
}, i.o = function (t, i) {
return Object.prototype.hasOwnProperty.call(t, i)
}, i.p = '', i(i.s = 4)
}([function (t, i, e) {
'use strict'
function r() {
this.live2DModel = null, this.modelMatrix = null, this.eyeBlink = null, this.physics = null, this.pose = null, this.debugMode = !1, this.initialized = !1, this.updating = !1, this.alpha = 1, this.accAlpha = 0, this.lipSync = !1, this.lipSyncValue = 0, this.accelX = 0, this.accelY = 0, this.accelZ = 0, this.dragX = 0, this.dragY = 0, this.startTimeMSec = null, this.mainMotionManager = new h(), this.expressionManager = new h(), this.motions = {}, this.expressions = {}, this.isTexLoaded = !1
}
function o() {
AMotion.prototype.constructor.call(this), this.paramList = new Array()
}
function n() {
this.id = '', this.type = -1, this.value = null
}
function s() {
this.nextBlinkTime = null, this.stateStartTime = null, this.blinkIntervalMsec = null, this.eyeState = g.STATE_FIRST, this.blinkIntervalMsec = 4e3, this.closingMotionMsec = 100, this.closedMotionMsec = 50, this.openingMotionMsec = 150, this.closeIfZero = !0, this.eyeID_L = 'PARAM_EYE_L_OPEN', this.eyeID_R = 'PARAM_EYE_R_OPEN'
}
function _() {
this.tr = new Float32Array(16), this.identity()
}
function a(t, i) {
_.prototype.constructor.call(this), this.width = t, this.height = i
}
function h() {
MotionQueueManager.prototype.constructor.call(this), this.currentPriority = null, this.reservePriority = null, this.super = MotionQueueManager.prototype
}
function l() {
this.physicsList = new Array(), this.startTimeMSec = UtSystem.getUserTimeMSec()
}
function $() {
this.lastTime = 0, this.lastModel = null, this.partsGroups = new Array()
}
function u(t) {
this.paramIndex = -1, this.partsIndex = -1, this.link = null, this.id = t
}
function p() {
this.EPSILON = 0.01, this.faceTargetX = 0, this.faceTargetY = 0, this.faceX = 0, this.faceY = 0, this.faceVX = 0, this.faceVY = 0, this.lastTimeSec = 0
}
function f() {
_.prototype.constructor.call(this), this.screenLeft = null, this.screenRight = null, this.screenTop = null, this.screenBottom = null, this.maxLeft = null, this.maxRight = null, this.maxTop = null, this.maxBottom = null, this.max = Number.MAX_VALUE, this.min = 0
}
function c() { }
let d = 0
r.prototype.getModelMatrix = function () {
return this.modelMatrix
}, r.prototype.setAlpha = function (t) {
t > 0.999 && (t = 1), t < 0.001 && (t = 0), this.alpha = t
}, r.prototype.getAlpha = function () {
return this.alpha
}, r.prototype.isInitialized = function () {
return this.initialized
}, r.prototype.setInitialized = function (t) {
this.initialized = t
}, r.prototype.isUpdating = function () {
return this.updating
}, r.prototype.setUpdating = function (t) {
this.updating = t
}, r.prototype.getLive2DModel = function () {
return this.live2DModel
}, r.prototype.setLipSync = function (t) {
this.lipSync = t
}, r.prototype.setLipSyncValue = function (t) {
this.lipSyncValue = t
}, r.prototype.setAccel = function (t, i, e) {
this.accelX = t, this.accelY = i, this.accelZ = e
}, r.prototype.setDrag = function (t, i) {
this.dragX = t, this.dragY = i
}, r.prototype.getMainMotionManager = function () {
return this.mainMotionManager
}, r.prototype.getExpressionManager = function () {
return this.expressionManager
}, r.prototype.loadModelData = function (t, i) {
const e = c.getPlatformManager()
this.debugMode && e.log('Load model : ' + t)
const r = this
e.loadLive2DModel(t, function (t) {
if (r.live2DModel = t, r.live2DModel.saveParam(), Live2D.getError() != 0) return void console.error('Error : Failed to loadModelData().')
r.modelMatrix = new a(r.live2DModel.getCanvasWidth(), r.live2DModel.getCanvasHeight()), r.modelMatrix.setWidth(2), r.modelMatrix.setCenterPosition(0, 0), i(r.live2DModel)
})
}, r.prototype.loadTexture = function (t, i, e) {
d++
const r = c.getPlatformManager()
this.debugMode && r.log('Load Texture : ' + i)
const o = this
r.loadTexture(this.live2DModel, t, i, function () {
d--, d == 0 && (o.isTexLoaded = !0), typeof e === 'function' && e()
})
}, r.prototype.loadMotion = function (t, i, e) {
const r = c.getPlatformManager()
this.debugMode && r.log('Load Motion : ' + i)
let o = null
const n = this
r.loadBytes(i, function (i) {
o = Live2DMotion.loadMotion(i), t != null && (n.motions[t] = o), e(o)
})
}, r.prototype.loadExpression = function (t, i, e) {
const r = c.getPlatformManager()
this.debugMode && r.log('Load Expression : ' + i)
const n = this
r.loadBytes(i, function (i) {
t != null && (n.expressions[t] = o.loadJson(i)), typeof e === 'function' && e()
})
}, r.prototype.loadPose = function (t, i) {
const e = c.getPlatformManager()
this.debugMode && e.log('Load Pose : ' + t)
const r = this
try {
e.loadBytes(t, function (t) {
r.pose = $.load(t), typeof i === 'function' && i()
})
} catch (t) {
console.warn(t)
}
}, r.prototype.loadPhysics = function (t) {
const i = c.getPlatformManager()
this.debugMode && i.log('Load Physics : ' + t)
const e = this
try {
i.loadBytes(t, function (t) {
e.physics = l.load(t)
})
} catch (t) {
console.warn(t)
}
}, r.prototype.hitTestSimple = function (t, i, e) {
if (this.live2DModel === null) return !1
const r = this.live2DModel.getDrawDataIndex(t)
if (r < 0) return !1
for (var o = this.live2DModel.getTransformedPoints(r), n = this.live2DModel.getCanvasWidth(), s = 0, _ = this.live2DModel.getCanvasHeight(), a = 0, h = 0; h < o.length; h += 2) {
const l = o[h]
const $ = o[h + 1]
l < n && (n = l), l > s && (s = l), $ < _ && (_ = $), $ > a && (a = $)
}
const u = this.modelMatrix.invertTransformX(i)
const p = this.modelMatrix.invertTransformY(e)
return n <= u && u <= s && _ <= p && p <= a
}, r.prototype.hitTestSimpleCustom = function (t, i, e, r) {
return this.live2DModel !== null && (e >= t[0] && e <= i[0] && r <= t[1] && r >= i[1])
}, o.prototype = new AMotion(), o.EXPRESSION_DEFAULT = 'DEFAULT', o.TYPE_SET = 0, o.TYPE_ADD = 1, o.TYPE_MULT = 2, o.loadJson = function (t) {
const i = new o()
const e = c.getPlatformManager()
const r = e.jsonParseFromBytes(t)
if (i.setFadeIn(parseInt(r.fade_in) > 0 ? parseInt(r.fade_in) : 1e3), i.setFadeOut(parseInt(r.fade_out) > 0 ? parseInt(r.fade_out) : 1e3), r.params == null) return i
const s = r.params
const _ = s.length
i.paramList = []
for (let a = 0; a < _; a++) {
const h = s[a]
const l = h.id.toString()
let $ = parseFloat(h.val)
let u = o.TYPE_ADD
const p = h.calc != null ? h.calc.toString() : 'add'
if ((u = p === 'add' ? o.TYPE_ADD : p === 'mult' ? o.TYPE_MULT : p === 'set' ? o.TYPE_SET : o.TYPE_ADD) == o.TYPE_ADD) {
var f = h.def == null ? 0 : parseFloat(h.def)
$ -= f
} else if (u == o.TYPE_MULT) {
var f = h.def == null ? 1 : parseFloat(h.def)
f == 0 && (f = 1), $ /= f
}
const d = new n()
d.id = l, d.type = u, d.value = $, i.paramList.push(d)
}
return i
}, o.prototype.updateParamExe = function (t, i, e, r) {
for (let n = this.paramList.length - 1; n >= 0; --n) {
const s = this.paramList[n]
s.type == o.TYPE_ADD ? t.addToParamFloat(s.id, s.value, e) : s.type == o.TYPE_MULT ? t.multParamFloat(s.id, s.value, e) : s.type == o.TYPE_SET && t.setParamFloat(s.id, s.value, e)
}
}, s.prototype.calcNextBlink = function () {
return UtSystem.getUserTimeMSec() + Math.random() * (2 * this.blinkIntervalMsec - 1)
}, s.prototype.setInterval = function (t) {
this.blinkIntervalMsec = t
}, s.prototype.setEyeMotion = function (t, i, e) {
this.closingMotionMsec = t, this.closedMotionMsec = i, this.openingMotionMsec = e
}, s.prototype.updateParam = function (t) {
let i; const e = UtSystem.getUserTimeMSec()
let r = 0
switch (this.eyeState) {
case g.STATE_CLOSING:
r = (e - this.stateStartTime) / this.closingMotionMsec, r >= 1 && (r = 1, this.eyeState = g.STATE_CLOSED, this.stateStartTime = e), i = 1 - r
break
case g.STATE_CLOSED:
r = (e - this.stateStartTime) / this.closedMotionMsec, r >= 1 && (this.eyeState = g.STATE_OPENING, this.stateStartTime = e), i = 0
break
case g.STATE_OPENING:
r = (e - this.stateStartTime) / this.openingMotionMsec, r >= 1 && (r = 1, this.eyeState = g.STATE_INTERVAL, this.nextBlinkTime = this.calcNextBlink()), i = r
break
case g.STATE_INTERVAL:
this.nextBlinkTime < e && (this.eyeState = g.STATE_CLOSING, this.stateStartTime = e), i = 1
break
case g.STATE_FIRST:
default:
this.eyeState = g.STATE_INTERVAL, this.nextBlinkTime = this.calcNextBlink(), i = 1
}
this.closeIfZero || (i = -i), t.setParamFloat(this.eyeID_L, i), t.setParamFloat(this.eyeID_R, i)
}
var g = function () { }
g.STATE_FIRST = 'STATE_FIRST', g.STATE_INTERVAL = 'STATE_INTERVAL', g.STATE_CLOSING = 'STATE_CLOSING', g.STATE_CLOSED = 'STATE_CLOSED', g.STATE_OPENING = 'STATE_OPENING', _.mul = function (t, i, e) {
let r; let o; let n; const s = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for (r = 0; r < 4; r++) for (o = 0; o < 4; o++) for (n = 0; n < 4; n++) s[r + 4 * o] += t[r + 4 * n] * i[n + 4 * o]
for (r = 0; r < 16; r++) e[r] = s[r]
}, _.prototype.identity = function () {
for (let t = 0; t < 16; t++) this.tr[t] = t % 5 == 0 ? 1 : 0
}, _.prototype.getArray = function () {
return this.tr
}, _.prototype.getCopyMatrix = function () {
return new Float32Array(this.tr)
}, _.prototype.setMatrix = function (t) {
if (this.tr != null && this.tr.length == this.tr.length) for (let i = 0; i < 16; i++) this.tr[i] = t[i]
}, _.prototype.getScaleX = function () {
return this.tr[0]
}, _.prototype.getScaleY = function () {
return this.tr[5]
}, _.prototype.transformX = function (t) {
return this.tr[0] * t + this.tr[12]
}, _.prototype.transformY = function (t) {
return this.tr[5] * t + this.tr[13]
}, _.prototype.invertTransformX = function (t) {
return (t - this.tr[12]) / this.tr[0]
}, _.prototype.invertTransformY = function (t) {
return (t - this.tr[13]) / this.tr[5]
}, _.prototype.multTranslate = function (t, i) {
const e = [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, t, i, 0, 1]
_.mul(e, this.tr, this.tr)
}, _.prototype.translate = function (t, i) {
this.tr[12] = t, this.tr[13] = i
}, _.prototype.translateX = function (t) {
this.tr[12] = t
}, _.prototype.translateY = function (t) {
this.tr[13] = t
}, _.prototype.multScale = function (t, i) {
const e = [t, 0, 0, 0, 0, i, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]
_.mul(e, this.tr, this.tr)
}, _.prototype.scale = function (t, i) {
this.tr[0] = t, this.tr[5] = i
}, a.prototype = new _(), a.prototype.setPosition = function (t, i) {
this.translate(t, i)
}, a.prototype.setCenterPosition = function (t, i) {
const e = this.width * this.getScaleX()
const r = this.height * this.getScaleY()
this.translate(t - e / 2, i - r / 2)
}, a.prototype.top = function (t) {
this.setY(t)
}, a.prototype.bottom = function (t) {
const i = this.height * this.getScaleY()
this.translateY(t - i)
}, a.prototype.left = function (t) {
this.setX(t)
}, a.prototype.right = function (t) {
const i = this.width * this.getScaleX()
this.translateX(t - i)
}, a.prototype.centerX = function (t) {
const i = this.width * this.getScaleX()
this.translateX(t - i / 2)
}, a.prototype.centerY = function (t) {
const i = this.height * this.getScaleY()
this.translateY(t - i / 2)
}, a.prototype.setX = function (t) {
this.translateX(t)
}, a.prototype.setY = function (t) {
this.translateY(t)
}, a.prototype.setHeight = function (t) {
const i = t / this.height
const e = -i
this.scale(i, e)
}, a.prototype.setWidth = function (t) {
const i = t / this.width
const e = -i
this.scale(i, e)
}, h.prototype = new MotionQueueManager(), h.prototype.getCurrentPriority = function () {
return this.currentPriority
}, h.prototype.getReservePriority = function () {
return this.reservePriority
}, h.prototype.reserveMotion = function (t) {
return !(this.reservePriority >= t) && (!(this.currentPriority >= t) && (this.reservePriority = t, !0))
}, h.prototype.setReservePriority = function (t) {
this.reservePriority = t
}, h.prototype.updateParam = function (t) {
const i = MotionQueueManager.prototype.updateParam.call(this, t)
return this.isFinished() && (this.currentPriority = 0), i
}, h.prototype.startMotionPrio = function (t, i) {
return i == this.reservePriority && (this.reservePriority = 0), this.currentPriority = i, this.startMotion(t, !1)
}, l.load = function (t) {
for (var i = new l(), e = c.getPlatformManager(), r = e.jsonParseFromBytes(t), o = r.physics_hair, n = o.length, s = 0; s < n; s++) {
const _ = o[s]
const a = new PhysicsHair()
const h = _.setup
const $ = parseFloat(h.length)
const u = parseFloat(h.regist)
const p = parseFloat(h.mass)
a.setup($, u, p)
for (var f = _.src, d = f.length, g = 0; g < d; g++) {
const y = f[g]
var m = y.id
var T = PhysicsHair.Src.SRC_TO_X
var P = y.ptype
P === 'x' ? T = PhysicsHair.Src.SRC_TO_X : P === 'y' ? T = PhysicsHair.Src.SRC_TO_Y : P === 'angle' ? T = PhysicsHair.Src.SRC_TO_G_ANGLE : UtDebug('live2d', 'Invalid parameter:PhysicsHair.Src')
var S = parseFloat(y.scale)
var v = parseFloat(y.weight)
a.addSrcParam(T, m, S, v)
}
for (var L = _.targets, M = L.length, g = 0; g < M; g++) {
const E = L[g]
var m = E.id
var T = PhysicsHair.Target.TARGET_FROM_ANGLE
var P = E.ptype
P === 'angle' ? T = PhysicsHair.Target.TARGET_FROM_ANGLE : P === 'angle_v' ? T = PhysicsHair.Target.TARGET_FROM_ANGLE_V : UtDebug('live2d', 'Invalid parameter:PhysicsHair.Target')
var S = parseFloat(E.scale)
var v = parseFloat(E.weight)
a.addTargetParam(T, m, S, v)
}
i.physicsList.push(a)
}
return i
}, l.prototype.updateParam = function (t) {
for (let i = UtSystem.getUserTimeMSec() - this.startTimeMSec, e = 0; e < this.physicsList.length; e++) this.physicsList[e].update(t, i)
}, $.load = function (t) {
for (var i = new $(), e = c.getPlatformManager(), r = e.jsonParseFromBytes(t), o = r.parts_visible, n = o.length, s = 0; s < n; s++) {
for (var _ = o[s], a = _.group, h = a.length, l = new Array(), p = 0; p < h; p++) {
const f = a[p]
const d = new u(f.id)
if (l[p] = d, f.link != null) {
const g = f.link
const y = g.length
d.link = new Array()
for (let m = 0; m < y; m++) {
const T = new u(g[m])
d.link.push(T)
}
}
}
i.partsGroups.push(l)
}
return i
}, $.prototype.updateParam = function (t) {
if (t != null) {
t != this.lastModel && this.initParam(t), this.lastModel = t
const i = UtSystem.getUserTimeMSec()
let e = this.lastTime == 0 ? 0 : (i - this.lastTime) / 1e3
this.lastTime = i, e < 0 && (e = 0)
for (let r = 0; r < this.partsGroups.length; r++) this.normalizePartsOpacityGroup(t, this.partsGroups[r], e), this.copyOpacityOtherParts(t, this.partsGroups[r])
}
}, $.prototype.initParam = function (t) {
if (t != null) {
for (let i = 0; i < this.partsGroups.length; i++) {
for (let e = this.partsGroups[i], r = 0; r < e.length; r++) {
e[r].initIndex(t)
const o = e[r].partsIndex
const n = e[r].paramIndex
if (!(o < 0)) {
const s = t.getParamFloat(n) != 0
if (t.setPartsOpacity(o, s ? 1 : 0), t.setParamFloat(n, s ? 1 : 0), e[r].link != null) for (let _ = 0; _ < e[r].link.length; _++) e[r].link[_].initIndex(t)
}
}
}
}
}, $.prototype.normalizePartsOpacityGroup = function (t, i, e) {
for (var r = -1, o = 1, n = 0; n < i.length; n++) {
var s = i[n].partsIndex
const _ = i[n].paramIndex
if (!(s < 0) && t.getParamFloat(_) != 0) {
if (r >= 0) break
r = n, o = t.getPartsOpacity(s), o += e / 0.5, o > 1 && (o = 1)
}
}
r < 0 && (r = 0, o = 1)
for (var n = 0; n < i.length; n++) {
var s = i[n].partsIndex
if (!(s < 0)) {
if (r == n) t.setPartsOpacity(s, o)
else {
var a; let h = t.getPartsOpacity(s)
a = o < 0.5 ? -0.5 * o / 0.5 + 1 : 0.5 * (1 - o) / 0.5
const l = (1 - a) * (1 - o)
l > 0.15 && (a = 1 - 0.15 / (1 - o)), h > a && (h = a), t.setPartsOpacity(s, h)
}
}
}
}, $.prototype.copyOpacityOtherParts = function (t, i) {
for (let e = 0; e < i.length; e++) {
const r = i[e]
if (r.link != null && !(r.partsIndex < 0)) {
for (let o = t.getPartsOpacity(r.partsIndex), n = 0; n < r.link.length; n++) {
const s = r.link[n]
s.partsIndex < 0 || t.setPartsOpacity(s.partsIndex, o)
}
}
}
}, u.prototype.initIndex = function (t) {