-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnyaggertunes.js
More file actions
398 lines (352 loc) · 13.5 KB
/
nyaggertunes.js
File metadata and controls
398 lines (352 loc) · 13.5 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
// ==UserScript==
// @name NyaggerTunes CLEAN
// @namespace NyaggerSquad
// @icon https://i.imgur.com/sGe5FJ1.png
// @version 1.04
// @description You'll cowards don't even riichi. Now with Youtube integration, press escape to open menu and input video IDs to replace music. Create playlists by separating with commas. (Remember to unblock youtube, ytimg and googlevideo scripts and allow site autoplay in your browser)
// @author anon
// @include https://mahjongsoul.game.yo-star.com/
// @include https://game.mahjongsoul.com/
// @include https://majsoul.union-game.com/0/
// @grant GM_addStyle
// ==/UserScript==
GM_addStyle(`
.fuck{
background-color:#eee;
position:fixed;
z-index:1000;
background-size: 120px 120px;
background-position: right bottom;
background-repeat: no-repeat;
background-image: url('https://i.imgur.com/sGe5FJ1.png');
border-radius:5px;
margin:0px;
box-shadow: 3px 5px 5px #0005;
}
.tarea{
background: #fffb;
display:block;
margin:5px;
height:35px;
width:300px;
white-space: nowrap;
}
.labelBtn{
background: #fffb;
font-size:10pt;
padding:3px;
float:left;
margin:5px;
margin-left:5px;
border-width: 2px;
border-style: solid;
border-bottom-color: gray;
border-right-color: gray;
border-top-color: silver;
border-left-color: silver;
}
input[type=checkbox]:checked + label{
background: #6f6b;
border: 2px solid #3c3;
}
`);
//automate this some time
var map = {
'music/game.mp3': ['6o3vN8AfkRk','NvJGKyiGPyQ','mLDo-jHcvAQ'],
'music/lobby.mp3': 'jX6fqafv3_Q',
'music/liqi1.mp3': 'Uniah8hu7Mk',
'music/liqi2.mp3': '1jJsYbVBnaE',
};
var playlist = [];
var pindex = 0;
var pshuffle = true;
var ready = false;
var shuffleMap = [];
var YTdiv = document.createElement('div');
YTdiv.id = "ytplayer";
YTdiv.style="visibility:hidden;";
document.body.appendChild(YTdiv);
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
unsafeWindow.onYouTubeIframeAPIReady = function(){
player = new YT.Player('ytplayer',{
height: '0',
width: '0',
videoId: '6o3vN8AfkRk',
//host: 'https://www.youtube.com',
playerVars: {
origin: 'https://mahjongsoul.game.yo-star.com',
enablejsapi: '1',
mute: '1',
},
events:{
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
function onPlayerReady(event){
//event.target.playVideo();
}
function onPlayerStateChange(event){
//YT.PlayerState.PLAYING
if (event.data == YT.PlayerState.ENDED) {
if (Array.isArray(playlist)){
if (++pindex==playlist.length)
pindex = 0;
player.loadVideoById(playlist[shuffleMap[pindex]]);
return;
}
player.loadVideoById(playlist);
}
}
var once = false;
function playerCheck(f){
if (!player || !player[f]){
console.log("Youtube player not initialized.");
if (!once){
alert("Youtube player not initialized. Check your script blockers.");
once = true;
}
return false;
}
return true;
}
function stopVideo(){
if (playerCheck("stopVideo"))
player.stopVideo();
}
function setVolume(v){
if (playerCheck("setVolume"))
player.setVolume(v);
}
(function() {
'use strict';
document.addEventListener('keydown', function(e) {
e = e || window.event;
if (e.keyCode == 27 && ready)
ToggleMenu();
}, true);
var Menu = document.createElement('div');
document.body.appendChild(Menu);
function GetAudioList(){
for (let key in cfg.audio.bgm.map_){
map[cfg.audio.bgm.map_[key].path] = "";
}
for (let key in cfg.item_definition.item.map_){
let row = cfg.item_definition.item.map_[key];
if (Array.isArray(row.sargs) && row.sargs[0].search("music/") != -1){
map[row.sargs[0]] = "";
}
}
};
function CloseMenu(){
Menu.style.visibility = "hidden";
for (var m in map){
var iv = document.getElementById(m).value.replace(/\s/g,"").split(',');
map[m] = iv.length==1?iv[0]:iv;
}
pshuffle = document.getElementById('shuffleBtn').checked;
localStorage.setItem("tutturu", JSON.stringify({
tunes: map,
shuffle: pshuffle
}));
localStorage.removeItem("riichiFile"); //old trash
}
function ToggleMenu(){
Menu.style.visibility==""?CloseMenu():Menu.style.visibility="";
}
function InitMenu(){
Menu.className = "fuck";
Menu.style = 'position:absolute';
GetAudioList();
if (localStorage.getItem("tutturu")){
let local = JSON.parse(localStorage.getItem("tutturu"));
for (let m in local.tunes)
map[m] = local.tunes[m];
pshuffle = local.shuffle;
}
for (let m in map){
let label = document.createElement('label');
label.style = 'height:10px;color:gray;font-size:12pt;margin:5px;display:block;';
label.innerHTML = m;
let input = document.createElement('textarea');
input.className = "tarea";
input.id = m;
input.autocomplete="off";
input.autocorrect="off";
input.autocapitalize="off";
input.spellcheck="false";
input.value = Array.isArray(map[m])?map[m].join():map[m];
Menu.appendChild(label);
Menu.appendChild(input);
}
function makeButton(id, string, checked){
let label = document.createElement('label');
label.for = id;
label.className = "labelBtn";
label.innerHTML = string;
label.onclick = function(e){
var input = document.getElementById(this.for);
input.checked = !input.checked;
}
let input = document.createElement('input');
input.type = "checkbox";
input.id = id;
input.style = "display:none;";
input.checked = checked;
Menu.appendChild(input);
Menu.appendChild(label);
}
makeButton("shuffleBtn","Shuffle Playlists",pshuffle);
Menu.init = "FuckJavascript";
Menu.style.visibility = "hidden";
}
document.addEventListener("click", function(event){
if (event.target.closest(".fuck"))
return;
if (Menu.style.visibility == "")
CloseMenu();
});
function shuffleArray(a) {
for (let i = a.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[a[i], a[j]] = [a[j], a[i]];
}
return a;
}
function setShuffle(toggle){
if (Array.isArray(playlist)){
for (var i = 0; i < playlist.length; i++){
shuffleMap[i] = i;
}
} else
shuffleMap = [0];
if (toggle)
shuffleArray(shuffleMap);
}
function loadPlaylist(ids, index){ //courtesy of google being fucking worthless
playlist = ids;
pindex = index;
setShuffle(pshuffle);
if (Array.isArray(playlist)){
player.loadVideoById(playlist[shuffleMap[index]]);
return;
}
player.loadVideoById(playlist);
}
function playSomething(i, d){
for (var m in map){
if (m == i){
var id = map[m];
if (Array.isArray(map[m]))
id = map[m][shuffleMap[pindex]];
if (id == "" || !playerCheck("getVideoData"))
continue;
if (player.getVideoData()['video_id'] != id || player.getPlayerState() != YT.PlayerState.PLAYING)
loadPlaylist(map[m],0);
player.unMute();
Laya.SoundManager.stopMusic(0);
return d;
}
}
stopVideo();
return Laya.SoundManager.playMusic("audio/" + i, 0);
}
var e;
! function(t) {
t[t.none = 0] = "none", t[t.start = 1] = "start", t[t.during = 2] = "during", t[t.end = 3] = "end"
}(e || (e = {}));
function onMusicChange(t){
try{
void 0 === t && (t = 1e3);
var i = "",
n = 0;
"" == i && !this.lizhiMuted && this._current_lizhi_bgm && (i = this._current_lizhi_bgm, n = this.lizhiVolume),
"" == i && !this.musicMuted && this._current_music && (i = this._current_music, n = this.musicVolume),
this._music ? i == this._playing_music ||
(this._music.stop(), this._music = null, i && (this._music = playSomething(i,this._music),
this._music &&
(this._playing_music = i,
this._playing_music_volume = n,
this._music.volume = 0,
this._music_state = e.start,
this._music_state_starttime = Laya.timer.currTimer,
this._music_state_lifetime = t)))
: i && (this._music = playSomething(i,this._music),
this._music && (this._playing_music = i,
this._playing_music_volume = n,
this._music.volume = 0,
this._music_state = e.start,
this._music_state_starttime = Laya.timer.currTimer,
this._music_state_lifetime = t))
//beautiful
this._playing_music = i;
this._playing_music_volume = n;
this._music_state = e.start;
this._music_state_starttime = Laya.timer.currTimer;
this._music_state_lifetime = t;
setVolume(n*100.0);
player.defaultVol = n*100.0;
} catch(e){console.log(e); stopVideo(); backup(t);}
}
var backup = 0;
var LobbyCheck = setInterval(function(){
if (GameMgr.prototype.EnterLobby){
setShuffle(pshuffle);
GameMgr.prototype.EnterLobby = (function() {
var cacheF = GameMgr.prototype.EnterLobby;
return function() {
ready = true;
if (!Menu.init) InitMenu();
backup = view.AudioMgr.onMusicChange;
view.AudioMgr.onMusicChange = onMusicChange;
view.AudioMgr.StopMusic = function(t) {
void 0 === t && (t = 1e3)
this._current_music = "";
this._current_lizhi_bgm = "";
(t <= 0 ?
(playerCheck("stopVideo") && player.stopVideo(), this._music && this._music.stop(), this._music = null, this._music_state = e.none) :
(this._music_state = e.end, this._music_state_starttime = Laya.timer.currTimer, this._music_state_lifetime = t)
)
}
Laya.timer._getHandler(view.AudioMgr,view.AudioMgr._update).method = (function(){
var c = view.AudioMgr._update;
return function() {
if (!isNaN(player.getVolume())){
var volume = player.defaultVol/100.0;
if (this._music_state != e.none) {
var t = Laya.timer.currTimer - this._music_state_starttime;
if (this._music_state == e.start){
if (t >= this._music_state_lifetime) volume = this._playing_music_volume;
else {
i = t / this._music_state_lifetime;
volume = volume * i;
}
} else if (this._music_state == e.end){
if (t >= this._music_state_lifetime) {volume = 0; player.stopVideo();}
else {
var i = t / this._music_state_lifetime;
volume = volume * (1 - i);
}
}
}
setVolume(volume*100.0);
}
var res = c.apply(this,arguments);
if (this._music_state == e.start && t >= this._music_state_lifetime) this._music_state = e.during;
else if (this._music_state == e.end && t >= this._music_state_lifetime) this._music_state = e.none, this._current_music = "";
return res;
};
})();
var result = cacheF.apply(this, arguments);
return result;
};
})();
clearInterval(LobbyCheck);
}
},2000);
})();