-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
178 lines (165 loc) · 4.36 KB
/
main.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
var viewerList = [],
keyword = "keyword";
var options = {
options: {
debug: true
},
connection: {
reconnect: true,
},
identity: {
username: "yourTwitchUsername",
password: "oath2"
},
channels: ["#twitchChannel"]
};
var client = new tmi.client(options);
client.on("chat", function (channel, user, message, self) {
if ( message.toLowerCase() == keyword && !user.mod )
{
if ( $.inArray( user.username, viewerList ) <= -1 ){
viewerList.push(user.username);
}
else return;
}
else return;
});
client.connect().then(function() {
//client.action("#warframersb", "Giveaway roll starts soon! Be sure to type >> rsbgiveaway << in the chat!");
});
function removeA(arr) {
var what, a = arguments, L = a.length, ax;
while (L > 1 && arr.length) {
what = a[--L];
while ((ax= arr.indexOf(what)) !== -1) {
arr.splice(ax, 1);
}
}
return arr;
}
function hideAway() {
setTimeout(function () {
$(document.body).css('color', 'rgba(255, 176, 25, 0)');
$('#viewers').css("text-shadow", "0 0 rgba(0,0,0,0)").attr('data-content',"");
$('#prize').css("text-shadow", "0 0 rgba(0,0,0,0)").attr('data-content',"")
.delay(500)
.queue(function (next) {
$(".winnerBox").css('width', '0px');
$(".prizeBox").css('width', '0px');
next();
})
.delay(200)
.queue(function (next) {
$(".box").css('width', '0px');
next();
})
.delay(1000)
.queue(function (next) {
$(".icon").css("transform", "scale(0.0)")
//window.setTimeout('location.reload()', 3000);
next();
});
}, 10000)
}
function giveawayRoulete() {
var iW = 0,
iP = 0,
winner = "",
prize = "";
prizeData = new Array();
prizeList = new Array();
prizeArray = new Array();
//client.action("#warframersb", "Rolling now...");
$.ajax({
type: 'GET',
url: "data.json",
dataType: "json",
success: function( response ) {
prizeData = response;
prizeList = prizeData['prizes'].slice(0);
if(parseInt(prizeList[0]) >= 1000){
prizeList[0] = "1000 Platinum";
}else{
prizeList.splice(0,1);
}
}
});
$(".icon").css("transform", "scale(1.0)")
.delay(500)
.queue(function (next) {
$(".box").css('width', '500px');
next();
})
.delay(200)
.queue(function (next) {
$(".winnerBox").css('width', '480px');
next();
})
.delay(100)
.queue(function (next) {
$(".prizeBox").css('width', '480px');
next();
})
.delay(600)
.queue(function (next) {
$(document.body).css('color', 'rgba(255, 176, 25, 1)');
next();
pickWinner();
});
function pickWinner(){
var rollWinners = $(viewerList).not(prizeData['past_winners']).get();
setTimeout(function () {
randomNumber = Math.round( Math.random() * ( rollWinners.length - 1 ) );
winner = rollWinners[randomNumber];
$('#viewers').text(winner).attr('data-content',winner);
iW++;
if (iW < 50) {
pickWinner();
}else
{
//$('#click').get(0).play();
$('#viewers').css("text-shadow", "0 0 16px rgba(255, 176, 25, 1)");
iW = 0;
pickPrize();
}
}, 50 + Math.pow(600, iW/50))
}
function pickPrize() {
setTimeout(function () {
randomNumber = Math.round( Math.random() * ( prizeList.length - 1 ) );
prize = prizeList[randomNumber];
$('#prize').text(prize).attr('data-content',prize);
iP++;
if (iP < 50) {
pickPrize();
}
else
{
//$('#click').get(0).play();
$('#prize').css("text-shadow", "0 0 16px rgba(255, 176, 25, 1)");
if(prize == "1000 Platinum"){
prizeData['prizes'][0] = (parseInt(prizeData['prizes'][0]) - 1000).toString();
}
removeA(prizeData['prizes'], prize);
prizeData['past_winners'].push(winner);
$.ajax({
url: 'http://localhost/data',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(prizeData)
})
client.action("#warframersb", "Congratulations to @" + winner + " They have won: " + prize + "!");
hideAway();
}
}, 50 + Math.pow(600, iP/50))
}
}
function onDocumentReady () {
$(window).keypress(function (e) {
if (e.keyCode === 0 || e.keyCode === 32) {
e.preventDefault()
giveawayRoulete();
}
})
}
$(document).ready(function(){onDocumentReady();});