-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
YoutubeGeniusLyrics.user.js
2770 lines (2432 loc) · 88.8 KB
/
YoutubeGeniusLyrics.user.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
// ==UserScript==
// @name Youtube Genius Lyrics
// @namespace https://greasyfork.org/users/20068
// @description Shows lyrics/songtexts from genius.com on Youtube next to music videos
// @description:es Mostra la letra de genius.com de las canciones en Youtube junto a los vídeos musicales
// @description:de Zeigt den Songtext von genius.com neben Musikvideos auf Youtube
// @description:fr Présente les paroles des chansons de genius.com sur Youtube à côté des vidéos de musique.
// @description:pl Pokazuje teksty piosenek z genius.com na Youtube obok teledysków
// @description:pt Mostra letras de canções de genius.com no Youtube ao lado de vídeos de música
// @description:it Mostra i testi delle canzoni di genius.com su Youtube accanto ai video musicali
// @description:ja Youtube(ユーチューブ)では、ミュージックビデオの横に genius.com の歌詞が表示されます
// @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @copyright 2020, cuzi (https://github.com/cvzi)
// @author cuzi
// @icon https://raw.githubusercontent.com/hfg-gmuend/openmoji/master/color/72x72/E044.png
// @supportURL https://github.com/cvzi/Youtube-Genius-Lyrics-userscript/issues
// @version 10.10.1
// @require https://update.greasyfork.org/scripts/406698/GeniusLyrics.js
// @require https://cdnjs.cloudflare.com/ajax/libs/lz-string/1.5.0/lz-string.min.js
// @grant GM.xmlHttpRequest
// @grant GM.setValue
// @grant GM.getValue
// @grant GM.registerMenuCommand
// @grant GM_addValueChangeListener
// @connect genius.com
// @match https://www.youtube.com/*
// @match https://music.youtube.com/*
// @exclude https://www.youtube.com/embed/*
// @exclude https://www.youtube-nocookie.com/embed/*
// @exclude https://www.youtube.com/live_chat*
// @exclude https://www.youtube.com/live_chat_replay*
// @exclude /^https?://\S+\.(png|jpg|jpeg|gif|xml|svg|manifest|log|ini)[^\/]*$/
// ==/UserScript==
/*
Copyright (C) 2020 cuzi (cuzi@openmail.cc)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* global GM, genius, geniusLyrics, top, GM_addValueChangeListener */ // eslint-disable-line no-unused-vars, no-redeclare
/* jshint asi: true, esversion: 8 */
'use strict'
let genius
const SCRIPT_NAME = 'Youtube Genius Lyrics'
/** @type {globalThis.PromiseConstructor} */
const Promise = (async () => { })().constructor // YouTube polyfill to Promise in older browsers will make the feature being unstable.
let lyricsDisplayState = 'hidden'
let disableShowLyricsButton = false // hide if the page is confirmed as non-video page
let isYouTubeLive = false
let iframeBlankURL = null
const elmBuild = (tag, ...contents) => {
/** @type {HTMLElement} */
const elm = typeof tag === 'string' ? document.createElement(tag) : tag
for (const content of contents) {
if (!content || typeof content !== 'object' || (content instanceof Node)) { // eslint-disable-line no-undef
elm.append(content)
} else if (content.length > 0) {
elm.appendChild(elmBuild(...content))
} else if (content.style) {
Object.assign(elm.style, content.style)
} else if (content.classList) {
elm.classList.add(...content.classList)
} else if (content.attr) {
for (const [attr, val] of Object.entries(content.attr)) elm.setAttribute(attr, val)
} else {
Object.assign(elm, content)
}
}
return elm
}
const elmBuildNS = (tag, ...contents) => {
const ns = 'http://www.w3.org/2000/svg'
/** @type {Element} */
const elm = typeof tag === 'string' ? document.createElementNS(ns, tag) : tag
for (const content of contents) {
if (!content || typeof content !== 'object' || (content instanceof Node)) { // eslint-disable-line no-undef
elm.append(content)
} else if (content.length > 0) {
elm.appendChild(elmBuildNS(...content))
} else if (content.style) {
Object.assign(elm.style, content.style)
} else if (content.classList) {
elm.classList.add(...content.classList)
} else if (content.attr) {
for (const [attr, val] of Object.entries(content.attr)) elm.setAttributeNS(null, attr, val)
} else if (content.attrNS) {
for (const [attr, val] of Object.entries(content.attrNS)) elm.setAttributeNS(ns, attr, val)
} else {
Object.assign(elm, content)
}
}
return elm
}
function addCss () {
let style = document.querySelector('style#youtube_genius_lyrics_style')
if (style === null) {
style = document.createElement('style')
style.id = 'youtube_genius_lyrics_style'
style.textContent = `
body #mycaptchahint897454 {
z-index: 2070;
}
body #myoverlay7658438 {
z-index: 2050;
}
body #myconfigwin39457845 {
z-index: 2060;
}
html {
/* allow modification from external */
--ygl-container-right: var(--ytd-margin-6x, 4px);
--ygl-container-default-padding: 2px 6px;
--ygl-spinner-color: rgb(255, 255, 100);
}
#lyricscontainer {
box-sizing: border-box;
position: fixed;
right: 0;
margin: 0px;
padding: 0px;
background-color: white;
z-index: 2001;
font-size: 1.4rem;
border: 0;
border-radius: 0;
background: var(--ytd-searchbox-background);
color: var(--ytd-searchbox-text-color);
border: 1px solid var(--ytd-searchbox-legacy-border-color);
padding: var(--ygl-container-default-padding);
/* overrided by found/loading */
line-height: 100%;
width: calc(var(--ygl-container-width, 324px) - var(--ytd-margin-6x, 24px) + 7px);
right: calc(var(--ygl-container-right) - 1px);
}
#lyricsiframe {
opacity: 0.1;
transition: opacity 2s;
margin: 0;
padding: 0;
}
.lyricsnavbar {
font-size: 0.83em;
text-align: right;
padding-right: 10px;
background-color: #fafafa;
background: transparent;
color: inherit;
display: flex;
user-select: none;
flex-direction: row;
justify-content: end;
align-items: center;
align-items: stretch;
}
.lyricsnavbar span {
color: var(--yt-live-chat-primary-text-color);
text-decoration: none;
transition: color 400ms;
}
.lyricsnavbar span:hover {
color: var(--yt-live-chat-toast-action-color);
text-decoration: none;
}
body .loadingspinner {
/* override .loadingspinner */
color: currentColor;
font-size: 1em;
line-height: 2.5em;
--ygl-spinner-border-color: var(--yt-live-chat-secondary-text-color, #181818);
border-color: var(--ygl-spinner-color) var(--ygl-spinner-border-color) var(--ygl-spinner-border-color) var(--ygl-spinner-border-color);
}
.loadingspinnerholder {
z-index: 2050;
background-color: inherit;
cursor: progress;
}
.lorem br {
height: 0px;
line-height: 0;
font-size: 0;
padding: 0;
margin: 0;
}
.lorem {
--ygl-lorem-gray: var(--yt-live-chat-disabled-icon-button-color);
padding: 10px 0px 0px 15px;
font-size: 1.4rem;
line-height: 2.2rem;
letter-spacing: 0.3rem;
user-select: none !important;
pointer-events: none !important;
width: 100%;
}
/* this is only supported in modern browsers */
@property --num {
syntax: '<integer>';
initial-value: 0;
inherits: false;
}
@keyframes loadingLorem {
0% {
--num: 0;
}
99% {
--num: 8;
}
100% {
--num: 0;
}
}
.lorem-scroll {
--num: 0;
animation: loadingLorem 4s ease infinite;
margin-top: calc(-13rem - 2rem*var(--num, 0));
contain: content;
width: 96%;
overflow: hidden;
}
.lorem .white {
background-color: inherit;
color: white;
user-select: none !important;
}
.lorem .gray {
background-color: var(--ygl-lorem-gray);
color: transparent;
user-select: none !important;
}
#showlyricsbutton {
position: fixed; /* youtube's unknown layout bug - the 'absolute' position top would offset upwards by around 80px after the page is changed */
/* note: youtube layouts are inside ytd-watch-flexy by default; therefore the 'absolute' layout for elements outside ytd-watch-flexy is not guaranteed */
z-index: 3000;
right: 4px;
cursor: pointer;
border-radius: 50%;
margin: auto;
padding: 0px 1px;
text-align: center;
font-size: 15px;
line-height: 14px;
background: #ffff64;
color: #000a;
padding: 9px;
display: flex;
align-content: center;
align-items: center;
justify-content: center;
contain: strict;
opacity: 0.7;
transition: opacity 50ms;
/*
--ytd-masthead-height
--ytd-toolbar-height
--ytd-watch-flexy-masthead-height
*/
top: var(--ytd-toolbar-height, var(--ytd-masthead-height, var(--ytd-watch-flexy-masthead-height, 56px)));
}
#showlyricsbutton.hide-during-ytlive {
display: none;
}
#showlyricsbutton:hover {
opacity: 1.0;
}
/* :fullscreen shall be sufficient for modern browsers */
/* see more at https://caniuse.com/mdn-css_selectors_fullscreen */
/* just except opera ? */
:fullscreen #showlyricsbutton, :fullscreen #lyricscontainer {
display: none;
}
:-moz-full-screen #showlyricsbutton {
display: none;
}
:-webkit-full-screen #showlyricsbutton {
display: none;
}
#showlyricsbutton::before {
color: inherit;
content: 'G';
position: absolute;
display: block;
pointer-events: none;
user-select: none;
touch-action: none;
}
.youtube-genius-lyrics-search-container {
border: 1px solid black;
border-radius: 3px;
--ygl-lyricscontainer-padding: 0px 10px;
}
span.youtube-genius-lyrics-results-line-separator,
span.youtube-genius-lyrics-found-separator {
padding: 0px 3px;
}
.youtube-genius-lyrics-results-container {
border: 1px solid black;
border-radius: 3px;
}
ol.youtube-genius-lyrics-results-tracklist {
list-style: none;
width: 99%;
font-size: 1.15em;
}
li.youtube-genius-lyrics-results-li {
cursor: pointer;
transition: background-color 0.2s;
margin: 2px;
border-radius: 3px;
padding: 8px 6px;
}
span.youtube-genius-lyrics-results-hide-btn,
span.youtube-genius-lyrics-results-back-btn,
span.youtube-genius-lyrics-found-hide-btn,
span.youtube-genius-lyrics-found-back-btn {
cursor: pointer;
}
li.youtube-genius-lyrics-results-li div.onhover {
display: none;
margin-top: -0.25em;
}
li.youtube-genius-lyrics-results-li div.onout {
display: block;
}
li.youtube-genius-lyrics-results-li:hover div.onhover {
display: block;
}
li.youtube-genius-lyrics-results-li:hover div.onout {
display: none;
}
ol.youtube-genius-lyrics-results-tracklist {
font-size: var(--ytd-link-font-size);
}
li.youtube-genius-lyrics-results-li {
/* --tyt-tracklist-li-background: var(--yt-live-chat-slider-container-color); */
--tyt-tracklist-li-background: var(--ytd-searchbox-legacy-button-color);
background-color: var(--tyt-tracklist-li-background);
color: var(--ytd-searchbox-text-color);
border: 1px solid var(--ytd-searchbox-legacy-border-color);
list-style: none;
/*
color: var(--yt-live-chat-secondary-text-color);
--tyt-tracklist-li-background: var(--ytd-searchbox-legacy-button-color);
--tyt-tracklist-li-background: var(--yt-spec-commerce-tonal-hover);
*/
opacity: 0.9;
}
li.youtube-genius-lyrics-results-li:hover {
--tyt-tracklist-li-background: var(--yt-live-chat-button-dark-background-color);
/* --tyt-tracklist-li-background: var(--yt-live-chat-slider-active-color); */
border: 1px solid var(--ytd-searchbox-legacy-button-hover-border-color);
opacity: 1.0;
}
li.youtube-genius-lyrics-results-li.lyrics-minor-result {
font-size: 80%;
opacity: 0.6;
}
li.youtube-genius-lyrics-results-li.lyrics-minor-result:hover {
opacity: 0.7;
}
li.youtube-genius-lyrics-results-li * {
pointer-events: none;
}
li.youtube-genius-lyrics-results-li div.onhover span {
color: black;
font-size: 2.0em;
}
li.youtube-genius-lyrics-results-li div.onout span {
font-size: 1.5em;
}
body #lyricscontainer ol.tracklist li .onhover,
body #lyricscontainer ol.tracklist li .onout {
display: none;
}
body #lyricscontainer>ol.tracklist {
max-width: 480px;
min-width: 280px;
width: auto;
}
span.youtube-genius-lyrics-found-config-btn {
cursor: pointer;
}
span.youtube-genius-lyrics-found-wonglyrics-btn {
cursor: pointer;
}
html {
--ygl-theater-player-max-width: '--NULL--';
--ygl-theater-player-float: '--NULL--';
}
html[youtube-genius-lyrics-container="found"] ytd-watch-flexy[theater],
html[youtube-genius-lyrics-container="loading"] ytd-watch-flexy[theater] {
--ygl-theater-player-max-width: 50%;
--ygl-theater-player-float: right;
}
ytd-watch-flexy[theater] #movie_player .ytp-left-controls {
max-width: var(--ygl-theater-player-max-width);
}
ytd-watch-flexy[theater] #movie_player .ytp-right-controls {
float: var(--ygl-theater-player-float);
}
html[youtube-genius-lyrics-container="found"] ytd-watch-flexy[theater] #movie_player video[src],
html[youtube-genius-lyrics-container="loading"] ytd-watch-flexy[theater] #movie_player video[src] {
left: 0 !important;
}
html[youtube-genius-lyrics-container] #showlyricsbutton {
display: none;
}
.youtube-genius-lyrics-search-input {
-webkit-appearance: none;
appearance: none;
-webkit-font-smoothing: antialiased;
background-color: transparent;
border: none;
box-shadow: none;
color: inherit;
font-family: Roboto, Noto, sans-serif;
text-align: inherit;
border: 1px solid currentColor;
box-sizing: border-box;
padding: 1px 0;
margin: 0;
outline-offset: 0px;
outline: none;
padding: 1px 6px;
font-size: 80%;
background-color: var(--yt-emoji-picker-search-background-color);
border-color: currentColor;
margin: 0 6px 0 6px;
flex: 1;
}
[dark] .youtube-genius-lyrics-search-input {
border-color: transparent;
}
.youtube-genius-lyrics-search-input:not(:focus)::placeholder {
border-color: var(--yt-emoji-picker-search-placeholder-color);
color: var(--yt-emoji-picker-search-placeholder-color);
}
.youtube-genius-lyrics-search-input.placeholder-lastfetch:not(:focus)::placeholder,
.youtube-genius-lyrics-search-input.placeholder-lastfetch:focus::placeholder{
color: var(--yt-spec-text-secondary);
font-weight: bold;
}
.youtube-genius-lyrics-search-input:focus,
.youtube-genius-lyrics-search-input:active {
border-color: var(--paper-checkbox-checked-color);
}
span.youtube-genius-lyrics-search-search-btn {
cursor: pointer;
vertical-align: middle;
align-self: center;
display: inline-flex;
margin-left: 0;
margin-right: 8px;
}
.youtube-genius-lyrics-search-search-btn:hover {
color: var(--yt-live-chat-toast-action-color);
}
span.youtube-genius-lyrics-search-search-btn > svg {
fill: currentColor;
pointer-events: none;
touch-action: none;
user-select: none;
}
@keyframes inputNoResult {
0% {
transform: translateX(0px);
}
25% {
transform: translateX(-6px);
}
50% {
transform: translateX(0px);
}
75% {
transform: translateX(6px);
}
100% {
transform: translateX(6px);
}
}
.youtube-genius-lyrics-search-input.lyrics-input-noresult {
border-color: red;
opacity: 0.75;
animation: inputNoResult 140ms;
animation-iteration-count: 3;
}
.lyrics-searching {
/* dont make animation here */
filter: blur(0.7px);
opacity: 0.85;
pointer-events: none;
}
html {
--ygl-lyricsiframe-flex: '--NULL--';
--ygl-lyricscontainer-bottom: '--NULL--';
--ygl-lyricscontainer-border-radius: '--NULL--';
--ygl-lyricscontainer-padding: '--NULL--';
--ygl-lyricscontainer-display: '--NULL--';
--ygl-lyricscontainer-flex-direction: '--NULL--';
--ygl-lyricscontainer-bar-padding: '--NULL--';
}
.youtube-genius-lyrics-loading-container,
.youtube-genius-lyrics-found-container {
--ygl-lyricsiframe-flex: 1;
--ygl-lyricscontainer-bottom: 4px;
/* allow override */
--ygl-lyricscontainer-border-radius: 0px 0px 8px 8px;
/* allow override */
--ygl-lyricscontainer-padding: 0px 8px 8px 8px;
/* allow override */
--ygl-lyricscontainer-display: flex;
--ygl-lyricscontainer-flex-direction: column;
--ygl-lyricscontainer-bar-padding: 4px 6px;
}
.lyricsnavbar {
padding: var(--ygl-lyricscontainer-bar-padding);
}
body #lyricscontainer {
display: var(--ygl-lyricscontainer-display);
flex-direction: var(--ygl-lyricscontainer-flex-direction);
bottom: var(--ygl-lyricscontainer-bottom);
border-radius: var(--ygl-lyricscontainer-border-radius);
padding: var(--ygl-lyricscontainer-padding);
}
#lyricsiframe {
flex: var(--ygl-lyricsiframe-flex);
}
#lyricscontainer.youtube-genius-lyrics-loading-container #lyricsiframe {
position: absolute;
width: 80%;
height: 80%;
transform: translate(10%, 10%);
}
#lyricscontainer.youtube-genius-lyrics-loading-container .loadingspinnerholder {
position: relative;
width: auto !important;
top: auto !important;
display: flex;
flex-direction: column;
align-content: center;
align-items: center;
justify-content: center;
overflow: hidden;
contain: content;
}
.youtube-genius-lyrics-search-container {
--ygl-lyricscontainer-display: flex;
--ygl-lyricscontainer-flex-direction: row;
align-items: center;
}
.youtube-genius-lyrics-results-container {
--ygl-lyricscontainer-padding: 2px 6px 6px 6px;
}
.youtube-genius-lyrics-search-hide-btn,
.youtube-genius-lyrics-results-back-btn,
.youtube-genius-lyrics-results-hide-btn,
.youtube-genius-lyrics-results-config-btn,
.youtube-genius-lyrics-search-config-btn {
border: 1px solid var(--ytd-searchbox-background);
margin: 3px;
font-size: 0.83em;
color: var(--yt-live-chat-primary-text-color);
text-decoration: none;
transition: color 400ms;
cursor: pointer;
}
.youtube-genius-lyrics-search-hide-btn:hover,
.youtube-genius-lyrics-results-back-btn:hover,
.youtube-genius-lyrics-results-hide-btn:hover,
.youtube-genius-lyrics-results-config-btn:hover,
.youtube-genius-lyrics-search-config-btn:hover {
color: var(--yt-live-chat-toast-action-color);
text-decoration: none;
}
.youtube-genius-lyrics-results-line-separator {
font-size: 0.83em;
color: var(--yt-live-chat-primary-text-color);
}
.youtube-genius-lyrics-search-label {
font-family: cursive;
padding: 0px 6px;
color: var(--yt-live-chat-primary-text-color);
font-size: 80%;
}
[dark] .youtube-genius-lyrics-search-label {
color: var(--yt-live-chat-author-chip-owner-background-color);
}
.youtube-genius-lyrics-tracklist-info-container{
display: flex;
column-gap: 6px;
flex-direction: row;
flex-wrap: nowrap;
}
.youtube-genius-lyrics-tracklist-info-primary{
flex:1;
}
.youtube-genius-lyrics-tracklist-info-secondary{
text-transform: uppercase;
font-style: italic;
}
`
document.head.appendChild(style)
}
}
const { requestAnimationFrame, setTimeout, setInterval, clearTimeout, clearInterval } = (() => { // eslint-disable-line no-unused-vars
let win = typeof unsafeWindow !== 'undefined' ? unsafeWindow : window // eslint-disable-line no-undef
let removeIframeFn = null
try {
const frameId = 'vanillajs-iframe-v1'
let frame = document.getElementById(frameId)
if (!frame) {
frame = document.createElement('iframe')
frame.id = frameId
const blobURL = typeof webkitCancelAnimationFrame === 'function' ? (frame.src = URL.createObjectURL(new Blob([], { type: 'text/html' }))) : null // avoid Brave Crash
frame.sandbox = 'allow-same-origin' // script cannot be run inside iframe but API can be obtained from iframe
let n = document.createElement('noscript') // wrap into NOSCRPIT to avoid reflow (layouting)
n.appendChild(frame)
const root = document.documentElement
if (root) {
root.appendChild(n)
if (blobURL) Promise.resolve().then(() => URL.revokeObjectURL(blobURL))
removeIframeFn = (setTimeout) => {
const removeIframeOnDocumentReady = (e) => {
e && win.removeEventListener('DOMContentLoaded', removeIframeOnDocumentReady, false)
e = n
n = win = removeIframeFn = 0
setTimeout ? setTimeout(() => e.remove(), 200) : e.remove()
}
if (!setTimeout || document.readyState !== 'loading') {
removeIframeOnDocumentReady()
} else {
win.addEventListener('DOMContentLoaded', removeIframeOnDocumentReady, false)
}
}
}
}
const fc = frame ? frame.contentWindow : null
if (fc) {
try {
const { requestAnimationFrame, setTimeout, setInterval, clearTimeout, clearInterval } = fc
const res = { requestAnimationFrame, setTimeout, setInterval, clearTimeout, clearInterval }
for (const k in res) res[k] = res[k].bind(win) // necessary
if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn)
return res
} catch (e) {
if (removeIframeFn) removeIframeFn()
}
}
} catch (e) {
console.warn(e)
}
// since the mechanism does not utilize async/await, use the old method as fallback.
function isFakeWindow () {
// window is not window in Spotify Web App
return (window instanceof window.constructor) === false
}
/**
* getTrueWindow
* @returns {Window}
*/
function getTrueWindow () {
// this can bypass Spotify's window Proxy Object and obtain the original window object
try {
return new Function('return window')() // eslint-disable-line no-new-func
} catch (e) {
console.warn('the actual window object cannot be obtained.', e) // e.g. YouTube Music
return window // fallback
}
}
let trueWindow = isFakeWindow() ? getTrueWindow() : win
const { requestAnimationFrame, setTimeout, setInterval, clearTimeout, clearInterval } = trueWindow
const res = { requestAnimationFrame, setTimeout, setInterval, clearTimeout, clearInterval }
for (const k in res) res[k] = res[k].bind(trueWindow) // necessary
trueWindow = null
if (removeIframeFn) Promise.resolve(res.setTimeout).then(removeIframeFn)
return res
})()
function appendElements (target, elements) {
if (typeof target.append === 'function') {
target.append(...elements)
} else {
for (const element of elements) {
target.appendChild(element)
}
}
}
const removeElements = (typeof window.DocumentFragment.prototype.append === 'function')
? function (elements) {
document.createDocumentFragment().append(...elements)
}
: function (elements) {
for (const element of elements) {
element.remove()
}
}
function getMastheadHeight () {
// can be replaced by youtube css custom properties
const masthead = document.querySelector('ytd-masthead#masthead')
return masthead.getBoundingClientRect().height
}
function calcContainerWidthTop () {
let w
const upnext = document.querySelector('#secondary #secondary-inner') || document.getElementById('upnext')
const playlist = document.querySelector('ytd-playlist-panel-renderer#playlist')
const video = document.querySelector('ytd-watch-flexy div#primary video')
if (upnext && upnext.getBoundingClientRect().left > 0) {
w = window.innerWidth - upnext.getBoundingClientRect().left - 5
} else if (playlist && playlist.getBoundingClientRect().left > 0) {
w = window.innerWidth - playlist.getBoundingClientRect().left - 5
} else if (video) {
w = window.innerWidth - 1.02 * video.getBoundingClientRect().right
} else {
w = window.innerWidth * 0.45
}
w = Math.min(window.innerWidth * 0.75, w)
const top = getMastheadHeight()
const isTheatherView = !!document.querySelector('ytd-watch-flexy[theater]')
if (isTheatherView) {
return {
top,
width: parseInt(0.3 * document.querySelector('#columns').clientWidth),
isTheatherView
}
} else {
return {
top,
width: w,
isTheatherView
}
}
}
function setFrameDimensions (container, iframe, bar) { // eslint-disable-line no-unused-vars
// if (!container || !iframe || !bar) {
// console.warn('elements not found in setFrameDimensions()')
// return
// }
// const bar = container.querySelector('.lyricsnavbar')
// const width = iframe.style.width = container.clientWidth - 1 + 'px'
// const height = iframe.style.height = window.innerHeight - bar.clientHeight - getMastheadHeight() + 'px'
/*
iframe.style.width = container.clientWidth - 1 + 'px'
iframe.style.height = window.innerHeight - bar.clientHeight - getMastheadHeight() + 'px'
if (genius.option.themeKey === 'spotify') {
iframe.style.backgroundColor = '#181818'
bar.style.backgroundColor = '#181818'
} else {
iframe.style.backgroundColor = ''
}
*/
// return [width, height]
}
let lastResizeDT = 0
function onResize () {
const tdt = Date.now()
lastResizeDT = tdt
setTimeout(function () {
if (tdt === lastResizeDT) {
resize()
}
}, 600)
}
function resize () {
const container = document.getElementById('lyricscontainer')
if (!container) {
return
}
const { top, width } = calcContainerWidthTop()
// container.style.top = `${top}px`
container.style.setProperty('--ygl-container-top', `${top}px`)
container.style.top = 'var(--ytd-toolbar-height, var(--ytd-masthead-height, var(--ytd-watch-flexy-masthead-height, var(--ygl-container-top))))' // compatible with YouTube Live Borderless
container.style.setProperty('--ygl-container-width', `${width}px`)
// const iframe = document.getElementById('lyricsiframe')
// if (iframe) {
// const bar = container.querySelector('.lyricsnavbar')
// if (bar) {
// setFrameDimensions(container, iframe, bar)
// }
// }
}
function getCleanLyricsContainer () {
let container = null
const { top, width } = calcContainerWidthTop()
if (!document.getElementById('lyricscontainer')) {
container = document.createElement('div')
container.id = 'lyricscontainer'
document.body.appendChild(container)
} else {
container = document.getElementById('lyricscontainer')
container.textContent = ''
container.className = ''
container.style = ''
}
// container.style.top = `${top}px`
container.style.setProperty('--ygl-container-top', `${top}px`)
container.style.top = 'var(--ytd-toolbar-height, var(--ytd-masthead-height, var(--ytd-watch-flexy-masthead-height, var(--ygl-container-top))))' // compatible with YouTube Live Borderless
container.style.setProperty('--ygl-container-width', `${width}px`)
document.body.appendChild(container)
const result = document.getElementById('lyricscontainer')
if (result !== container) {
console.warn(SCRIPT_NAME + ' getCleanLyricsContainer() Could not insert the element correctly')
}
return result
}
function hideLyrics () {
if (document.querySelector('.loadingspinnerholder') !== null) {
genius.f.cancelLoading()
}
const elementsToBeRemoved = [...document.querySelectorAll('.loadingspinnerholder')]
const lyricscontainer = document.getElementById('lyricscontainer')
if (lyricscontainer) {
elementsToBeRemoved.push(lyricscontainer)
}
document.documentElement.removeAttribute('youtube-genius-lyrics-container')
const isHiding = elementsToBeRemoved.length > 0
removeElements(elementsToBeRemoved)
addLyricsButton()
return isHiding
}
async function showLyricsButtonClicked () {
removeLyricsButton()
genius.option.autoShow = true // Temporarily enable showing lyrics automatically on song change
addLyrics(true)
}
function addLyricsButton () {
if (disableShowLyricsButton === true) return
if (document.getElementById('showlyricsbutton')) {
return
}
// const top = getMastheadHeight()