-
Notifications
You must be signed in to change notification settings - Fork 20
/
amqSongDifficultyCounter.user.js
1008 lines (928 loc) · 37.4 KB
/
amqSongDifficultyCounter.user.js
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
// ==UserScript==
// @name AMQ Song Difficulty Counter
// @namespace https://github.com/TheJoseph98
// @version 1.5
// @description Counts the songs by individual difficulty, per song type
// @author TheJoseph98
// @grant GM_xmlhttpRequest
// @connect script.google.com
// @connect script.googleusercontent.com
// @match https://animemusicquiz.com/*
// @require https://github.com/joske2865/AMQ-Scripts/raw/master/common/amqScriptInfo.js
// @downloadURL https://github.com/joske2865/AMQ-Scripts/raw/master/amqSongDifficultyCounter.user.js
// @updateURL https://github.com/joske2865/AMQ-Scripts/raw/master/amqSongDifficultyCounter.user.js
// ==/UserScript==
// Wait until the LOADING... screen is hidden and load script
if (typeof Listener === "undefined") return;
let loadInterval = setInterval(() => {
if ($("#loadingScreen").hasClass("hidden")) {
clearInterval(loadInterval);
setup();
}
}, 500);
const version = "1.5";
let counting = false; // counting currently active
let countingAdvanced = false; // counting currently active by years
let autoCountAdvanced = false; // auto counting by years for 100+ songs active
// object containing counted songs, this gets sent to the spreadsheet
let count = {
username: null,
openings: {},
endings: {},
inserts: {}
};
let sendToSpreadsheet = false; // enable sending to spreadsheet
// difficulty ranges and types
let typeRanges = []; // difficulty ranges for each type (openings, endings and inserts) (eg. [[10, 50], [50, 80], [53, 89]])
let curDiffRange = [0, 1]; // current selected difficulty
let curType = 0; // current selected type, index of types array
let types = []; // types ("opening", "ending" and "insert")
let minYear = 1944;
let maxYear = 2022;
let yearRanges = []; // year ranges array for counting by years
let yearIndex = 0; // current index of the year ranges array
let curYearRange = [minYear, maxYear]; // default year range
// difficulty sliders
let openingsDiffSlider;
let endingsDiffSlider;
let insertsDiffSlider;
// old listeners
let oldSettingsChangeListener;
let oldQuizNoSongsListener;
let oldQuizOverListener;
// new listeners
let quizReadyListener;
let playNextSongListener;
let quizNoSongsListener;
let quizOverListener;
let settingsChangeListener;
let hostGameListener;
let joinGameListener;
let spectateGameListener;
let buttonHidden = false;
function createSongCounterModal() {
let buttonHTML = $(`
<div class="clickAble topMenuButton topMenuMediumButton" id="lbCounterButton">
<h3>Counter</h3>
</div>`);
let counterModalHTML = $(`
<div class="modal fade tab-modal" id="songCounterModal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<h2 class="modal-title">Song Counter</h2>
</div>
<div class="modal-body" style="overflow-y: auto;max-height: calc(100vh - 150px);">
<div id="scDifficultySliderContainer">
<div class="scTypeContainer">
<div class="scTypeCheckboxContainer">
<div class="customCheckbox">
<input id="scTypeOpenings" type="checkbox" checked="">
<label for="scTypeOpenings"><i class="fa fa-check" aria-hidden="true"></i></label>
</div>
<span>Openings</span>
</div>
<div class="scTypeDifficultySlider">
<input id="scOpeningsDiffMin" type="text" value="1" class="minWell text-center mhRangeSliderTextBox">
<input class="sliderInput" id="scOpeningsDiffRange" data-slider-class="scDifficultySlider" data-slider-id="scOpeningsDifficultySlider" type="text" style="display: none;" data-value="1" value="1">
<input id="scOpeningsDiffMax" type="text" value="100" class="minWell text-center mhRangeSliderTextBox">
</div>
</div>
<div class="scTypeContainer">
<div class="scTypeCheckboxContainer">
<div class="customCheckbox">
<input id="scTypeEndings" type="checkbox" checked="">
<label for="scTypeEndings"><i class="fa fa-check" aria-hidden="true"></i></label>
</div>
<span>Endings</span>
</div>
<div class="scTypeDifficultySlider">
<input id="scEndingsDiffMin" type="text" value="1" class="minWell text-center mhRangeSliderTextBox">
<input class="sliderInput" id="scEndingsDiffRange" data-slider-class="scDifficultySlider" data-slider-id="scEndingsDifficultySlider" type="text" style="display: none;" data-value="1" value="1">
<input id="scEndingsDiffMax" type="text" value="100" class="minWell text-center mhRangeSliderTextBox">
</div>
</div>
<div class="scTypeContainer">
<div class="scTypeCheckboxContainer">
<div class="customCheckbox">
<input id="scTypeInserts" type="checkbox" checked="">
<label for="scTypeInserts"><i class="fa fa-check" aria-hidden="true"></i></label>
</div>
<span>Inserts</span>
</div>
<div class="scTypeDifficultySlider">
<input id="scInsertsDiffMin" type="text" value="1" class="minWell text-center mhRangeSliderTextBox">
<input class="sliderInput" id="scInsertsDiffRange" data-slider-class="scDifficultySlider" data-slider-id="scInsertsDifficultySlider" type="text" style="display: none;" data-value="1" value="1">
<input id="scInsertsDiffMax" type="text" value="100" class="minWell text-center mhRangeSliderTextBox">
</div>
</div>
</div>
<div id="scExtraOptionsContainer">
<div id="scSpreadsheetContainer">
<div class="customCheckbox">
<input id="scSendToSpreadsheet" type="checkbox" checked="">
<label for="scSendToSpreadsheet"><i class="fa fa-check" aria-hidden="true"></i></label>
</div>
<span id="scSpreadsheetLabel">Send to spreadsheet</span>
</div>
<div id="scUsernameContainer" class="disabled">
<span>Username (required)</span>
<input id="scUsername" type="text" style="width: 100%;">
</div>
<select id="scWatchingType">
<option value="watched">Only Watched</option>
<option value="random">Random</option>
</select>
<div id="scAdvancedCountContainer">
<div class="customCheckbox">
<input type="checkbox" checked="" id="scAdvancedCount">
<label for="scAdvancedCount"><i class="fa fa-check" aria-hidden="true"></i></label>
</div>
<span id="scAdvancedCountLabel">Advanced counting</span>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" id="scCountinueCounter">Continue</button>
<a target="_blank" href="https://docs.google.com/spreadsheets/d/1mvwE_7CPN0jV5C76vHVX67ijo4VfhgIkkSxc5LOJLJE/edit?usp=sharing" id="scSpreadsheetLink">Spreadsheet</a>
<button type="button" class="btn btn-default" data-dismiss="modal">Exit</button>
<button type="button" class="btn btn-primary" id="scStartCounter">Start</button>
</div>
</div>
</div>
</div>
`);
// create button
$("#lobbyPage .menuBar").append(buttonHTML);
$("#lbCounterButton").click(function () {
openCounterModal();
});
// create window and sliders
$("#gameContainer").append(counterModalHTML);
openingsDiffSlider = new SliderTextCombo($("#scOpeningsDiffRange"), [$("#scOpeningsDiffMin"), $("#scOpeningsDiffMax")],
{
min: 1,
max: 100,
value: [1, 100],
range: true,
tooltip: "hide"
});
endingsDiffSlider = new SliderTextCombo($("#scEndingsDiffRange"), [$("#scEndingsDiffMin"), $("#scEndingsDiffMax")],
{
min: 1,
max: 100,
value: [1, 100],
range: true,
tooltip: "hide"
});
insertsDiffSlider = new SliderTextCombo($("#scInsertsDiffRange"), [$("#scInsertsDiffMin"), $("#scInsertsDiffMax")],
{
min: 1,
max: 100,
value: [1, 100],
range: true,
tooltip: "hide"
});
// enable/disable sliders
$("#scTypeOpenings").click(function () {
if ($(this).prop("checked")) {
$(this).parent().parent().next().removeClass("disabled");
}
else {
$(this).parent().parent().next().addClass("disabled")
}
});
$("#scTypeEndings").click(function () {
if ($(this).prop("checked")) {
$(this).parent().parent().next().removeClass("disabled");
}
else {
$(this).parent().parent().next().addClass("disabled")
}
});
$("#scTypeInserts").click(function () {
if ($(this).prop("checked")) {
$(this).parent().parent().next().removeClass("disabled");
}
else {
$(this).parent().parent().next().addClass("disabled")
}
});
// popovers
$("#scSpreadsheetLabel").popover({
content: "Send data to a public spreadsheet",
trigger: "hover",
placement: "top",
container: "body"
});
$("#scAdvancedCountLabel").popover({
content: "Automatically splits difficulty by years if it finds more than 100 songs",
trigger: "hover",
placement: "top",
container: "body"
});
// enable/disable username input and sync between tabs
$("#scSendToSpreadsheet").click(function () {
if ($(this).prop("checked")) {
$("#scUsernameContainer").removeClass("disabled");
sendToSpreadsheet = true;
}
else {
$("#scUsernameContainer").addClass("disabled");
sendToSpreadsheet = false;
}
});
// start counter
$("#scStartCounter").click(function () {
if ($("#scSendToSpreadsheet").prop("checked")) {
if ($("#scUsername").val().trim() === "") {
displayMessage("Error", "You must enter a username to send data to the spreadsheet");
return;
}
else {
clearCountData();
count.username = $("#scUsername").val().trim();
}
}
else {
clearCountData();
}
initializeRanges();
$("#songCounterModal").modal("hide");
startCounting(curDiffRange, curType);
});
// continue counter
$("#scCountinueCounter").click(function () {
if (!loadCounterData()) {
displayMessage("Continue", "No saved data found");
}
else {
let message = `Saved data found<br /><br />`;
if (sendToSpreadsheet) {
message += `Send to spreadsheet: Enabled<br />Username: ${count.username}<br />`;
}
else {
message += `Send to spreadsheet: Disabled<br />`;
}
message += `Advanced counting: ${autoCountAdvanced ? "Enabled" : "Disabled"}<br />`;
message += `Song Selection: ${$("#scWatchingType").val() === "watched" ? "Only Watched" : "Random"}<br /><br />`;
message += `Current Difficulty range: ${curDiffRange[0]}-${curDiffRange[1]}%<br />`;
message += `Current Type: ${types[curType] === "opening" ? "Openings" : types[curType] === "ending" ? "Endings" : "Inserts"}<br /><br />`;
message += `Selected types:<br />`;
for (let i = 0; i < types.length; i++) {
if (types[i] === "opening") {
message += `Openings: ${typeRanges[i][0]}-${typeRanges[i][1]}%<br />`;
}
if (types[i] === "ending") {
message += `Endings: ${typeRanges[i][0]}-${typeRanges[i][1]}%<br />`;
}
if (types[i] === "insert") {
message += `Inserts: ${typeRanges[i][0]}-${typeRanges[i][1]}%<br />`;
}
}
message += `<br />Would you like to continue?`;
displayHtmlOption("Continue", message, "Yes", "No", () => {
startCounting(curDiffRange, curType);
$("#songCounterModal").modal("hide");
}, () => {});
}
});
// default auto count by years unchecked
$("#scAdvancedCount").prop("checked", false);
// change auto count by years on click
$("#scAdvancedCount").click(function () {
autoCountAdvanced = $(this).prop("checked");
});
// default send to spreadsheet unchecked
$("#scSendToSpreadsheet").prop("checked", false);
}
// initialize difficulty ranges per type
function initializeRanges() {
typeRanges = [];
types = [];
if ($("#scTypeOpenings").prop("checked")) {
types.push("opening");
typeRanges.push(openingsDiffSlider.getValue());
}
if ($("#scTypeEndings").prop("checked")) {
types.push("ending");
typeRanges.push(endingsDiffSlider.getValue());
}
if ($("#scTypeInserts").prop("checked")) {
types.push("insert");
typeRanges.push(insertsDiffSlider.getValue());
}
if (typeRanges.length === 0) {
displayMessage("Error", "Must select at least one song type");
return;
}
curDiffRange[0] = typeRanges[0][0] - 1;
curDiffRange[1] = typeRanges[0][0];
curType = 0;
}
function showCounterButton() {
$("#lbCounterButton").show();
if (buttonHidden) {
let oldWidth = $("#qpOptionContainer").width();
$("#qpOptionContainer").width(oldWidth + 35);
$("#qpStopCounter").show();
buttonHidden = false;
}
}
function hideCounterButton() {
$("#lbCounterButton").hide();
if (!buttonHidden) {
let oldWidth = $("#qpOptionContainer").width();
$("#qpOptionContainer").width(oldWidth - 35);
$("#qpStopCounter").hide();
buttonHidden = true;
}
}
// open the counter modal window
function openCounterModal() {
if (!lobby.soloMode) {
displayMessage("Error", "Must be in solo mode");
}
else {
$("#songCounterModal").modal("show");
}
}
// add an amount of songs to a difficulty
function addSongCounter(diffRange, type, amount) {
if (countingAdvanced) {
if (type === "opening") {
count.openings[diffRange[1]] = !count.openings[diffRange[1]] ? amount : count.openings[diffRange[1]] + amount;
gameChat.systemMessage(`Openings in ${diffRange[0]}-${diffRange[1]}% in ${curYearRange[0]}-${curYearRange[1]}: ${amount}`);
}
if (type === "ending") {
count.endings[diffRange[1]] = !count.endings[diffRange[1]] ? amount : count.endings[diffRange[1]] + amount;
gameChat.systemMessage(`Endings in ${diffRange[0]}-${diffRange[1]}% in ${curYearRange[0]}-${curYearRange[1]}: ${amount}`);
}
if (type === "insert") {
count.inserts[diffRange[1]] = !count.inserts[diffRange[1]] ? amount : count.inserts[diffRange[1]] + amount;
gameChat.systemMessage(`Inserts in ${diffRange[0]}-${diffRange[1]}% in ${curYearRange[0]}-${curYearRange[1]}: ${amount}`);
}
}
else {
if (type === "opening") {
count.openings[diffRange[1]] = amount;
gameChat.systemMessage(`Openings in ${diffRange[0]}-${diffRange[1]}%: ${amount}`);
}
if (type === "ending") {
count.endings[diffRange[1]] = amount;
gameChat.systemMessage(`Endings in ${diffRange[0]}-${diffRange[1]}%: ${amount}`);
}
if (type === "insert") {
count.inserts[diffRange[1]] = amount;
gameChat.systemMessage(`Inserts in ${diffRange[0]}-${diffRange[1]}%: ${amount}`);
}
}
}
// display total number of songs per difficulty per type (used for counting by years when there's more than 100 songs)
function displayTotal(diffRange, type) {
if (type === "opening") {
gameChat.systemMessage(`Total Openings in ${diffRange[0]}-${diffRange[1]}%: ${count.openings[diffRange[1]]}`);
}
if (type === "ending") {
gameChat.systemMessage(`Total Endings in ${diffRange[0]}-${diffRange[1]}%: ${count.endings[diffRange[1]]}`);
}
if (type === "insert") {
gameChat.systemMessage(`Total Inserts in ${diffRange[0]}-${diffRange[1]}%: ${count.inserts[diffRange[1]]}`);
}
}
// set new difficulty
function setDifficulty(diffRange) {
hostModal.songDiffRangeSliderCombo.setValue(diffRange);
}
// set new song type
function setSongType(type) {
let openings = hostModal.$songTypeOpening;
let endings = hostModal.$songTypeEnding;
let inserts = hostModal.$songTypeInsert;
if (type === "opening") {
if (!openings.is(":checked")) {
openings.click();
}
if (endings.is(":checked")) {
endings.click();
}
if (inserts.is(":checked")) {
inserts.click();
}
}
if (type === "ending") {
if (!endings.is(":checked")) {
endings.click();
}
if (openings.is(":checked")) {
openings.click();
}
if (inserts.is(":checked")) {
inserts.click();
}
}
if (type === "insert") {
if (!inserts.is(":checked")) {
inserts.click();
}
if (openings.is(":checked")) {
openings.click();
}
if (endings.is(":checked")) {
endings.click();
}
}
}
// set year setting
function setYears(yearRange) {
hostModal.vintageRangeSliderCombo.setValue(yearRange);
}
// start the game from lobby
function startGame() {
if (counting) {
if ($("#lbStartButton").is(":visible")) {
$("#lbStartButton").click();
}
}
}
// start counting songs
function startCounting(startDiffRange, startType) {
if (lobby.soloMode && lobby.inLobby) {
resetYears();
counting = true;
// unbind and remove old listeners (that spam the chat with "no songs found" and "game settings have been changed")
lobby._settingListener.unbindListener();
quiz._noSongsListner.unbindListener();
quiz._quizOverListner.unbindListener();
lobby._settingListener = new Listener("Room Settings Changed", payload => {});
quiz._noSongsListner = new Listener("Quiz no songs", payload => {});
quiz._quizOverListner = new Listener("quiz over", payload => {});
quizReadyListener.bindListener();
playNextSongListener.bindListener();
quizNoSongsListener.bindListener();
quizOverListener.bindListener();
settingsChangeListener.bindListener();
// set difficulty range
curDiffRange = startDiffRange;
curType = startType;
setSettings(); // set default lobby settings
setDifficulty(curDiffRange);
setSongType(types[curType]);
setYears(curYearRange);
lobby.changeGameSettings();
}
else {
displayMessage("Error", "You are not in a lobby");
}
}
// stop counting songs
function stopCounting() {
quizReadyListener.unbindListener();
playNextSongListener.unbindListener();
quizNoSongsListener.unbindListener();
quizOverListener.unbindListener();
settingsChangeListener.unbindListener();
// set old listeners back
lobby._settingListener = oldSettingsChangeListener;
quiz._noSongsListner = oldQuizNoSongsListener;
quiz._quizOverListner = oldQuizOverListener;
lobby._settingListener.bindListener();
quiz._noSongsListner.bindListener();
quiz._quizOverListner.bindListener();
counting = false;
gameChat.systemMessage("Counter stopped");
sendDataToSpreadsheet();
console.log(count);
clearCountData();
}
// reset counting data
function clearCountData() {
count = {
username: null,
openings: {},
endings: {},
inserts: {}
};
localStorage.removeItem("countData");
}
// set default game settings
function setSettings() {
hostModal.numberOfSongsSliderCombo.setValue(100); // set 100 songs
hostModal.songDiffAdvancedSwitch.setOn(true); // set advanced difficulty sliders on
hostModal.playLengthSliderCombo.setValue(5); // set 5 seconds guess time
if ($("#scWatchingType").val() === "watched") {
hostModal.watchedSliderCombo.setValue(100);
hostModal.unwatchedSliderCombo.setValue(0)
hostModal.randomWatchedSliderCombo.setValue(0);
}
else {
hostModal.watchedSliderCombo.setValue(0);
hostModal.unwatchedSliderCombo.setValue(0)
hostModal.randomWatchedSliderCombo.setValue(100);
}
// enable auto skip during replay
options.$AUTO_VOTE_REPLAY.prop("checked", true)
options.updateAutoVoteSkipReplay();
}
// increment difficulty
function updateSongDifficulty() {
// reset year ranges and yearIndex, if it reaches this point, counting by years has finished and can safely reset
resetYears();
curDiffRange[0]++;
curDiffRange[1]++;
// check if new difficulty is out of range, if it is, increment type by 1
if (curDiffRange[1] > typeRanges[curType][1]) {
curType++;
// check if new type is out of range, if it is, the counter has reached the end and can stop
if (curType >= types.length) {
stopCounting();
return;
}
// otherwise, set the new difficulty to be the beginning of the new range for the next type
else {
curDiffRange[0] = typeRanges[curType][0] - 1;
curDiffRange[1] = typeRanges[curType][0];
}
}
setDifficulty(curDiffRange);
setSongType(types[curType]);
setYears(curYearRange);
lobby.changeGameSettings();
}
function updateYearRange() {
curYearRange = yearRanges[yearIndex];
// check that yearIndex is out of range and returns undefined, if it doesn't, set the years settings to the new range
if (curYearRange !== undefined) {
setYears(curYearRange);
lobby.changeGameSettings();
}
// if yearIndex is out of range, then counting by years has concluded
else {
displayTotal(curDiffRange, types[curType]); // display total number of songs in the difficulty
updateSongDifficulty();
}
}
function splitYears() {
// divide into 5 on the initial 1944, 2022 split
if (curYearRange[0] === minYear && curYearRange[1] === maxYear) {
let splits = [1995, 2005, 2010, 2015];
for (let i = 0; i < splits.length; i++) {
if (i === 0) {
yearRanges.splice(yearIndex, 1, [curYearRange[0], splits[i]]);
}
if (i < splits.length - 1) {
yearRanges.splice(yearIndex + i + 1, 0, [splits[i] + 1, splits[i+1]]);
}
if (i === splits.length - 1) {
yearRanges.splice(yearIndex + i + 1, 0, [splits[i] + 1, curYearRange[1]])
}
}
}
// else, divide into halves
else {
let average = Math.floor((curYearRange[0] + curYearRange[1])/2);
yearRanges.splice(yearIndex, 1, [curYearRange[0], average]);
yearRanges.splice(yearIndex + 1, 0, [average + 1, curYearRange[1]]);
}
}
// reset year ranges and yearIndex
function resetYears() {
yearRanges = [[minYear, maxYear]];
yearIndex = 0;
curYearRange = [minYear, maxYear];
countingAdvanced = false;
}
// save data to the localStorage
function saveCounterData() {
let saveData = {
countData: count,
diffRangeData: curDiffRange,
typeData: curType,
typesData: types,
typeRangesData: typeRanges,
autoCountAdvancedEnabled: autoCountAdvanced,
sendToSpreadsheetData: sendToSpreadsheet,
watchingTypeData: $("#scWatchingType").val()
};
localStorage.setItem("countData", JSON.stringify(saveData));
}
// load data from localStorage
function loadCounterData() {
let loadData = JSON.parse(localStorage.getItem("countData"));
if (loadData !== null) {
count = loadData.countData;
curDiffRange = loadData.diffRangeData;
curType = loadData.typeData;
types = loadData.typesData;
typeRanges = loadData.typeRangesData;
autoCountAdvanced = loadData.autoCountAdvancedEnabled;
sendToSpreadsheet = loadData.sendToSpreadsheetData;
$("#scWatchingType").val(loadData.watchingTypeData);
return true;
}
return false;
}
// send data to a public spreadsheet
function sendDataToSpreadsheet() {
if (sendToSpreadsheet) {
gameChat.systemMessage("Sending data to spreadsheet, might take a while if sending to a new list for the first time");
GM_xmlhttpRequest({
method: "POST",
url: "https://script.google.com/macros/s/AKfycbxOTigCeni8hyoUk5o1G5VrjVDnWcVkb0hrWYzDxe2oj9BztIo/exec",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
},
data: "data=" + encodeURIComponent(JSON.stringify(count)),
onload: function (response) {
gameChat.systemMessage("Successfully sent data to the spreadsheet");
gameChat.systemMessage("Done!");
},
onerror: function (response) {
gameChat.systemMessage("Error sending data to the spreadsheet");
gameChat.systemMessage("Done!");
}
});
}
else {
gameChat.systemMessage("Skipped sending data to spreadsheet");
gameChat.systemMessage("Done!");
}
}
// modified displayOption to support HTML
function displayHtmlOption(title, msg, acceptMsg, declineMsg, callback, callbackCancel) {
if (!callback) {
callback = () => {};
}
if (!callbackCancel) {
callbackCancel = () => {};
}
if (SWAL_ACTIVE) {
return swal({
title: title,
html: msg,
showCancelButton: true,
confirmButtonColor: "#204d74",
confirmButtonText: acceptMsg,
cancelButtonText: declineMsg,
}).then((result) => {
if (result.dismiss) {
callbackCancel();
} else {
callback(result.value);
}
});
}
}
function setup() {
// listen for if the quiz returns no songs
quizNoSongsListener = new Listener("Quiz no songs", payload => {
// check if counting years flag is active and increment yearIndex by 1
if (countingAdvanced) {
yearIndex += 1;
}
else {
// set that song difficulty to 0 songs
addSongCounter(curDiffRange, types[curType], 0);
}
saveCounterData();
});
// listen for if the quiz starts normally
quizReadyListener = new Listener("quiz ready", payload => {
// check if the user has advanced counting enabled
if (countingAdvanced) {
// first, check if there are less than 100 songs (there are more than 0 guaranteed if "quiz ready" listener fires) and increment yearIndex by 1;
if (payload.numberOfSongs < 100) {
yearIndex += 1;
addSongCounter(curDiffRange, types[curType], payload.numberOfSongs);
}
// else, check if there are 100 songs and check that the year range can be split into halves then split years into halves
else if (payload.numberOfSongs === 100 && curYearRange[0] !== curYearRange[1]) {
gameChat.systemMessage(`100 songs found in ${curYearRange[0]}-${curYearRange[1]} in ${curDiffRange[0]}-${curDiffRange[1]}%, splitting years`);
splitYears();
}
// else, check if the year range is 1 year, then increment yearIndex by 1
else {
yearIndex += 1;
addSongCounter(currDiffRane, types[curType], payload.numberOfSongs);
}
}
else {
// if the user has "Advanced counting" option enabled and there are 100 songs, split the years and count again
if (payload.numberOfSongs === 100 && autoCountAdvanced) {
resetYears();
splitYears();
countingAdvanced = true;
gameChat.systemMessage(`100 songs found in ${curYearRange[0]}-${curYearRange[1]} in ${curDiffRange[0]}-${curDiffRange[1]}%, splitting years`);
}
// else just add the number of songs to that difficulty range
else {
addSongCounter(curDiffRange, types[curType], payload.numberOfSongs);
}
}
// return to lobby vote
socket.sendCommand({
type: "quiz",
command: "start return lobby vote",
});
saveCounterData();
});
// skip song when playing next song
playNextSongListener = new Listener("play next song", payload => {
// 500 ms delay because race conditions
setTimeout(function () {
quiz.skipClicked();
}, 500);
});
// listen for when the quiz ends
quizOverListener = new Listener("quiz over", payload => {
lobby.setupLobby(payload, quiz.isSpectator);
viewChanger.changeView("lobby", {
supressServerMsg: true,
keepChatOpen: true
});
if (lobby.inLobby && lobby.soloMode) {
// if advanced counting is active, increment the year
if (countingAdvanced) {
updateYearRange();
}
// otherwise, increment difficulty
else {
updateSongDifficulty();
}
}
else {
displayMessage("Error", "You must be in a solo lobby");
stopCounting();
}
});
// listen for when room settings change
settingsChangeListener = new Listener("Room Settings Changed", payload => {
console.log(payload);
hostModal.changeSettings(payload);
Object.keys(payload).forEach(key => {
let newValue = payload[key];
let oldValue = lobby.settings[key];
lobby.settings[key] = newValue;
});
if (payload.roomSize) {
lobby.settings.roomSize = payload.roomSize;
}
Object.values(lobby.players).forEach(player => {
player.ready = true;
});
lobby.isReady = true;
lobby.toggleRuleButton();
lobby.updateMainButton();
if (payload.roomName) {
lobby.$roomName.text(payload.roomName);
}
lobby.updatePlayerCounter();
startGame();
});
// show the counter button when hosting a solo game, otherwise hide it
hostGameListener = new Listener("Host Game", payload => {
if (payload.soloMode) {
showCounterButton();
}
else {
hideCounterButton();
}
});
// hide the counter button when joining non-solo lobbies
joinGameListener = new Listener("Join Game", payload => {
hideCounterButton();
});
// hide the counter button when spectating non-solo lobbies
spectateGameListener = new Listener("Spectate Game", payload => {
hideCounterButton();
});
// set old listeners
oldQuizOverListener = quiz._quizOverListner;
oldSettingsChangeListener = lobby._settingListener;
oldQuizNoSongsListener = quiz._noSongsListner;
createSongCounterModal();
// stop counting button
let oldWidth = $("#qpOptionContainer").width();
$("#qpOptionContainer").width(oldWidth + 35);
$("#qpOptionContainer > div").append($("<div></div>")
.attr("id", "qpStopCounter")
.attr("class", "clickAble qpOption")
.html(`<i aria-hidden="true" class="fa fa-ban qpMenuItem"></i>`)
.click(() => {
if (counting) {
stopCounting();
}
})
.popover({
content: "Stop Counting",
trigger: "hover",
placement: "bottom"
})
);
AMQ_addStyle(`
#lbCounterButton {
width: 100px;
right: 30%;
}
#qpStopCounter {
width: 30px;
height: auto;
margin-right: 5px;
}
#songCounterModal .modal-dialog {
width: 650px;
}
#songCounterModal .modal-body {
padding: 0px;
}
#scDifficultySliderContainer {
width: 430px;
height: 180px;
border-right: 1px solid #6d6d6d;
padding: 15px;
float: left;
}
.scTypeContainer {
height: 45px;
width: 400px;
}
.scTypeCheckboxContainer {
float: left;
display: table;
}
.scTypeCheckboxContainer span {
vertical-align: top;
}
.scTypeDifficultySlider {
width: 300px;
float: right;
}
.scTypeDifficultySlider .slider {
width: 200px !important;
}
#scExtraOptionsContainer {
width: 215px;
height: 180px;
padding: 15px;
float: left;
}
#scSpreadsheetContainer {
display: table;
}
#scAdvancedCountContainer {
margin-top: 15px;
display: table;
}
#scAdvancedCountLabel {
vertical-align: top;
}
#scSpreadsheetContainer span {
vertical-align: top;
}
#scUsernameContainer {
margin-top: 10px;
}
#scUsername {
width: 100%;
border-radius: 4px;
color: black;
}
#scWatchingType {
color: black;
border-radius: 4px;
width: 100%;
margin-top: 15px;
}
#scCountinueCounter {
float: left;
}
#scSpreadsheetLink {
float: left;
margin-top: 5px;
margin-left: 15px;
}
`)
AMQ_addScriptData({
name: "Song Difficulty Counter",
author: "TheJoseph98",
version: version,
link: "https://github.com/joske2865/AMQ-Scripts/raw/master/amqSongDifficultyCounter.user.js",
description: `
<p>Adds a counting tool that automatically counts the number of songs on each difficulty</p>
<p>Can be customized to count only certain difficulty ranges and certain song types and has an option to automatically split by years if you get 100 songs or more to get a more accurate result</p>
<p>With a provided username, you can share your song breakdown by difficulty to a
<a target="_blank" href="https://docs.google.com/spreadsheets/d/1mvwE_7CPN0jV5C76vHVX67ijo4VfhgIkkSxc5LOJLJE/edit?usp=sharing">public Spreadsheet</a>.
The tool will automatically create a data sheet and a graph sheet with all of the data you collect and add it to the Index page</p>
<p>You can update your data by inputting the same username as it is on the spreadsheet (NOTE: username is case-sensitive. For example "thejoseph98" and "THEJOSEPH98" are NOT the same)</p>
<p>To use the tool, simply click "Counter" button while in lobby, next to the "Room settings" button. You must be in a solo lobby to use this tool. Usage of guest accounts is strongly recommended to not inflate your Songs Played and guess rate due to the nature of this tool.
Simply select your preferred settings and click "Start", the tool will automatically set all other settings for you (100 songs, 5 seconds guess time, only watched/random depending on your tool settings and more)</p>