-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdocs.html
1584 lines (1490 loc) · 64.3 KB
/
docs.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>upnext.fm user scripts</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Official upnext.fm user scripting repository and documentation.">
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon">
<link href="favicon.ico" rel="icon" type="image/x-icon">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/site.css" rel="stylesheet">
<link href="assets/prism.css" rel="stylesheet">
</head>
<body id="top">
<a href="https://github.com/upnextfm/scripts/fork">
<img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png">
</a>
<div class="container">
<div class="row">
<div class="col-sm-3 card">
<div id="sidebar">
<img src="images/logo.png" style="width: 100%;" />
<h2>Official upnext.fm script repository and API documentation.</h2>
<ul class="sidebar-items">
<li>
<a href="index.html" class="docs-tc-root">Scripts</a>
</li>
<li>
<a href="installing.html" class="docs-tc-root">How To Install Scripts</a>
</li>
<li class="active">
<a href="docs.html" class="docs-tc-root">API Documentation</a>
<div>
<a href="docs.html#topic-api-api" class="docs-tc-root sub">Overview</a>
<ul id="sidebar-item-api">
<li><a href="docs.html#topic-api-api">$api</a></li>
<li><a href="docs.html#topic-api-chat">$chat</a></li>
<li><a href="docs.html#topic-api-playlist">$playlist</a></li>
<li><a href="docs.html#topic-api-channel">$channel</a></li>
<li><a href="docs.html#topic-api-user">$user</a></li>
<li><a href="docs.html#topic-api-options">$options</a></li>
<li><a href="docs.html#topic-api-proxy">$proxy</a></li>
<li><a href="docs.html#topic-api-store">$store</a></li>
<li><a href="docs.html#topic-api-timer">$timer</a></li>
<li><a href="docs.html#topic-api-script">$script</a></li>
<li><a href="docs.html#topic-api-stylesheet">$stylesheet</a></li>
<li><a href="docs.html#topic-api-first-script">First Script</a></li>
</ul>
<a href="docs.html#topic-properties" class="docs-tc-root sub">Properties</a>
<ul id="sidebar-item-properties">
<li><a href="docs.html#topic-properties-version">$api.version</a></li>
</ul>
<a href="docs.html#topic-api-methods" class="docs-tc-root sub">Methods</a>
<ul id="sidebar-item-methods">
<li><a href="docs.html#topic-api-methods-send">$chat.send()</a></li>
<li><a href="docs.html#topic-api-methods-notice">$chat.notice()</a></li>
<li><a href="docs.html#topic-api-methods-command">$chat.command()</a></li>
<li><a href="docs.html#topic-api-methods-toast">$chat.toast()</a></li>
<li><a href="docs.html#topic-api-methods-clear">$chat.clear()</a></li>
<li><a href="docs.html#topic-api-methods-color">$chat.color()</a></li>
<li><a href="docs.html#topic-api-methods-ignore">$chat.ignore()</a></li>
<li><a href="docs.html#topic-api-methods-unignore">$chat.unignore()</a></li>
<li><a href="docs.html#topic-api-methods-kick">$chat.kick()</a></li>
<li><a href="docs.html#topic-api-methods-mute">$chat.mute()</a></li>
<li><a href="docs.html#topic-api-methods-smute">$chat.smute()</a></li>
<li><a href="docs.html#topic-api-methods-unmute">$chat.unmute()</a></li>
<li><a href="docs.html#topic-api-methods-ban-by-name">$chat.banByName()</a></li>
<li><a href="docs.html#topic-api-methods-ban-by-ip">$chat.banByIP()</a></li>
<li><a href="docs.html#topic-api-methods-users">$chat.users()</a></li>
<li><a href="docs.html#topic-api-methods-playlist-queue">$playlist.queue()</a></li>
<li><a href="docs.html#topic-api-methods-playlist-dequeue-by-name">$playlist.dequeueByName()</a></li>
<li><a href="docs.html#topic-api-methods-playlist-skip">$playlist.skip()</a></li>
<li><a href="docs.html#topic-api-methods-playlist-vote">$playlist.vote()</a></li>
<li><a href="docs.html#topic-api-methods-playlist-clear">$playlist.clear()</a></li>
<li><a href="docs.html#topic-api-methods-playlist-shuffle">$playlist.shuffle()</a></li>
<li><a href="docs.html#topic-api-methods-playlist-lock">$playlist.lock()</a></li>
<li><a href="docs.html#topic-api-methods-playlist-search">$playlist.search()</a></li>
<li><a href="docs.html#topic-api-methods-set-storage">$store.local.set()</a></li>
<li><a href="docs.html#topic-api-methods-get-storage">$store.local.get()</a></li>
<li><a href="docs.html#topic-api-methods-remove-storage">$store.local.remove()</a></li>
<li><a href="docs.html#topic-api-methods-set-database">$store.database.set()</a></li>
<li><a href="docs.html#topic-api-methods-get-database">$store.database.get()</a></li>
<li><a href="docs.html#topic-api-methods-remove-database">$store.database.remove()</a></li>
<li><a href="docs.html#topic-api-methods-keys-database">$store.database.keys()</a></li>
<li><a href="docs.html#topic-api-methods-timer-interval">$timer.interval()</a></li>
<li><a href="docs.html#topic-api-methods-timer-once">$timer.once()</a></li>
<li><a href="docs.html#topic-api-methods-timer-clear">$timer.clear()</a></li>
<li><a href="docs.html#topic-api-methods-timer-clear-all">$timer.clearAll()</a></li>
<li><a href="docs.html#topic-api-methods-timer-has">$timer.has()</a></li>
</ul>
<a href="docs.html#topic-api-events" class="docs-tc-root sub">Events</a>
<ul id="sidebar-item-events">
<li><a href="docs.html#topic-api-events-delete-script">$api.delete_script</a></li>
<li><a href="docs.html#topic-api-events-save-scripts">$api.save_scripts</a></li>
<li><a href="docs.html#topic-api-events-loaded">$chat.loaded</a></li>
<li><a href="docs.html#topic-api-events-reloaded">$chat.reloaded</a></li>
<li><a href="docs.html#topic-api-events-receive">$chat.receive</a></li>
<li><a href="docs.html#topic-api-events-send">$chat.send</a></li>
<li><a href="docs.html#topic-api-events-notice">$chat.notice</a></li>
<li><a href="docs.html#topic-api-events-whisper">$chat.whisper</a></li>
<li><a href="docs.html#topic-api-events-command">$chat.command</a></li>
<li><a href="docs.html#topic-api-events-user-join">$chat.user_join</a></li>
<li><a href="docs.html#topic-api-events-user-leave">$chat.user_leave</a></li>
<li><a href="docs.html#topic-api-events-emotes-personal">$chat.emotes_personal</a></li>
<li><a href="docs.html#topic-api-events-emotes-channel">$chat.emotes_channel</a></li>
<li><a href="docs.html#topic-api-events-afk">$chat.afk</a></li>
<li><a href="docs.html#topic-api-events-profile-menu">$chat.profile_menu</a></li>
<li><a href="docs.html#topic-api-events-user-options-save">$chat.user_options_save</a></li>
<li><a href="docs.html#topic-api-events-channel-option-save">$chat.channel_option_save</a></li>
<li><a href="docs.html#topic-api-events-color-change">$chat.color_change</a></li>
<li><a href="docs.html#topic-api-events-blink">$chat.blink</a></li>
<li><a href="docs.html#topic-api-events-unblink">$chat.unblink</a></li>
<li><a href="docs.html#topic-api-events-video-resize">$chat.video_resize</a></li>
<li><a href="docs.html#topic-api-events-playlist-loaded">$playlist.loaded</a></li>
<li><a href="docs.html#topic-api-events-queue">$playlist.queue</a></li>
<li><a href="docs.html#topic-api-events-media-change">$playlist.media_change</a></li>
<li><a href="docs.html#topic-api-events-media-update">$playlist.media_update</a></li>
<li><a href="docs.html#topic-api-events-favorites">$playlist.favorites</a></li>
<li><a href="docs.html#topic-api-events-favorite-add">$playlist.favorite_add</a></li>
<li><a href="docs.html#topic-api-events-tags">$playlist.tags</a></li>
<li><a href="docs.html#topic-api-events-votes">$playlist.votes</a></li>
<li><a href="docs.html#topic-api-events-vote-value">$playlist.vote_value</a></li>
<li><a href="docs.html#topic-api-events-search-results">$playlist.search_results</a></li>
</ul>
<a href="docs.html#topic-examples" class="docs-tc-root sub">Examples</a>
<ul id="sidebar-item-examples">
<li><a href="docs.html#topic-api-examples-favorites">Queuing Favorites</a></li>
<li><a href="docs.html#topic-api-examples-lucky">I'm Feeling Lucky</a></li>
</ul>
</div>
</li>
</ul>
</div>
</div>
<div class="col-sm-9">
<div id="docs-container">
<section class="card">
<h1 id="topic-overview-api">API</h1>
<p>
Several objects are available to user scripts.
</p>
<ul style="margin:0;padding:0;list-style-type:none;">
<li>
<code id="topic-api-api" class="signature">$api</code>
<p>
Used to interact with the API.
</p>
</li>
<li>
<code id="topic-api-chat" class="signature">$chat</code>
<p>
Provides an interface to the chat API. The rest of this documentation covers the properties,
methods, and events related to this object.
</p>
</li>
<li>
<code id="topic-api-playlist" class="signature">$playlist</code>
<p>
Provides an interface to the playlist API. The rest of this documentation covers the properties,
methods, and events related to this object.
</p>
</li>
<li>
<code id="topic-api-channel" class="signature">$channel</code>
<p>
An object containing information about the channel you are in. The object contains several properties.
</p>
<pre style="margin-top: 12px;">
<code class="language-javascript">
{
bio: String, // The channel bio/information.
css: String, // The channel CSS.
js: String, // The channel Javascript.
emotes: Array, // An array of channel emotes.
motd: String, // The channel message of the day.
name: String, // The name of the channel.
usercount: Number // The number of users in the channel.
}
</code>
</pre>
</li>
<li>
<code id="topic-api-user" class="signature">$user</code>
<p>
An object containing information about you. The object contains several properties.
</p>
<pre style="margin-top: 12px;">
<code class="language-javascript">
{
emotes: Array, // An array of your personal emotes.
name: String, // Your username.
profile: Object, // Your profile information.
rank: Number // Your channel rank.
}
</code>
</pre>
</li>
<li>
<code id="topic-api-options" class="signature">$options</code>
<p>
Reference to an object which represents the channel Options menu. Used to create options
menus for scripts.
</p>
<pre style="margin-top: 12px;">
<code class="language-javascript">
// Creates a new menu where the tab has the label "Twitter Feed", and
// sub element IDs are prefixed with "twitter".
var options = $options.create("Twitter Feed", "twitter");
// Set the menu title.
options.title("Twitter Feed");
// Add a text input to the form.
options.add("text", "twitter-username", {
label: "Username",
val: settings.username,
help: "Your Twitter username"
}).on("change", function() {
// Get the value of the input.
settings.username = options.val("twitter-username");
console.log(settings.username);
// Clear the input.
options.clear("twitter-username");
});
</code>
</pre>
</li>
<li>
<code id="topic-api-proxy" class="signature">$proxy</code>
<p>
Wrapper for jQuery ajax shorthand methods, which sends request through the site proxy.
Helps to get around CORS and TLS/SSL issues when making remote requests.
See <a href="http://api.jquery.com/category/ajax/shorthand-methods" target="_blank">http://api.jquery.com/category/ajax/shorthand-methods</a>
</p>
<p>
Contains the methods <code>$proxy.getJSON()</code>, <code>$proxy.getScript()</code>,
<code>$proxy.get()</code>, and <code>$proxy.post()</code>.
</p>
</li>
<li>
<code id="topic-api-store" class="signature">$store</code>
<p>
Provides access to cookies, localStorage, and the site database key/value store.
More information about the <code>$store</code> methods are covered in the
<a href="#topic-api-methods" class="help-tc-root">methods</a> of this documentation.
</p>
</li>
<li>
<code id="topic-api-timer" class="signature">$timer</code>
<p>
A convenience wrapper around the setInterval() and setTimeout() functions. Information about the
methods is available in the <a href="#topic-api-methods-timer-interval" class="help-tc-root">methods section</a> of
this documentation.
</p>
</li>
<li>
<code id="topic-api-script" class="signature">$script</code>
<p>
Provides information about the script itself, as well as annotations found in the
script doc block header.For instance when the user script contains the following doc block:
</p>
<pre style="margin-top: 12px;">
<code class="language-javascript">
/**
* Name: Reaction GIFs
* Version: 1.5
* Author: headzoo
*
* Displays a random image from replygif.net based on your search term
*/
</code>
</pre>
<p>
The <code>$script</code> object will contain the following values:
</p>
<pre style="margin-top: 12px;">
<code class="language-javascript">
{
"filename": "react.js",
"is_first_run": false,
"Name": "Reaction GIFs",
"Version": "1.5",
"Author": "headzoo"
}
</code>
</pre>
<p>
Note that <code>$script</code> also contains the script filename, and whether it's being run for
the the first.
</p>
</li>
<li>
<code id="topic-api-stylesheet" class="signature">$stylesheet</code>
<p>
Used to create and add stylesheets to the document.
</p>
<pre style="margin-top: 12px;">
<code class="language-javascript">
// Create a new stylesheet using a unique identifier.
var my_stylesheet = new $stylesheet("my_stylesheet");
// Add styles by providing the selector followed by one or more
// properties.
my_stylesheet.add("#wrap", {
"color": "#FFF",
"font-family": "arial"
});
// Append the stylesheet to the document head. Automatically removes
// previously appended stylesheets with the same identifier.
my_stylesheet.append();
// Removes the stylesheet from the document.
my_stylesheet.remove();
</code>
</pre>
</li>
<li>
<code id="topic-api-store" class="signature">$store</code>
<p>
Provides access to cookies, localStorage, and the site database key/value store.
More information about the <code>$store</code> methods are covered in the
<a href="#topic-api-methods" class="help-tc-root">methods</a> of this documentation.
</p>
</li>
</ul>
<h5 id="topic-api-first-script">First Script</h5>
<p>
From the site navigation menu click on Options and then Scripting. In the default text box,
type (or paste) this code and click save.
</p>
<pre>
<code class="language-javascript line-numbers">
alert("Your username is " + $user.name + " and you are in the channel " + $channel.name);
</code>
</pre>
<a href="#top" class="top">
<span class="glyphicon glyphicon-chevron-up"></span>
Back to Top
</a>
</section>
<section class="card">
<h1 id="topic-properties">Properties</h1>
<code id="topic-properties-version" class="signature">$api.version</code>
<p>
Version of the API implemented.
</p>
<a href="#top" class="top">
<span class="glyphicon glyphicon-chevron-up"></span>
Back to Top
</a>
</section>
<section class="card">
<h1 id="topic-api-events">Events</h1>
<p>
Interacting with the channel is mostly done through the use of event callbacks. The following code
demonstrates the use of callbacks to CAPITALIZE every message you send. Callbacks are registered
with events using the <code>$chat.on()</code> method, which takes two arguments: the name of the
event, and the callback function. The function will be called when an event with the given name
is triggered.
</p>
<pre>
<code class="language-javascript line-numbers">
// Registers a callback which filters every message you send _before_ it gets sent
// to the server, and subsequently broadcast to each user in the channel.
$chat.on("send", function(e, data) {
// Every message you send will be automatically capitalized.
data.msg = data.msg.toUpperCase();
});
</code>
</pre>
<pre>
<code class="language-javascript line-numbers">
// Registers a callback which filters every message you received from the server.
$chat.on("receive", function(e, data) {
// Every message you receive will be automatically capitalized.
data.msg = data.msg.toUpperCase();
});
</code>
</pre>
<pre>
<code class="language-javascript line-numbers">
// Automatically up vote each video.
$playlist.on("media_change", function(e, data) {
$playlist.vote(1);
});
</code>
</pre>
<h5>Event Names</h5>
<ul style="list-style-type: none; padding: 0;">
<li id="topic-api-events-delete-script">
<code class="signature">$api.delete_script</code>
Triggered before a script is deleted. The filename of the script being deleted is passed to the callback.
This is triggered when any script is deleted, not just the script watching the event. Scripts should
use <code>$script.filename</code> to check if its being deleted.
<pre>
<code class="language-javascript">
$api.on("delete_script", function(e, filename) {
if ($script.filename == filename) {
console.log("Help! I'm being deleted!");
}
});
</code>
</pre>
</li>
<li id="topic-api-events-save-scripts">
<code class="signature">$api.save_scripts</code>
Triggered when the scripts are being saved. The callback receives an <i>array</i> of objects which
have these properties.
<pre>
<code class="language-javascript">
{
name: String, // The name of the script
script: String // The script text
}
</code>
</pre>
</li>
<li id="topic-api-events-loaded">
<code class="signature">$chat.loaded</code>
Triggered after every page element has been loaded, and all user scripts have been loaded.
Page elements are the user list, chat buffer, and video player. No data is passed to the callback.
</li>
<li id="topic-api-events-reloaded">
<code class="signature">$chat.reloading</code>
Triggered after the user scripts have been updated, and are about to be torn down and
reinserted into the page. No data is passed to the callback.
</li>
<li id="topic-api-events-receive">
<code class="signature">$chat.receive</code>
Triggered when a message is received from another user in the room. The callback gets a
data object with the following properties.
<pre>
<code class="language-javascript">
{
username: String, // Name of the user that sent the message.
msg: String, // The message sent by the user.
msg_clean: String, // Message without color codes.
is_mentioned: Boolean, // If the user is mentioned in the message
time: Number, // Time the message was sent.
meta: Object, // Contains a "color" property with the text color.
}
</code>
</pre>
</li>
<li id="topic-api-events-send">
<code class="signature">$chat.send</code>
Triggered before sending a message to the other users in the room. The callback gets a data
object which contains the details of your message.
<pre>
<code class="language-javascript">
{
msg: String, // The message you are sending.
meta: Object, // Contains a "color" property with your text color.
}
</code>
</pre>
</li>
<li id="topic-api-events-notice">
<code class="signature">$chat.notice</code>
Triggered when a notice is received from the server. Notices are used to notify users when
someone up votes or favorites their videos.
<pre>
<code class="language-javascript">
{
msg: String // The notice text
}
</code>
</pre>
</li>
<li id="topic-api-events-whisper">
<code class="signature">$chat.whisper</code>
Triggered when a whisper is received from another user. The callback gets an object which
contains the whisper data.
<pre>
<code class="language-javascript">
{
msg: String, // The whisper text
meta: Object, // Meta information
time: Number, // Time the whisper was sent
name: String, // Name of the user who sent the whisper
}
</code>
</pre>
</li>
<li id="topic-api-events-command">
<code class="signature">$chat.command</code>
Triggered when the script receives a command. The callback gets an object which contains the
command data.
<pre>
<code class="language-javascript">
{
to: String, // Name of the user receiving the command or "#" for the whole channel
from: String, // Name of the user that sent the command
data: Object // The command data
}
</code>
</pre>
</li>
<li id="topic-api-events-user-join">
<code class="signature">$chat.user_join</code>
Triggered when a user joins the channel. The callback gets a data object with the user's details.
<pre>
<code class="language-javascript">
{
name: String, // The user's name
rank: Number, // The user's rank
meta: Object, // Contains properties such as "afk"
profile: Object, // Contains "image" (avatar url), and "text" (tagline)
}
</code>
</pre>
</li>
<li id="topic-api-events-user-leave">
<code class="signature">$chat.user_leave</code>
Triggered when a user leaves the channel. The callback gets an object with the user's name.
<pre>
<code class="language-javascript">
{
name: String, // The user's name
}
</code>
</pre>
</li>
<li id="topic-api-events-emotes-personal">
<code class="signature">$chat.emotes_personal</code>
Triggered when the server sends your personal emotes. The callback receives an <i>array</i> of
objects which describe the emote.
<pre>
<code class="language-javascript">
{
image: String, // URL of the emote image
name: String, // The string value that triggers the emote
regex: RegExp // Used to find the emote in strings
}
</code>
</pre>
</li>
<li id="topic-api-events-emotes-channel">
<code class="signature">$chat.emotes_channel</code>
Triggered when the server sends the channel emotes. The callback receives an <i>array</i> of
objects which describe the emote.
<pre>
<code class="language-javascript">
{
image: String, // URL of the emote image
name: String, // The string value that triggers the emote
regex: RegExp // Used to find the emote in strings
}
</code>
</pre>
</li>
<li id="topic-api-events-afk">
<code class="signature">$chat.afk</code>
Triggered when a user goes afk or comes back from afk. The callback gets an object detailing
the user and whether they are coming are going into afk.
<pre>
<code class="language-javascript">
{
name: String, // The name of the user
afk: Boolean // True if they are going afk, false if they are coming back
}
</code>
</pre>
</li>
<li id="topic-api-events-profile-menu">
<code class="signature">$chat.profile_menu</code>
Triggered when the popup profile menu is created for each user in the user list. The callback
receives a jQuery element with the content of the menu.
</li>
<li id="topic-api-events-user-options-save">
<code class="signature">$chat.user_options_save</code>
Triggered when the user options are being saved. The callback receives an object which represent
the settings key/value pairs. For example:
<pre>
<code class="language-javascript">
{
ignore_channelcss: false
ignore_channeljs: false
joinmessage: true,
show_colors: true
show_joins: true
show_notices: true,
...
}
</code>
</pre>
</li>
<li id="topic-api-events-channel-option-save">
<code class="signature">$chat.channel_option_save</code>
Triggered when a single channel option is being saved. Only applicable to admins and mods. The
callback receives an object which represents the setting key/value pair. For example:
<pre>
<code class="language-javascript">
{
join_msg: "Welcome to the lobby!"
}
</code>
</pre>
</li>
<li id="topic-api-events-color-change">
<code class="signature">$chat.color_change</code>
Triggered when the text color is changed. Fires when the page initially loads as well. The
callback gets a string with the html color code.
</li>
<li id="topic-api-events-blink">
<code class="signature">$chat.blink</code>
Triggered when the browser title bar is to blink because the user's name was said in chat. The callback
receives the following object.
<pre>
<code class="language-javascript">
{
title_text: String, // Text that will appear in the title bar, e.g. "*Chat*"
boop_setting: String, // Play sound setting, either "never", "onlyping", or "always"
blink_setting: String, // Blink setting, either "never", "onlyping", or "always"
blink_interval: Number // Speed of flashing title text. Lower equals faster, default is 1000.
}
</code>
</pre>
</li>
<li id="topic-api-events-unblink">
<code class="signature">$chat.unblink</code>
Triggered when the receives focus and blinking is being turned off.
</li>
<li id="topic-api-events-video-resize">
<code class="signature">$chat.video_resize</code>
Triggered when the video or window resizes.
</li>
<li id="topic-api-events-playlist-loaded">
<code class="signature">$playlist.loaded</code>
Triggered when the channel receives the list of videos in the playlist. The callback gets an
<i>array</i> of objects that describe each video.
<pre>
<code class="language-javascript">
{
queueby: String, // Name of the user that queued the video
media: Object // Describes the video
}
</code>
</pre>
<p>
The "media" property contains the following values.
</p>
<pre>
<code class="language-javascript">
{
duration: Number, // Human readable video duration, e.g. "00:00"
seconds: Number, // Video duration in seconds
uid: String, // Typically a YouTube video id
title: String, // Title of the video
type: String, // "yt" for YouTube videos, "sc" for soundcloud, etc
}
</code>
</pre>
</li>
<li id="topic-api-events-queue">
<code class="signature">$playlist.queue</code>
Triggered before a video gets added to the playlist. The callback gets an object describing where
the video is being added to the playlist, and a media object.
<pre>
<code class="language-javascript">
{
after: Number, // Video is being inserted after this index
item: Object // Info about the video
}
</code>
</pre>
<p>
The "item" property contains information about the video.
</p>
<pre>
<code class="language-javascript">
{
queueby: String, // Name of the user that queued the video
media: Object // Describes the video
}
</code>
</pre>
<p>
The "media" property contains the following values.
</p>
<pre>
<code class="language-javascript">
{
duration: Number, // Human readable video duration, e.g. "00:00"
seconds: Number, // Video duration in seconds
uid: String, // Typically a YouTube video id
title: String, // Title of the video
type: String, // "yt" for YouTube videos, "sc" for soundcloud, etc
}
</code>
</pre>
</li>
<li id="topic-api-events-media-change">
<code class="signature">$playlist.media_change</code>
Triggered before the next song in the playlist begins to play. The callback gets a media object.
<pre>
<code class="language-javascript">
{
duration: Number, // Human readable video duration, e.g. "00:00"
seconds: Number, // Video duration in seconds
currentTime: Number, // Time where the video will start to play
paused: Boolean, // Whether the video is paused
uid: String, // Typically a YouTube video id
title: String, // Title of the video
type: String, // "yt" for YouTube videos, "sc" for soundcloud, etc
}
</code>
</pre>
</li>
<li id="topic-api-events-media-update">
<code class="signature">$playlist.media_update</code>
Triggered when the time/synchronization information for the currently playing video updates.
Typically fires every few seconds. The callback gets an object describing the position
in the currently playing video.
<pre>
<code class="language-javascript">
{
currentTime: Float, // Current position in seconds
paused: Boolean, // Whether the video is paused
}
</code>
</pre>
</li>
<li id="topic-api-events-favorites">
<code class="signature">$playlist.favorites</code>
Triggered when the server sends your list of favorited videos. The callback gets an <i>array</i>
of objects describing each video.
<pre>
<code class="language-javascript">
{
favorite_id: Number, // The favorite id
media_id: Number, // The media id
seconds: Number, // The video duration in seconds
time: Number, // Date/time when the video was favorited
uid: String, // Typically a YouTube video id
title: String, // Title of the video
type: String, // "yt" for YouTube videos, "sc" for soundcloud, etc
}
</code>
</pre>
</li>
<li id="topic-api-events-favorite-add">
<code class="signature">$playlist.favorite_add</code>
Triggered when you have favorited a video. The callback gets an object with the tags used, and
information about the media.
<pre>
<code class="language-javascript">
{
tags: Array, // Array of strings representing the tags applied to the favorite
media: Object // Object describing the video
}
</code>
</pre>
<p>
The "media" object contains the following properties.
</p>
<pre>
<code class="language-javascript">
{
id: Number, // The favorite id
seconds: Number, // The video duration in seconds
time: Number, // Date/time when the video was favorited
uid: String, // Typically a YouTube video id
title: String, // Title of the video
type: String, // "yt" for YouTube videos, "sc" for soundcloud, etc
}
</code>
</pre>
</li>
<li id="topic-api-events-tags">
<code class="signature">$playlist.tags</code>
Triggered when the server sends a list of all tags you have used. The callback gets an array
of strings, where each string is a tag. For example:
<pre>
<code class="language-javascript">
["80s", "90s", "Rock", "Kpop"]
</code>
</pre>
</li>
<li id="topic-api-events-votes">
<code class="signature">$playlist.votes</code>
Triggered when the votes for the currently playing video have changed. The callback gets an
object with the number of up votes and down votes for the video.
<pre>
<code class="language-javascript">
{
up: Number, // The number of up votes
down: Number // The number of down votes
}
</code>
</pre>
</li>
<li id="topic-api-events-vote-value">
<code class="signature">$playlist.vote_value</code>
Triggered when the vote you gave to the video changes. The callback gets a number that indicates
how you voted: -1, 1, or 0, indicating whether you down voted, up voted, or remain neutral
on the vote.
</li>
<li id="topic-api-events-search-results">
<code class="signature">$playlist.search_results</code>
Triggered with the results of a YouTube search. The callback gets an object which contains
the results of the search.
<pre>
<code class="language-javascript">
{
source: String, // Always "yt" for YouTube
results: Array // An array of objects representing found videos
}
</code>
</pre>
<p>
The "results" property is an array of objects with the following properties.
</p>
<pre>
<code class="language-javascript">
{
duration: String, // Human readable video duration, e.g. "00:00"
seconds: Number, // The video duration in seconds
thumb: Object, // Contains a "url" property with the thumbnail url
uid: String, // Typically a YouTube video id
title: String, // Title of the video
type: String, // "yt" for YouTube videos, "sc" for soundcloud, etc
}
</code>
</pre>
</li>
</ul>
<h5>Event Object</h5>
<p>
Each time a registered callback is invoked, it receives an event object as the first
parameter. The event contains two methods.
</p>
<p>
<code>Event.stop()</code> Called inside your callback will stop any other callbacks from
processing the event. For example if you have three callbacks registered with the "receive"
event, and the first callback calls <code>Event.stop()</code>, the other two registered callbacks
will not be invoked.
</p>
<p>
<code>Event.cancel()</code> Called inside your callback stops the channel from processing
the message. For instance, the following code will prevent ALL messages from appearing in the
chat buffer.
</p>
<pre>
<code class="language-javascript line-numbers">
$chat.on("receive", function(e, data) {
// This causes the channel to completely discard the message, and it won't
// be shown in your chat buffer.
e.cancel();
});
</code>
</pre>
<a href="#top" class="top">
<span class="glyphicon glyphicon-chevron-up"></span>
Back to Top
</a>
</section>
<section class="card">
<h1 id="topic-api-methods">Methods</h1>
<p>
The API contains a few methods for interacting with the channel. For instance to send messages,
queue songs, and vote skip videos.
</p>
<!-- $store.local.set() -->
<code id="topic-api-methods-set-storage" class="signature">$store.local.set(key, value)</code>
<p>
Saves a value to local storage with the given value. All values are serialized
before saving. Note that local storage is volatile, and values are not guaranteed
to exist beyond the current browser session.
</p>
<pre>
<code class="language-javascript line-numbers">
// Saving a plain string.
$store.local.set("gradient_color", "#FF0000");
// Saving an object.
$store.local.set("gradient_color", {
red: 255,
green: 0,
blue: 0
});
</code>
</pre>
<!-- $store.local.get() -->
<code id="topic-api-methods-get-storage" class="signature">$store.local.get(key, default_value)</code>
<p>
Returns a value from local storage. Values are automatically unserialized. Returns the
<code>default_value</code> when the value does not exist in local storage.
Note that local storage is volatile, and values are not guaranteed
to exist beyond the current browser session.
</p>
<pre>
<code class="language-javascript line-numbers">
// Gets a value from local storage using the key "gradient_color".
// This will return null if the value does not exist in storage.
var color = $store.local.get("gradient_color");
// Same as above, but will return the given default value when the value
// does not exist in local storage.
var color = $store.local.get("gradient_color", "#FF0000");
</code>
</pre>
<!-- $store.local.remove() -->
<code id="topic-api-methods-remove-storage" class="signature">$store.local.remove(key)</code>
<p>
Removes an item from local storage. Note that local storage is volatile, and values are not guaranteed
to exist beyond the current browser session.
</p>
<pre>
<code class="language-javascript line-numbers">
$store.local.remove("gradient_color");
</code>
</pre>
<!-- $store.database.set() -->
<code id="topic-api-methods-set-database" class="signature">$store.database.set(key, value, callback)</code>
<p>
Saves a value to permanent storage in the site database. The <code>key</code> param must be 150
characters or less. The JSON encoded string value of <code>value</code> must be 5000 bytes
or less. The <code>value</code> argument may be any kind of value, including arrays and objects.
</p>
<p>
The optional <code>callback</code> argument is invoked when the operation is complete, and is
passed any error that occurred as the first argument, and the result of the operation as
the second argument. The second argument is object with the properties "affectedRows" and "changedRows".
</p>
<p>
NOTE: Each account may only store 100 values in permanent storage.
</p>
<pre>
<code class="language-javascript line-numbers">
$store.database.set("gradient_color", "#FF0000", function(err, res) {
if (err) {
alert(err);
return;
}
console.log("Affected rows " + res.affectedRows);
});
</code>
</pre>
<!-- $store.database.get() -->
<code id="topic-api-methods-get-database" class="signature">$store.database.get(key, default_value, callback)</code>
<p>
Returns a value from permanent storage in the site's database. Returns the
<code>default_value</code> when the value does not exist.
</p>
<p>
The optional <code>callback</code> argument is a function which receives two values: any error that
occurred and the value from the database.
</p>
<pre>
<code class="language-javascript line-numbers">
// The value will be the default if the key does not exist in the database.
$store.database.get("gradient_colors", "#FF0000", function(err, value) {
if (err) {
alert(err);
return;
}
console.log("Got value: " + value);
});
// The default argument is optional. Without a default the value will be
// null when the key does not exist in the database.
$store.database.get("gradient_colors", function(err, value) {
if (err) {
alert(err);
return;
}
console.log("Got value: " + value);
});
</code>