-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
659 lines (554 loc) · 20.4 KB
/
index.html
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
<html>
<head>
<title>BRB - Button</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.16.1/TweenMax.min.js"></script>
<script src="/scripts/tmi.min.js"></script>
<script src="/scripts/snackbar.js"></script>
<link rel="stylesheet" href="style/snackbar.css" />
<style>
html {
height: 100%;
}
body {
min-height: 100%;
margin: 0;
display: flex;
justify-content: center;
align-items: center;
background-color: #24282f;
}
canvas {
position: absolute;
pointer-events: none;
z-index: 1;
top: 0;
left: 0;
}
#canvas-number {
width: 680px;
height: 420px;
}
/* Button */
button {
position: relative;
z-index: 3;
border-radius: 50%;
width: 300px;
height: 300px;
border: none;
color: white;
font-family: Avenir, Arial, sans-serif;
font-weight: 900;
font-size: 3.5rem;
background: rgba(255, 0, 0, 1);
text-shadow: 0 5px 1px rgba(122, 17, 8, .8);
box-shadow: 0 8px 0 rgb(183, 9, 0),
0 15px 20px rgba(0, 0, 0, .35);
text-transform: uppercase;
transition: .4s all ease-in;
outline: none;
cursor: pointer;
text-align: center;
}
button span {
position: relative;
}
/* fix for IE 11 (and IE8+, although the earlier versions are harder to address) stupidly moving the inner button text on click */
.pressed {
padding-top: 3px;
transform: translateY(4px);
box-shadow: 0 4px 0 rgb(183, 0, 0),
0 8px 6px rgba(0, 0, 0, .45);
}
/* Input Field */
input[type=text] {
width: 80%;
z-index: 4;
text-align: center;
position: relative;
background: rgb(253, 96, 96);
border: 2px solid rgb(155, 0, 0);
border-radius: 4px;
margin: 8px 0;
outline: none;
padding: 8px;
box-sizing: border-box;
transition: .3s;
}
input[type=text]:focus {
border-color: dodgerBlue;
box-shadow: 0 0 8px 0 dodgerBlue;
}
</style>
</head>
<body>
<div>
<canvas id="canvas-number"></canvas>
<canvas id="canvas-dots"></canvas>
<button id="BRB" type="button">BAN!<input type="text" id="UserToBan" placeholder="Username"></button>
<!-- <input type="text" id="UserToBan" placeholder="Username"> -->
</div>
</body>
</html>
<script>
const Global = {
SnackBox_Timeout: 400,
SnackBox_Location: 'tr',
isHidden: false,
keymap: {}
};
// Get global locations
const getUrl = window.location;
const baseUrl = getUrl.protocol + "//" + getUrl.host + "/";
const urlParams = decodeURI(getUrl.hash)
.replace('#', '')
.split('&')
.map(param => param.split('='))
.reduce((values, [key, value]) => {
values[key] = value
return values
}, {})
//Check Twich OAuth Token
if ('access_token' in urlParams) {
sessionStorage.setItem("access_token", urlParams.access_token)
window.location.replace(`${baseUrl}`);
} else {
if (sessionStorage.getItem("access_token") === null) {
sessionStorage.setItem("first_open", "true")
window.location.replace(`${baseUrl}login.html`);
}
}
//Register Keypress to go to settings
$(document).on('keypress', function (e) {
onkeydown = onkeyup = function(e){
e = e || event; // to deal with IE
Global.keymap[e.keyCode] = e.type == 'keydown';
if (Global.keymap[60] && Global.keymap[83]) {
window.location.replace(`${baseUrl}settings.html`);
//killdots();
}
if (Global.keymap[60] && Global.keymap[72]) {
if (Global.isHidden) {
hideButton(false); //hide button on h key
$('#UserToBan').val("");
initDots();
Global.isHidden = false;
} else {
hideButton(true); //unhide button on h key
$('#UserToBan').val("");
killdots();
Global.isHidden = true;
}
}
}
});
//Auto select input field
const input = document.getElementById('UserToBan');
input.focus();
input.select();
//Check if user has Settings
if (localStorage.getItem("Username") === null && localStorage.getItem("Channel") === null && localStorage.getItem("Reson") === null && localStorage.getItem("CoutDownTime") === null) {
sessionStorage.setItem("first_open", "false")
SnackBar({
message: `You need to enter settings, press "< + S" to go to settings`,
width: "400px",
speed: Global.SnackBox_Timeout,
timeout: false,
position: Global.SnackBox_Location,
status: "danger",
});
}
//Tell user about the settings page
if (sessionStorage.getItem("first_open") == "true") {
SnackBar({
message: `To get to the settings, press "< + S"`,
width: "400px",
speed: Global.SnackBox_Timeout * 2,
position: Global.SnackBox_Location,
status: "info",
});
}
// Twitch API Initialization
const client = new tmi.Client({
connection: {
secure: true,
reconnect: true
},
identity: {
username: localStorage.getItem("Username"),
password: `oauth:${sessionStorage.getItem("access_token")}`
},
channels: [localStorage.getItem("Channel")]
});
client.connect().then(() => {
SnackBar({
message: `Connected to Twich!`,
width: "400px",
speed: Global.SnackBox_Timeout,
position: Global.SnackBox_Location,
status: "success",
});
}).catch(err => {
SnackBar({
message: `Error: ${err}`,
width: "400px",
speed: Global.SnackBox_Timeout,
position: Global.SnackBox_Location,
status: "error",
});
});
//Twitch Chat Handler
let BadWordList;
if (localStorage.getItem("EnableChat") == "true") {
BadWordList = localStorage.getItem("BadWordList").split(",").map(v => v.toLowerCase().trim());
}
client.on('message', (channel, tags, message, self) => {
if (self) return;
if (localStorage.getItem("EnableChat") == "true") {
if (localStorage.getItem("LogChat") == "true") {
SnackBar({
message: `${tags["display-name"]}: ${message}`,
width: "400px",
speed: Global.SnackBox_Timeout,
position: Global.SnackBox_Location,
status: "success",
});
}
//Check if Message contains a bad word
const MessageArray = message.split(" ");
MessageArray.map(word => {
if (BadWordList.includes(word.toLowerCase())) {
SnackBar({
message: `User ${tags["display-name"]} wrote bad word ${word.toLowerCase().trim()}`,
width: "400px",
speed: Global.SnackBox_Timeout,
position: Global.SnackBox_Location,
status: "warning",
});
//Delete bad Messages if enabled
if(localStorage.getItem("DelBadMsg") == "true"){
console.log(tags)
client.deletemessage(localStorage.getItem("Channel"), tags["id"]);
}
//Autofill username that wrote bad word
$('#UserToBan').val(tags["display-name"]);
//UnhideButton if Hidden and enabled
if (localStorage.getItem("AHiddenMode") == "true") {
if (Global.isHidden) {
hideButton(false); //hide button on h key
initDots();
Global.isHidden = false;
}
}
}
})
}
});
//Button handler
const dance = document.getElementById("BRB");
function hideButton(bool) {
if (bool) {
$('#BRB').css({ 'z-index': '3', 'opacity': '0' });
} else {
$('#BRB').css({ 'z-index': '3', 'opacity': '1' });
}
}
function press() {
dance.classList.add("pressed");
}
function unpress() {
dance.classList.remove("pressed");
}
function handleKey() {
$('#BRB').css({ 'z-index': '3', 'opacity': '1' });
$('#canvas-dots').css({ 'z-index': '1' });
setTimeout(press, 100);
client.ban(localStorage.getItem("Channel"), $('#UserToBan').val(), localStorage.getItem("Reson")).then(() => {
if (localStorage.getItem("Brodcast") == "true") {
client.say(localStorage.getItem("Channel"), `The user ${$('#UserToBan').val()} has been banned for ${localStorage.getItem("Reson")}`);
}
setTimeout(unpress, 600);
//Hide Elements after ban, if enabled (HiddenMode)
if (localStorage.getItem("HiddenMode") == "true") {
setTimeout(() => {
hideButton(true); //unhide button on h key
killdots();
Global.isHidden = true;
}, 2000);
}
}).catch(function (err) {
setTimeout(unpress, 600);
if (localStorage.getItem("HiddenMode") == "true") {
setTimeout(() => {
hideButton(true); //unhide button on h key
killdots();
Global.isHidden = true;
}, 2000);
}
if (err === "already_banned") {
SnackBar({
message: `${$('#UserToBan').val()} is already banned!`,
width: "400px",
speed: Global.SnackBox_Timeout,
position: Global.SnackBox_Location,
status: "error",
});
} else if (err === "invalid_user") {
SnackBar({
message: `${$('#UserToBan').val()} is not a valid user!`,
width: "400px",
speed: Global.SnackBox_Timeout,
position: Global.SnackBox_Location,
status: "error",
});
} else if (err === "No response from Twitch.") {
SnackBar({
message: `You need to enter settings, press "S" to go to settings`,
width: "400px",
speed: Global.SnackBox_Timeout * 2,
position: Global.SnackBox_Location,
status: "danger",
});
} else {
console.log(err)
}
});
}
function runButton() {
if ($('#UserToBan').val() === "") {
console.log("Likly unitentional press")
} else {
//ResetCountDown
countdownRunning = true;
countdownFrom = localStorage.getItem("CoutDownTime");
if (localStorage.getItem("CoutDown") == "true") {
if(localStorage.getItem("TimeoutWhileBan") == "true"){
//Handling is useless since twich dosn´t respond with usefull information
client.timeout(localStorage.getItem("Channel"), $('#UserToBan').val(), Number(localStorage.getItem("CoutDownTime"))*4, localStorage.getItem("Reson"))
}
$('#BRB').css({ 'z-index': '1', 'opacity': '0.1' });
$('#canvas-dots').css({ 'z-index': '3' });
countdown()
} else {
handleKey();
}
}
}
dance.addEventListener('click', function (event) {
runButton();
});
/*
Desc: Define inital variables
*/
var numberStage,
numberStageCtx,
numberStageWidth = 680,
numberStageHeight = 420,
numberOffsetX,
numberOffsetY,
stage,
stageCtx,
stageWidth = window.innerWidth,
stageHeight = window.innerHeight,
stageCenterX = stageWidth / 2,
stageCenterY = stageHeight / 2,
countdownFrom = localStorage.getItem("CoutDownTime"),
countdownTimer = 2400,
countdownRunning = true,
number,
dots = [],
numberPixelCoordinates,
circleRadius = 2,
colors = ['61, 207, 236', '255, 244, 174', '255, 211, 218', '151, 211, 226'];
/*
Desc: Init canvases & Number text
*/
function init() {
// Init stage which will have numbers
numberStage = document.getElementById("canvas-number");
numberStageCtx = numberStage.getContext('2d');
// Set the canvas to width and height of the window
numberStage.width = numberStageWidth;
numberStage.height = numberStageHeight;
// Init Stage which will have dots
stage = document.getElementById("canvas-dots");
stageCtx = stage.getContext('2d');
stage.width = stageWidth;
stage.height = stageHeight;
// Create offset so text appears in middle of screen
numberOffsetX = (stageWidth - numberStageWidth) / 2;
numberOffsetY = (stageHeight - numberStageHeight) / 2;
}
function killdots() {
dots = [];
}
init(); //Init Canvas
initDots() //Create dots
/*
Desc: Dot object
*/
function Dot(x, y, color, alpha) {
var _this = this;
_this.x = x;
_this.y = y;
_this.color = color;
_this.alpha = alpha;
this.draw = function () {
stageCtx.beginPath();
stageCtx.arc(_this.x, _this.y, circleRadius, 0, 2 * Math.PI, false);
stageCtx.fillStyle = 'rgba(' + _this.color + ', ' + _this.alpha + ')';
stageCtx.fill();
}
}
/*
Desc: Create a certain amount of dots
*/
function initDots() {
for (var i = 0; i < 2240; i++) {
// Create a dot
var dot = new Dot(randomNumber(0, stageWidth), randomNumber(0, stageHeight), colors[randomNumber(1, colors.length)], .3);
// Push to into an array of dots
dots.push(dot);
// Animate dots
tweenDots(dot, '', 'space');
}
}
/*
Desc: Countdown
*/
function countdown() {
// Send number to be drawn
drawNumber(countdownFrom.toString());
// When we hit zero stop countdown
if (countdownFrom === 0) {
countdownRunning = false;
breakNumber(true);
// Now that countdowns finised show the text Go
}
// Decrement number down
countdownFrom--;
}
/*
Desc: Redraw loops
*/
function loop() {
stageCtx.clearRect(0, 0, stageWidth, stageHeight);
for (var i = 0; i < dots.length; i++) {
dots[i].draw(stageCtx);
}
requestAnimationFrame(loop);
}
loop();
/*
Desc: Draw number
*/
function drawNumber(num) {
// Create a number on a seperate canvas
// Use a seperate canvas thats smaller so we have less data to loop over when using getImagedata()
// Clear stage of previous numbers
numberStageCtx.clearRect(0, 0, numberStageWidth, numberStageHeight);
numberStageCtx.fillStyle = "#24282f";
numberStageCtx.textAlign = 'center';
numberStageCtx.font = "bold 418px Lato";
numberStageCtx.fillText(num, 340, 400);
var ctx = document.getElementById('canvas-number').getContext('2d');
// getImageData(x, y, width, height)
// note: is an exspenisve function, so make sure canvas is small as possible for what you grab
// Returns 1 Dimensional array of pixel color value chanels
// Red, blue, green, alpha chanel of single pixel
// First chanel is red
var imageData = ctx.getImageData(0, 0, numberStageWidth, numberStageHeight).data;
// Clear number coordinated
numberPixelCoordinates = [];
// i is equal to total image data(eg: 480,000)
// run while i is greater or equal to 0
// every time we run it minus 4 from i. Do this because each pixel has 4 chanels & we are only interested in individual pixels
for (var i = imageData.length; i >= 0; i -= 4) {
// If not an empty pixel
if (imageData[i] !== 0) {
// i represents the position in the array a red pixel was found
// (i / 4 ) and percentage by width of canvas
// Need to divide i by 4 because it has 4 values and you need its orginal position
// Then you need to percentage it by the width(600) because each row contains 600 pixels and you need its relative position in that row
var x = (i / 4) % numberStageWidth;
// (i divide by width) then divide by 4
// Divide by width(600) first so you get the rows of pixels that make up the canvas. Then divide by 4 to get its postion within the row
var y = Math.floor(Math.floor(i / numberStageWidth) / 4);
// If position exists and number is divisble by circle plus a pixel gap then add cordinates to array. So circles do not overlap
if ((x && x % (circleRadius * 2 + 3) == 0) && (y && y % (circleRadius * 2 + 3) == 0)) {
// Push object to numberPixels array with x and y coordinates
numberPixelCoordinates.push({ x: x, y: y });
}
}
}
formNumber();
}
/*
Desc: Form number
*/
function formNumber() {
for (var i = 0; i < numberPixelCoordinates.length; i++) {
// Loop out as many coordionates as we need & pass dots in to animate
tweenDots(dots[i], numberPixelCoordinates[i], '');
}
// Break number apart
if (countdownRunning && countdownFrom > 0) {
setTimeout(function () {
breakNumber(false);
countdown();
}, countdownTimer);
}
}
function breakNumber(end) {
for (var i = 0; i < numberPixelCoordinates.length; i++) {
tweenDots(dots[i], '', 'space');
}
if (end) {
// Build next number
setTimeout(function () {
handleKey();
}, countdownTimer);
}
}
/*
Desc: Animate dots
*/
function tweenDots(dot, pos, type) {
// Move dots around canvas randomly
if (type === 'space') {
// Tween dot to coordinate to form number
TweenMax.to(dot, (2 + Math.round(Math.random() * 100) / 100), {
x: randomNumber(0, stageWidth),
y: randomNumber(0, stageHeight),
alpha: 0.3,
ease: Cubic.easeInOut,
onComplete: function () {
tweenDots(dot, '', 'space');
}
});
} else {
// Tween dot to coordinate to form number
TweenMax.to(dot, (1 + Math.round(Math.random() * 100) / 100), {
x: (pos.x + numberOffsetX),
y: (pos.y + numberOffsetY),
delay: 0,
alpha: 1,
ease: Cubic.easeInOut,
onComplete: function () {
}
});
}
}
/*
Desc: Get a random number
*/
function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
</script>
<!-- Credits: -->
<!-- https://codepen.io/dudleystorey/pen/zqgGn -->
<!-- https://codepen.io/allanpope/pen/eNgGJm -->