forked from ftde0/yt2009
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nbedit_watch.js
1586 lines (1447 loc) · 50.7 KB
/
nbedit_watch.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
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
/*
yt2009 :D
2022 rewrite
*/
/*
======
smaller functions, fixes to site original code etc (not sure if needed)
======
*/
function $(element) {
if(document.querySelectorAll(element).length !== 1) {
return document.querySelectorAll(element);
} else {
return document.querySelector(element)
}
}
function urchinTracker(e) {}
function recordServiceUsage(a1, a2, a3) {}
function openPopup(url, d) {
window.open(url);
}
function non_css_anim_add(element, cssProperty, from, to) {
element.style[cssProperty] = from + "px"
var current = from;
var x = setInterval(function() {
current += 4;
element.style[cssProperty] = current + "px"
if(current >= to) {
element.style[cssProperty] = to + "px"
clearInterval(x);
}
}, 5)
}
function non_css_anim_remove(element, cssProperty, from, to) {
element.style[cssProperty] = from + "px"
var current = from;
var x = setInterval(function() {
current -= 4;
element.style[cssProperty] = current + "px"
if(current <= to) {
clearInterval(x);
}
}, 5)
}
function yt2009_search() {
var query = document.querySelector("#masthead-search-term").value
window.location = "/results?search_query=" + query.split(" ").join("+")
}
function shareVideoFromFlash() {
location.hash = "watch-main-area"
expandShare()
}
function skipAhead(seconds) {
$("video").currentTime = seconds;
$("video").play()
}
function showSimpleTooltip(tip) {
tip = tip.parentNode.getElementsByTagName("div")[0]
tip.style.display = "block"
}
function hideSimpleTooltip(tip) {
tip = tip.parentNode.getElementsByTagName("div")[0]
tip.style.display = "none"
}
/*
======
ui elements
a lot of old function calls for compatibility with old browsers
target firefox 3.6 & chrome 6 for winxp - quite a vibe that way
======
*/
var useLocalStorage = window.localStorage ? true : false;
// description expand/collapse
var descriptionExpanded = false;
// more info
$("#watch-video-details-toggle-less").addEventListener("click", function() {
$("#watch-video-details-inner-more").style.display = "block"
$("#watch-video-details-toggle-more").style.display = "block"
$("#watch-video-details-inner-less").style.display = "none"
$("#watch-video-details-toggle-less").style.display = "none"
}, false)
// less info
$("#watch-video-details-toggle-more").addEventListener("click", function() {
$("#watch-video-details-inner-more").style.display = "none"
$("#watch-video-details-toggle-more").style.display = "none"
$("#watch-video-details-inner-less").style.display = "block"
$("#watch-video-details-toggle-less").style.display = "block"
}, false)
// more comments
function onWatchCommentsShowMore() {
$("#watch-comments-show-more-td").style.display = "none"
var nextPage = parseInt($(".comments-container").getAttribute("data-page")) + 1
// request
var r = new XMLHttpRequest();
r.open("GET", "/get_more_comments")
r.setRequestHeader(
"page",
parseInt($(".comments-container").getAttribute("data-page"))
)
r.setRequestHeader("url_flags", location.href)
r.setRequestHeader("source", location.href)
r.send(null)
r.addEventListener("load", function(e) {
$("#watch-comments-show-more-td").style.display = "block"
if(r.responseText.length == 0) {
$("#watch-comments-show-more-td").style.display = "none"
}
// add html sent from server
$(".comments-container").innerHTML += r.responseText
.split(";yt_continuation=")[0]
$(".comments-container").setAttribute(
"data-continuation-token",
r.responseText.split(";yt_continuation=")[1]
)
// calc comment count + add page indicator
var commentCount = parseInt($("#watch-comment-count").innerHTML)
+ r.responseText.split("watch-comment-entry").length - 1
$("#watch-comment-count").innerHTML = commentCount
$(".comments-container").setAttribute("data-page", nextPage)
}, false)
}
// expand/collapse "more from"/"related videos"
function toggleExpander(element) {
if(element.className.indexOf("yt-uix-expander-collapsed") !== -1) {
// expand
element.className = "yt-uix-expander-head"
var className = element.parentNode.querySelector(".watch-discoverbox-body").className
element.parentNode.querySelector(".watch-discoverbox-body").className = className.replace(" hid", "")
// fetch "more from" if indicated needed by server
if(document.querySelector(".yt2009-mark-morefrom-fetch")) {
morefrom_load();
}
} else {
// collapse
element.className = "yt-uix-expander-head yt-uix-expander-collapsed"
element.parentNode.querySelector(".watch-discoverbox-body")
.className += " hid"
}
}
// expand/collapse comments
function toggleCommentsExpander(element) {
var expander = element.parentNode.querySelector(".yt-uix-expander-body")
if(element.className.indexOf("yt-uix-expander-collapsed") !== -1) {
element.className = "yt-uix-expander-head"
expander.className = "yt-uix-expander-body"
} else {
element.className = "yt-uix-expander-head yt-uix-expander-collapsed"
expander.className = "yt-uix-expander-body hid"
}
}
// expand/collapse quicklist
function toggleQuicklistExpander(element) {
var ql = document.querySelector("#quicklist-panel")
if(ql.className.indexOf("yt-uix-expander-collapsed") !== -1) {
// expand
document.querySelector("#playlistContainer_QL").style.display = "block"
document.querySelector("#quicklist-panel #watch-playlist-actions")
.style.display = "block"
ql.className = ql.className
.split(" yt-uix-expander-collapsed")
.join("")
} else {
// collapse
document.querySelector("#playlistContainer_QL").style.display = "none"
document.querySelector("#quicklist-panel #watch-playlist-actions")
.style.display = "none"
ql.className += " yt-uix-expander-collapsed"
}
}
// append to history
if(useLocalStorage) {
// localstorage
var currentId = $(".email-video-url").value.split("?v=")[1].split("&")[0].split("#")[0]
var title = $(".watch-vid-ab-title").innerHTML
var views = $("#watch-view-count").innerHTML
var watch_history = []
if(!localStorage.watch_history) {
localStorage.watch_history = "[]"
}
watch_history = JSON.parse(localStorage.watch_history)
if(JSON.stringify(watch_history).indexOf(currentId) == -1) {
watch_history.unshift({
"id": currentId,
"title": title,
"views": views
})
localStorage.watch_history = JSON.stringify(watch_history)
}
} else {
// cookie
var watchHistory = ""
document.cookie.split(";").forEach(function(cookie) {
if(cookie.indexOf("watch_history=") !== -1) {
watchHistory = cookie.trimLeft().replace("watch_history=", "")
}
})
if(watchHistory.length > 4000) {
// history backup if needed
document.cookie = "watch_history_backup_" + Date.now() + "=" + watchHistory + "; Path=/; expires=Fri, 31 Dec 2066 23:59:59 GMT"
document.cookie = "watch_history= ; Path=/; expires=Fri, 31 Dec 2066 23:59:59 GMT"
watchHistory = ""
}
if(watchHistory.split(":").splice(0, 20).join(":")
.indexOf($(".email-video-url").value
.split("?v=")[1]) == -1) {
watchHistory = encodeURIComponent($("#watch-vid-title h1").innerHTML)
+ "&" + $("#watch-view-count").innerHTML
+ "&" + $(".email-video-url").value.split("?v=")[1]
+ ":" + watchHistory;
document.cookie = "watch_history="
+ watchHistory
+ "; Path=/; expires=Fri, 31 Dec 2066 23:59:59 GMT"
}
}
// always_morefrom
function morefrom_load() {
var site = location.protocol.replace(":", "") + '://' + location.host
site = $(".yt2009-channel-link").href.replace(site, "")
var name = $(".yt2009-channel-link").innerHTML
// request
var r = new XMLHttpRequest();
r.open("POST", "/morefrom_load")
r.setRequestHeader("channel", site)
r.setRequestHeader("source", location.href)
r.send(name)
r.addEventListener("load", function(e) {
// add html sent from server
$("#watch-channel-discoverbox").innerHTML += r.responseText
// remove indicator so it doesn't load all the time
var mark = document.querySelector(".yt2009-mark-morefrom-fetch");
mark.parentNode.removeChild(mark)
}, false)
}
/*
======
sub
======
*/
if(window.localStorage && !localStorage.subscriptions) {
localStorage.subscriptions = "[]"
}
// SUBSCRIBE
$("#subscribeDiv").addEventListener("click", function() {
$("#subscribeDiv").style.display = "none"
$("#unsubscribeDiv").style.display = "block"
if(useLocalStorage) {
// localstorage
var url = $(".yt2009-channel-link").href.replace(
location.protocol + "//" + location.hostname + ":" + location.port,
""
)
var creator = $(".yt2009-channel-link").innerHTML
var subList = []
subList = JSON.parse(localStorage.subscriptions)
subList.unshift({
"url": url,
"creator": creator
})
localStorage.subscriptions = JSON.stringify(subList)
} else {
// cookie
var sub = ""
document.cookie.split(";").forEach(function(cookie) {
if(cookie.indexOf("sublist=") !== -1) {
sub = cookie.trimLeft().replace("sublist=", "")
}
})
sub = encodeURIComponent(
$(".yt2009-channel-link").href.replace(
location.protocol + "//" + location.hostname + ":" + location.port,
""
)
) + "&" + encodeURIComponent($(".yt2009-channel-link").innerHTML
) + ":" + sub;
document.cookie = "sublist="
+ sub
+ "; Path=/; expires=Fri, 31 Dec 2066 23:59:59 GMT"
}
}, false)
// UNSUBSCRIBE
$("#unsubscribeDiv").addEventListener("click", function() {
$("#unsubscribeDiv").style.display = "none"
$("#subscribeDiv").style.display = "block"
var subscribeMethod = "cookie"
var url = $(".yt2009-channel-link").href.replace(
location.protocol + "//" + location.hostname + ":" + location.port,
""
)
try {
JSON.parse(localStorage.subscriptions).forEach(function(sub) {
if(sub.url == url) {
subscribeMethod = "localStorage"
}
})
}
catch(error) {}
if(useLocalStorage && subscribeMethod == "localStorage") {
// localstorage
var subList = JSON.parse(localStorage.subscriptions)
var index = 0;
subList.forEach(function(sub) {
if(sub.url == url) {
subList[index] = {}
}
index++;
})
localStorage.subscriptions = JSON.stringify(subList)
} else {
// cookie
var sub = ""
document.cookie.split(";").forEach(function(cookie) {
if(cookie.indexOf("sublist=") !== -1) {
sub = cookie.trimLeft().replace("sublist=", "")
}
})
sub = sub.replace(
encodeURIComponent($(".yt2009-channel-link").href.replace(
location.protocol + "//" + location.hostname + ":" + location.port,
""
))
+ "&" + encodeURIComponent($(".yt2009-channel-link").innerHTML)
+ ":",
""
)
document.cookie = "sublist="
+ sub
+ "; Path=/; expires=Fri, 31 Dec 2066 23:59:59 GMT"
}
}, false)
// subscribed with localStor age? if so, show the Unsubscribe btn
if(window.localStorage) {
JSON.parse(localStorage.subscriptions).forEach(function(sub) {
if(!sub.url) return;
var url = $(".yt2009-channel-link").href.replace(
location.protocol + "//" + location.hostname + ":" + location.port,
""
)
if(sub.url.indexOf(url) !== -1
|| url.indexOf(sub.url) !== -1) {
// susbribed!!!
$("#subscribeDiv").style.display = "none"
$("#unsubscribeDiv").style.display = "block"
}
})
}
/*
======
buttons above the video
======
*/
// widescreen
var widescreen = false;
var player_overlay = $("#watch-this-vid");
var player_element = $("#watch-this-vid #watch-player-div");
function switchWidescreen() {
widescreen = !widescreen;
if(widescreen) {
player_overlay.className = "yt-rounded widescreen"
player_element.className = "flash-player widescreen"
$("#watch-vid-title").className = "title longform widescreen"
$("#player-toggle-switch").className = "reverse-tooltip-wrapper watch-wide-mode"
localStorage.widescreenEnabled = true
fourthreechecked = false
try {annotation43()}catch(error) {}
} else {
player_overlay.className = "yt-rounded"
player_element.className = "flash-player"
$("#watch-vid-title").className = "title longform"
$("#player-toggle-switch").className = "reverse-tooltip-wrapper"
localStorage.removeItem("widescreenEnabled")
fourthreechecked = false
try {annotation43()}catch(error) {}
}
try {adjustSeekbarWidth();}catch(error) {}
}
$("#watch-longform-player").addEventListener("click", switchWidescreen, false)
if(localStorage && localStorage.widescreenEnabled) {
switchWidescreen()
}
// popout
$("#watch-longform-popup").addEventListener("click", function() {
var id = window.location.href.split("v=")[1].split("&")[0]
window.open("/embed/" + id)
}, false)
/*
======
playlisty
======
*/
if(document.querySelector("#watch-playlist-videos-panel")) {
// następny film
$("video").addEventListener("ended", function() {
var videoElements = []
var currentVideoIndex = 0;
var tempIndex = 0;
var s = document.querySelectorAll("#watch-playlist-videos-panel .video-entry")
for(var sel in s) {
try {
videoElements.push(s[sel])
if(s[sel].className == "video-entry watch-ppv-vid") {
currentVideoIndex = tempIndex
}
}
catch(error) {}
tempIndex++;
}
var nextVideo = videoElements[currentVideoIndex + 1]
if(!nextVideo || typeof(nextVideo) == "function") {
nextVideo = videoElements[0]
}
nextVideo.className = "video-entry playlist-entry-video-next"
window.location = $(".playlist-entry-video-next .video-thumb-link").href
}, false)
// refetch jak nie ma filmów zapisanych
if(document.querySelector(".yt2009_marking_fetch_playlist_client")) {
// request
var r = new XMLHttpRequest();
r.open("GET", "/refetch_playlist_watch")
r.setRequestHeader("source", location.href)
r.send(null)
r.addEventListener("load", function(e) {
// dopełnianie htmla wysłanego z serwera
$("#watch-playlist-discoverbox").innerHTML += r.responseText
}, false)
}
}
/*
======
takie fajne
======
*/
if(location.href.indexOf("&flip=1") !== -1
|| (new Date().getMonth() == 3
&& new Date().getDate() == 1
&& document.cookie.indexOf("unflip=1") == -1)) {
// css
var css = document.createElement("style")
css.innerHTML = ".flip {-webkit-transform: rotate(180deg);-moz-transform: rotate(180deg);transform: rotate(180deg);direction: rtl;}\
.ltr_override {direction: ltr !important;}\
.v90WrapperInner img {margin-bottom: -10px;margin-top: 0px;}\
#masthead-nav-main {width: 840px !important;}\
#masthead-utility.flip {margin-left: 700px !important;}\
.new-layout {width: 300px;height: 60px;background: #c6d7f3;border: 1px #a0b1dc solid;margin-bottom: 10px;}\
.new-layout h1 {width: 30px;font-size: 40px;margin: 10px 10px;float: left;}\
.new-layout h2, .new-layout a {color: #03c;cursor: pointer;}\
.new-layout h2 {margin-bottom: 15px;}\
"
document.body.appendChild(css);
// classname flip
var s = document.querySelectorAll("a, #logo, #masthead-nav-main, \
#masthead-nav-user, .util-a1, \
#watch-this-vid, #watch-vid-title, .video-mini-title,\
.video-view-count, .video-username, #watch-channel-stats,\
#ratingMessage, #watch-views-div, #watch-video-tags-div,\
.watch-comment-info, .watch-comment-body,\
.watch-comment-action, .yt-uix-expander-head, .yt-uix-expander-arrow,\
.links, .region-and-language-pickers, .progress_container")
for(var sel in s) {
try {
s[sel].className += " flip"
}
catch(error) {}
}
// classname ltr_override jako workaround dla niektórych
s = document.querySelectorAll("#watch-vid-title, #watch-views-div")
for(var sel in s) {
try {
s[sel].className += " ltr_override"
}
catch(error) {}
}
// usuwamy .flip dla elementów wziętych w jakimś
// selectorze który jest niepotrzebny
s = document.querySelectorAll("a[href=\"/my_videos_upload\"]")
for(var sel in s) {
try {
s[sel].className = s[sel].className.replace("flip", "")
}
catch(error) {}
}
// div.new-layout (tipy tego "nowego layoutu")
var tipWindowInner = "<h1 class='flip'>?</h1>\
<h2 onclick='new_layout_alert()'>Tips for viewing the new layout</h2>\
<a onclick='new_layout_leave()'>(I prefer the old-fashioned layout!)</a>"
$("#watch-other-vids").innerHTML = "<div class=\"new-layout\">" + tipWindowInner + "</div>" + $("#watch-other-vids").innerHTML
// ukrywanie yt2009-signin-hide
s = document.querySelectorAll(".yt2009-signin-hide")
for(var sel in s) {
try {
s[sel].className = s[sel].className.replace("yt2009-signin-hide", "hid")
}
catch(error) {}
}
// right -> left for .seek_btn
if(document.querySelector(".seek_btn")) {
var seekBtn = document.querySelector(".seek_btn");
seekBtn.style.right = "initial"
seekBtn.style.left = "-9px"
}
// login width
document.querySelector("#masthead-utility").style.display = "inline-block"
setTimeout(function() {
var loginWidth = document.querySelector("#masthead-utility")
.getBoundingClientRect().width;
document.querySelector("#masthead-utility")
.style.marginLeft = (960 - loginWidth - 15) + "px"
document.querySelector("#masthead-utility").style.display = ""
}, 50)
}
function new_layout_alert() {
window.open("/t/new_viewing_experience")
}
function new_layout_leave() {
if(new Date().getMonth() == 3) {
document.cookie = "unflip=1; Path=/; expires=Fri, 31 Dec 2066 23:59:59 GMT"
} else {
document.cookie = "unflip=1; Path=/; expires=Fri, 31 Dec 2008 23:59:59 GMT"
}
location.href = location.href.replace("&flip=1", "")
}
/*
======
video cards (favorite/share/playlists/flag)
======
*/
function switchWatchTab(tabName) {
// hide report menu if open
if(document.getElementById("watch-flag-menu")
&& $("#watch-flag-menu").className.indexOf("show") !== -1) {
$("#watch-flag-menu").className = ""
flagMenuShown = false;
}
// heading
$(".watch-tab.watch-tab-sel").className = "watch-tab"
$("#watch-tab-" + tabName).className = "watch-tab watch-tab-sel"
// content
var e = document.querySelectorAll(".watch-tab-body.watch-tab-sel")
for(var sel in e) {
try {
e[sel].className = "watch-tab-body"
}
catch(error) {}
}
$("#watch-tab-" + tabName + "-body").className = "watch-tab-body watch-tab-sel"
// custom per-card handling
switch(tabName) {
case "favorite": {
favorite_video();
break;
}
case "flag": {
loadFlagMenu()
break;
}
}
}
/*
======
favoriting videos
======
*/
// kod taktycznie z kanałów zabrany
// adding
function favorite_video() {
try {
relayFavorite()
}
catch(error) {}
var currentId = $(".email-video-url").value.split("?v=")[1]
var favorites = ""
if(useLocalStorage) {
// localstorage
if(!localStorage.favorites) {
localStorage.favorites = "[]"
}
favorites = JSON.parse(localStorage.favorites)
if(JSON.stringify(favorites).indexOf(currentId) == -1) {
favorites.unshift({
"id": currentId,
"title": $(".watch-vid-ab-title").innerHTML,
"views": $("#watch-view-count").innerHTML
})
// remove empty elements (removed using ui)
localStorage.favorites = JSON.stringify(favorites)
.split(",{}").join("")
}
} else {
// cookie
var videoString = encodeURIComponent(
$(".watch-vid-ab-title").innerHTML
+ "&" + $("#watch-view-count").innerHTML
+ "&" + currentId
)
document.cookie.split(";").forEach(function(cookie) {
if(cookie.indexOf("favorites=") !== -1) {
favorites = cookie.trimLeft().replace("favorites=", "")
}
})
if(favorites.indexOf(currentId) == -1) {
favorites = videoString + ":" + favorites
document.cookie = "favorites="
+ favorites
+ "; Path=/; expires=Fri, 31 Dec 2066 23:59:59 GMT"
}
}
$("#watch-add-faves").className += " hid"
$("#watch-remove-faves").className = "watch-action-result"
}
// removing
function favorite_undo() {
var currentId = $(".email-video-url").value.split("?v=")[1]
var favorites = ""
if(useLocalStorage) {
// localstorage
favorites = JSON.parse(localStorage.favorites)
var index = 0;
favorites.forEach(function(favorite) {
if(favorite.id == currentId) {
favorites[index] = {}
}
index++;
})
localStorage.favorites = JSON.stringify(favorites)
} else {
// cookie
var videoString = encodeURIComponent(
$("#watch-vid-title h1").innerHTML
+ "&" + $("#watch-view-count").innerHTML
+ "&" + currentId
) + ":"
document.cookie.split(";").forEach(function(cookie) {
if(cookie.indexOf("favorites=") !== -1) {
favorites = cookie.trimLeft().replace("favorites=", "")
}
})
favorites = favorites.replace(videoString, "")
document.cookie = "favorites="
+ favorites
+ "; Path=/; expires=Fri, 31 Dec 2066 23:59:59 GMT"
}
$("#watch-remove-faves").className += " hid"
$("#watch-add-faves").className = "watch-action-result"
}
/*
======
sharing
======
*/
// more options
function expandShare() {
$("#watch-sharetab-options #more-options").style.display = "none"
$("#watch-share-services-collapsed").style.display = "none"
$("#watch-share-services-expanded").style.display = ""
$("#watch-sharetab-options #fewer-options").style.display = ""
}
$("#watch-sharetab-options #more-options a").addEventListener("click", function() {
expandShare()
}, false)
// less options
$("#watch-sharetab-options #fewer-options a").addEventListener("click", function() {
$("#watch-sharetab-options #more-options").style.display = ""
$("#watch-share-services-collapsed").style.display = ""
$("#watch-share-services-expanded").style.display = "none"
$("#watch-sharetab-options #fewer-options").style.display = "none"
}, false)
/*
======
embeds
======
*/
var embed_settings = {
"color1": "b1b1b1",
"color2": "cfcfcf",
"width": "425",
"height": "344",
"flash_player": true,
"add_related_html": false,
"add_border": false,
"no_controls_fade": false
}
// załaduj
// load
function show_embed() {
$("#watch-customize-embed-div").style.display = "block"
if(!document.querySelector("#watch-customize-embed")) {
// request
var r = new XMLHttpRequest();
r.open("GET", "/embed_generate")
r.send(null)
r.addEventListener("load", function(e) {
$("#watch-customize-embed-div").innerHTML = r.responseText
}, false)
}
}
// update kodu
// code update
function embed_update_code() {
var codeblock = $("#embed_code")
var id = $("#watch-url-field").value.split("?v=")[1]
var site = location.protocol.replace(":", "") + '://' + location.host
var attributes = "?color1=" + embed_settings.color1 + "&color2=" + embed_settings.color2
if(embed_settings.add_related_html) {
attributes += "&server_fill_related=1"
}
if(!embed_settings.flash_player) {
$(".embed-no-controls-fade-check").className = "embed-no-controls-fade-check"
} else {
$(".embed-no-controls-fade-check").className = "embed-no-controls-fade-check hid"
}
if(embed_settings.no_controls_fade) {
attributes += "&no_controls_fade=1"
}
var code = '<iframe width="' + embed_settings.width
+ '" height="' + embed_settings.height
+ '" src="' + site + '/embed/' + id + attributes
+ '" allowfullscreen></iframe>' // html5
if(embed_settings.flash_player) {
// i gave up trying to format this
code = '<object width="' + embed_settings.width + '" height="' + embed_settings.height + '"><param name="movie" value="' + site + '/embedF/' + id + attributes + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="' + site + '/embedF/' + id + attributes + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="' + embed_settings.width + '" height="' + embed_settings.height + '"></embed></object>' // flash player
}
codeblock.value = code
}
// kolorki
// colors
function switchColorEmbed(element) {
document.querySelector("#watch-customize-embed-theme-swatches .selected").className = "embed-radio-link embed-sprite"
element.className += " selected"
// zmiana w embed_settings
embed_settings.color1 = element.getAttribute("data-color1")
embed_settings.color2 = element.getAttribute("data-color2")
embed_update_code();
}
// rozmiary
// sizes
function switchSize(width, height, element) {
embed_settings.width = width;
embed_settings.height = height;
document.querySelector(".watch-embed-radio-box.selected").className = "watch-embed-radio-box"
element.querySelector(".watch-embed-radio-box").className += " selected"
embed_update_code();
}
// wyłączanie
// hide the embed creator
function close_embed() {
$("#watch-customize-embed-div").style.display = "none"
}
/*
======
adding videos to playlists
======
*/
// sprawdzanie czy mamy jakieś playlisty
// check if we have any playlists
var plDropdown = $(".playlists-options")
function updatePlaylists() {
var optionsHTML = ""
if(localStorage.playlistsIndex) {
var playlists = JSON.parse(localStorage.playlistsIndex);
playlists.forEach(function(playlist) {
optionsHTML += "<option value=\"" + playlist.id + "\">" + playlist.name + "</option>"
})
// show the playlist create window if we don't have any
if(optionsHTML == "") {
$(".playlist-create").style.display = ""
$(".playlist-add").style.display = "none"
}
} else {
// create the localStorage playlists entry if we don't have any
localStorage.playlistsIndex = "[]"
$(".playlist-create").style.display = ""
$(".playlist-add").style.display = "none"
}
optionsHTML += "<option value=\"override-createnew\">[ New Playlist ]</option>"
plDropdown.innerHTML = optionsHTML
}
updatePlaylists();
var selectedOption = plDropdown.querySelectorAll("option")[0]
// pokazujemy/ukrywamy .playlist-create
// show/hide .playlist-create
plDropdown.addEventListener("change", function() {
// get selected option
var options = plDropdown.querySelectorAll("option")
for(var s in options) {
if(options[s].selected) {
selectedOption = options[s]
}
}
// show/hide
if(selectedOption.value == "override-createnew") {
$(".playlist-create").style.display = ""
$(".playlist-add").style.display = "none"
} else {
$(".playlist-create").style.display = "none"
$(".playlist-add").style.display = ""
}
}, false)
// add current video to the playlist
function addPlaylistVideo(playlistId) {
var currentId = $(".email-video-url").value.split("?v=")[1]
var dateAdded = new Date().toString().split(" ")
dateAdded.shift();
dateAdded = dateAdded.slice(0, 3)
dateAdded[1] += ","
dateAdded = dateAdded.join(" ")
var videoData = {
"id": currentId,
"title": $(".watch-vid-ab-title").innerHTML,
"date": dateAdded,
"rating": $("#ratingStars button").title,
"viewCount": $("#watch-view-count").innerHTML,
"time": $(".timer").innerHTML.split("/ ")[1]
}
// relay if used
relayPlaylistAdd(playlistId)
// show success tick
$("#addToPlaylistResult").style.display = "block"
$("#addToPlaylistDiv").style.display = "none"
var playlist = JSON.parse(localStorage["playlist-" + playlistId])
if(JSON.stringify(playlist).indexOf(currentId) == -1) {
playlist.unshift(videoData)
}
localStorage["playlist-" + playlistId] = JSON.stringify(playlist)
}
// pokaż z powrotem kartę dodawania do playlisty
// re-show an add to playlist card
function playlistResultBack() {
$("#addToPlaylistResult").style.display = "none"
$("#addToPlaylistDiv").style.display = "block"
}
// event listener: przycisk add na istniejącej playliście
// add button on an existing playlist
$("#playlist-add-btn").addEventListener("click", function() {
addPlaylistVideo(selectedOption.value);
}, false)
// event listener: przycisk add na new playlist
// add button on a new playlist
$("#playlist-create-btn").addEventListener("click", function() {
var playlistId = Math.floor(Date.now() / 1000)
localStorage["playlist-" + playlistId] = "[]"
addPlaylistVideo(playlistId)
var index = JSON.parse(localStorage.playlistsIndex);
index.unshift({"id": playlistId, "name": $(".playlist-name-input").value})
localStorage.playlistsIndex = JSON.stringify(index)
// update playlists dropdown to show our new playlist
updatePlaylists();
$(".playlist-create").style.display = "none"
$(".playlist-add").style.display = ""
selectedOption = plDropdown.querySelectorAll("option")[0]
}, false)
/*
======
video response
======
*/
// expander button
var responseExpander = $(".yt2009-video-response-expander")
var videoResponsesLoaded = false;
function videoResponsesExpand() {
if(responseExpander.parentNode.className
.indexOf("yt-uix-expander-collapsed") !== -1) {
responseExpander.parentNode
.className = responseExpander.parentNode.className.replace(
"collapsed",
"expanded"
)
if(!videoResponsesLoaded) {
loadVideoResponses();
}
} else {
responseExpander.parentNode
.className = responseExpander.parentNode.className.replace(
"expanded",
"collapsed"
)
}
}
responseExpander.addEventListener("click", videoResponsesExpand, false)
// fetch our response list
var videoResponseCount = 0;
var vrPage = 0;
function loadVideoResponses() {
var r = new XMLHttpRequest();
r.open("POST", "/videoresponse_load")
try {
r.send($(".watch-vid-ab-title").innerHTML)
r.addEventListener("load", function(e) {
videoResponsesLoaded = true;
$("#watch-video-responses-children").innerHTML = r.responseText
videoResponseCount = r.responseText.split("video-bar-item")
.length - 1;
}, false)
}
catch(error) {
videoResponsesLoaded = true;
$("#watch-video-responses-children").innerHTML = "h?"
console.log(error)
}
}
// video response navigation with arrows
var videoResponseMargin = 0;
function responseNavigateLeft() {
var tempMargin = 0;
vrPage--;
if(vrPage < 0) {