-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoWoot.js
115 lines (101 loc) · 2.98 KB
/
autoWoot.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
/* to use in bookmarks:
* javascript:$("<script />").attr('id', 'plug-auto-scripts').attr('src', 'https://raw.github.com/chall8908/DJ-RuB/master/autoWoot.js').appendTo("body");
*/
(function() {
if(window.autoWootLoaded) {
return;
}
var djButton = $("#button-dj-play"),
waitListButton = $('#button-dj-waitlist-join'),
fakeService = { onResult: $.noop, onFailure: $.noop }
me = API.getSelf(),
onWaitList = false,
onDeck = false,
waitListSize = API.getWaitList().length,
raveInt = 0,
avatars = [],
currentAvi = 0,
defaultAvi = me.avatarID;
// Override default API.waitListJoin method
var __waitListJoin = API.waitListJoin;
API.waitListJoin = function() {
if(djButton.is(":visible")) {
socket.execute("booth.join", fakeService);
onWaitList = false;
onDeck = true;
} else if(!onWaitList && !onDeck) {
__waitListJoin();
onWaitList = true;
onDeck = false;
}
}
function determineUsableAvatars() {
var totalPoints = me.curatorPoints + me.djPoints + me.listenerPoints + 1;
$.each(AvatarOverlay.getOriginalSet(), function(i, aviSet) {
if(aviSet.required <= totalPoints) {
avatars = avatars.concat(aviSet.avatars);
}
});
}
function wootSong(dj) {
if(dj.id != me.id){
socket.execute("room.cast", fakeService, true, Models.room.data.historyID, true);
}
}
function activateRaveMode() {
clearInterval(raveInt);
raveInt = setInterval(function() {
new UserChangeAvatarService(avatars[currentAvi]);
currentAvi++;
if(currentAvi >= avatars.length) {
currentAvi = 0;
}
}, 500);
}
function deactivateRaveMode() {
clearInterval(raveInt);
new UserChangeAvatarService(defaultAvi);
}
determineUsableAvatars();
wootSong(true);
API.addEventListener(API.DJ_ADVANCE, function(data) {
wootSong(data.dj);
});
API.addEventListener(API.DJ_UPDATE, function(djs) {
if(onDeck && !onWaitList) {
//maybe we left?
onDeck = false;
$.each(djs, function(i, dj) {
if(dj.id == me.id) {
onDeck = true;
return false;
}
});
}
API.waitListJoin();
});
API.addEventListener(API.WAIT_LIST_UPDATE, function(users) {
if(onWaitList && users.length < waitListSize && !onDeck) {
//Make sure we weren't just removed
waitListSize = users.length;
onWaitList = false;
$.each(users, function(i, user) {
if(user.id == me.id) {
onWaitList = true;
return false;
}
});
}
API.waitListJoin();
});
API.addEventListener(API.CHAT, function(data) {
if(data.fromID == "50ef4f8b3e083e2a4bc1310c") {
if(data.message == "Assuming direct control.") {
activateRaveMode();
} else if(data.message == "Rescinding lockdown.") {
deactivateRaveMode();
}
}
});
window.autoWootLoaded = true;
})();