forked from joske2865/AMQ-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amqSongList.user.js
150 lines (135 loc) · 5.38 KB
/
amqSongList.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
// ==UserScript==
// @name AMQ Song List
// @namespace https://github.com/TheJoseph98
// @version 1.3.1
// @description Prints a copyable list to console at the end of each game
// @author TheJoseph98
// @match https://animemusicquiz.com/*
// @grant none
// @require https://raw.githubusercontent.com/TheJoseph98/AMQ-Scripts/master/common/amqScriptInfo.js
// @updateURL https://github.com/TheJoseph98/AMQ-Scripts/raw/master/amqSongList.user.js
// ==/UserScript==
// don't load on login page
if (document.getElementById("startPage")) return;
// Wait until the LOADING... screen is hidden and load script
let loadInterval = setInterval(() => {
if (document.getElementById("loadingScreen").classList.contains("hidden")) {
setup();
clearInterval(loadInterval);
}
}, 500);
let songs = [];
let videoHosts = ["catbox", "openingsmoe"];
let mp3Hosts = ["catbox"];
let videoResolutions = [720, 480];
function getVideoURL(URLMap) {
for (let host of videoHosts) {
if (URLMap[host] !== undefined) {
for (let resolution of videoResolutions) {
if (URLMap[host][resolution] !== undefined) {
return URLMap[host][resolution];
}
}
}
}
return null;
}
function getMP3URL(URLMap) {
for (let host of mp3Hosts) {
if (URLMap[host] !== undefined) {
if (URLMap[host][0] !== undefined) {
return URLMap[host][0];
}
}
}
return null;
}
function setup() {
let oldWidth = $("#qpOptionContainer").width();
$("#qpOptionContainer").width(oldWidth + 35);
$("#qpOptionContainer > div").append($("<div></div>")
.attr("id", "qpCopyJSON")
.attr("class", "clickAble qpOption")
.html("<i aria-hidden=\"true\" class=\"fa fa-clipboard qpMenuItem\"></i>")
.click(() => {
$("#copyBox").val(JSON.stringify(songs, null, 4)).select();
document.execCommand("copy");
$("#copyBox").val("").blur();
})
.popover({
content: "Copy JSON to Clipboard",
trigger: "hover",
placement: "bottom"
})
);
// clear list on quiz ready
let quizReadyListener = new Listener("quiz ready", data => {
songs = [];
});
let resultListener = new Listener("answer results", result => {
let newSong = {
songNumber: parseInt($("#qpCurrentSongCount").text()),
animeEnglish: result.songInfo.animeNames.english,
animeRomaji: result.songInfo.animeNames.romaji,
annId: result.songInfo.annId,
songName: result.songInfo.songName,
artist: result.songInfo.artist,
type: result.songInfo.type === 3 ? "Insert Song" : (result.songInfo.type === 2 ? "Ending " + result.songInfo.typeNumber : "Opening " + result.songInfo.typeNumber),
correctCount: result.players.filter(player => player.correct === true).length,
activePlayers: Object.values(quiz.players).filter(player => player.avatarSlot._disabled === false).length,
startSample: quizVideoController.moePlayers[quizVideoController.currentMoePlayerId].startPoint,
videoLength: parseFloat(quizVideoController.moePlayers[quizVideoController.currentMoePlayerId].$player.find("video")[0].duration.toFixed(2)),
linkWebm: getVideoURL(result.songInfo.urlMap),
linkMP3: getMP3URL(result.songInfo.urlMap)
};
//console.log(newSong);
songs.push(newSong);
});
// print list to console on quiz end
let quizEndListener = new Listener("quiz end result", result => {
console.log(songs);
});
// clear list on quiz over (returning to lobby)
let quizOverListener = new Listener("quiz over", roomSettings => {
songs = [];
});
// clear list on joining lobby
let quizJoinListener = new Listener("Join Game", payload => {
if (!payload.error) {
songs = [];
}
});
// clear list on spectating lobby
let quizSpectateListener = new Listener("Spectate Game", payload => {
if (!payload.error) {
songs = [];
}
});
resultListener.bindListener();
quizEndListener.bindListener();
quizReadyListener.bindListener();
quizOverListener.bindListener();
quizJoinListener.bindListener();
quizSpectateListener.bindListener();
AMQ_addScriptData({
name: "Song List",
author: "TheJoseph98",
description: `
<p>Tracks the songs that played during the round and outputs them to your browser's console including song name, artist, anime, number of players, video URLs and more</p>
<p>Currently stored data can be copied to clipboard by clicking the clipboard icon in the top right while in a quiz</p>
<a href="https://i.imgur.com/yGjMle9.png" target="_blank"><img src="https://i.imgur.com/yGjMle9.png" /></a>
<p>An example output can be found <a href="https://pastebin.com/1gS9n4xa" target="_blank">here</a></p>
<p>The list resets when the quiz ends (returning to back to lobby), when the quiz starts or when you leave the lobby</p>
`
})
AMQ_addStyle(`
#qpCopyJSON {
width: 30px;
height: auto;
margin-right: 5px;
}
#qpOptionContainer {
z-index: 10;
}
`);
}