-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
content.js
2772 lines (2564 loc) · 91.9 KB
/
content.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 Control Panel for YouTube
// @description Gives you more control over YouTube by adding missing options and UI improvements
// @icon https://raw.githubusercontent.com/insin/control-panel-for-youtube/master/icons/icon32.png
// @namespace https://jbscript.dev/control-panel-for-youtube
// @match https://www.youtube.com/*
// @match https://m.youtube.com/*
// @exclude https://www.youtube.com/embed/*
// @version 9
// ==/UserScript==
let debug = false
let debugManualHiding = false
let mobile = location.hostname == 'm.youtube.com'
let desktop = !mobile
/** @type {import("./types").Version} */
let version = mobile ? 'mobile' : 'desktop'
let lang = mobile ? document.body.lang : document.documentElement.lang
let loggedIn = /(^|; )SID=/.test(document.cookie)
function log(...args) {
if (debug) {
console.log('🙋', ...args)
}
}
function warn(...args) {
if (debug) {
console.log('❗️', ...args)
}
}
//#region Default config
/** @type {import("./types").SiteConfig} */
let config = {
enabled: true,
version,
disableAutoplay: true,
disableHomeFeed: false,
hiddenChannels: [],
hideChannels: true,
hideComments: false,
hideHiddenVideos: true,
hideHomeCategories: false,
hideLive: false,
hideMetadata: false,
hideMixes: false,
hideNextButton: true,
hideRelated: false,
hideShareThanksClip: false,
hideShorts: true,
hideSponsored: true,
hideStreamed: false,
hideSuggestedSections: true,
hideUpcoming: false,
hideVoiceSearch: false,
hideWatched: true,
hideWatchedThreshold: '80',
redirectShorts: true,
skipAds: true,
// Desktop only
downloadTranscript: true,
fullSizeTheaterMode: false,
hideChat: false,
hideEndCards: false,
hideEndVideos: true,
hideMerchEtc: true,
hideMiniplayerButton: false,
hideSubscriptionsLatestBar: false,
minimumGridItemsPerRow: 'auto',
searchThumbnailSize: 'medium',
tidyGuideSidebar: false,
// Mobile only
hideExploreButton: true,
hideOpenApp: true,
hideSubscriptionsChannelList: false,
mobileGridView: true,
}
//#endregion
//#region Locales
/**
* @type {Record<string, import("./types").Locale>}
*/
const locales = {
'en': {
CLIP: 'Clip',
DOWNLOAD: 'Download',
FOR_YOU: 'For you',
HIDE_CHANNEL: 'Hide channel',
MIXES: 'Mixes',
MUTE: 'Mute',
NEXT_VIDEO: 'Next video',
OPEN_APP: 'Open App',
PREVIOUS_VIDEO: 'Previous video',
SHARE: 'Share',
SHORTS: 'Shorts',
STREAMED_TITLE: 'views Streamed',
TELL_US_WHY: 'Tell us why',
THANKS: 'Thanks',
UNHIDE_CHANNEL: 'Unhide channel',
},
'ja-JP': {
CLIP: 'クリップ',
DOWNLOAD: 'オフライン',
FOR_YOU: 'あなたへのおすすめ',
HIDE_CHANNEL: 'チャンネルを隠す',
MIXES: 'ミックス',
MUTE: 'ミュート(消音)',
NEXT_VIDEO: '次の動画',
OPEN_APP: 'アプリを開く',
PREVIOUS_VIDEO: '前の動画',
SHARE: '共有',
SHORTS: 'ショート',
STREAMED_TITLE: '前 に配信済み',
TELL_US_WHY: '理由を教えてください',
UNHIDE_CHANNEL: 'チャンネルの再表示',
}
}
/**
* @param {import("./types").LocaleKey} code
* @returns {string}
*/
function getString(code) {
return (locales[lang] || locales['en'])[code] || locales['en'][code];
}
//#endregion
const undoHideDelayMs = 5000
const Classes = {
HIDE_CHANNEL: 'cpfyt-hide-channel',
HIDE_HIDDEN: 'cpfyt-hide-hidden',
HIDE_OPEN_APP: 'cpfyt-hide-open-app',
HIDE_STREAMED: 'cpfyt-hide-streamed',
HIDE_WATCHED: 'cpfyt-hide-watched',
HIDE_SHARE_THANKS_CLIP: 'cpfyt-hide-share-thanks-clip',
}
const Svgs = {
DELETE: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" focusable="false" style="pointer-events: none; display: block; width: 100%; height: 100%;"><path d="M11 17H9V8h2v9zm4-9h-2v9h2V8zm4-4v1h-1v16H6V5H5V4h4V3h6v1h4zm-2 1H7v15h10V5z"></path></svg>',
RESTORE: '<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 -960 960 960" width="24" focusable="false" style="pointer-events: none; display: block; width: 100%; height: 100%;"><path d="M460-347.692h40V-535.23l84 83.538L612.308-480 480-612.308 347.692-480 376-451.692l84-83.538v187.538ZM304.615-160Q277-160 258.5-178.5 240-197 240-224.615V-720h-40v-40h160v-30.77h240V-760h160v40h-40v495.385Q720-197 701.5-178.5 683-160 655.385-160h-350.77ZM680-720H280v495.385q0 9.23 7.692 16.923Q295.385-200 304.615-200h350.77q9.23 0 16.923-7.692Q680-215.385 680-224.615V-720Zm-400 0v520-520Z"/></svg>',
}
//#region State
/** @type {() => void} */
let onAdRemoved
/** @type {Map<string, import("./types").Disconnectable>} */
let globalObservers = new Map()
/** @type {import("./types").Channel} */
let lastClickedChannel
/** @type {HTMLElement} */
let $lastClickedElement
/** @type {() => void} */
let onDialogClosed
/** @type {Map<string, import("./types").Disconnectable>} */
let pageObservers = new Map()
//#endregion
//#region Utility functions
function addStyle(css = '') {
let $style = document.createElement('style')
$style.dataset.insertedBy = 'control-panel-for-youtube'
if (css) {
$style.textContent = css
}
document.head.appendChild($style)
return $style
}
function currentUrlChanges() {
let currentUrl = getCurrentUrl()
return () => currentUrl != getCurrentUrl()
}
/**
* @param {string} str
* @return {string}
*/
function dedent(str) {
str = str.replace(/^[ \t]*\r?\n/, '')
let indent = /^[ \t]+/m.exec(str)
if (indent) str = str.replace(new RegExp('^' + indent[0], 'gm'), '')
return str.replace(/(\r?\n)[ \t]+$/, '$1')
}
/** @param {Map<string, import("./types").Disconnectable>} observers */
function disconnectObservers(observers, scope) {
if (observers.size == 0) return
log(
`disconnecting ${observers.size} ${scope} observer${s(observers.size)}`,
Array.from(observers.keys())
)
logObserverDisconnects = false
for (let observer of observers.values()) observer.disconnect()
logObserverDisconnects = true
}
function getCurrentUrl() {
return location.origin + location.pathname + location.search
}
/**
* @typedef {{
* name?: string
* stopIf?: () => boolean
* timeout?: number
* context?: Document | HTMLElement
* }} GetElementOptions
*
* @param {string} selector
* @param {GetElementOptions} options
* @returns {Promise<HTMLElement | null>}
*/
function getElement(selector, {
name = null,
stopIf = null,
timeout = Infinity,
context = document,
} = {}) {
return new Promise((resolve) => {
let startTime = Date.now()
let rafId
let timeoutId
function stop($element, reason) {
if ($element == null) {
warn(`stopped waiting for ${name || selector} after ${reason}`)
}
else if (Date.now() > startTime) {
log(`${name || selector} appeared after`, Date.now() - startTime, 'ms')
}
if (rafId) {
cancelAnimationFrame(rafId)
}
if (timeoutId) {
clearTimeout(timeoutId)
}
resolve($element)
}
if (timeout !== Infinity) {
timeoutId = setTimeout(stop, timeout, null, `${timeout}ms timeout`)
}
function queryElement() {
let $element = context.querySelector(selector)
if ($element) {
stop($element)
}
else if (stopIf?.() === true) {
stop(null, 'stopIf condition met')
}
else {
rafId = requestAnimationFrame(queryElement)
}
}
queryElement()
})
}
/** @param {import("./types").Channel} channel */
function isChannelHidden(channel) {
return config.hiddenChannels.some((hiddenChannel) =>
channel.url && hiddenChannel.url ? channel.url == hiddenChannel.url : hiddenChannel.name == channel.name
)
}
let logObserverDisconnects = true
/**
* Convenience wrapper for the MutationObserver API:
*
* - Defaults to {childList: true}
* - Observers have associated names
* - Optional leading call for callback
* - Observers are stored in a scope object
* - Observers already in the given scope will be disconnected
* - onDisconnect hook for post-disconnect logic
*
* @param {Node} $target
* @param {MutationCallback} callback
* @param {{
* leading?: boolean
* logElement?: boolean
* name: string
* observers: Map<string, import("./types").Disconnectable> | Map<string, import("./types").Disconnectable>[]
* onDisconnect?: () => void
* }} options
* @param {MutationObserverInit} mutationObserverOptions
* @return {import("./types").CustomMutationObserver}
*/
function observeElement($target, callback, options, mutationObserverOptions = {childList: true}) {
let {leading, logElement, name, observers, onDisconnect} = options
let observerMaps = Array.isArray(observers) ? observers : [observers]
/** @type {import("./types").CustomMutationObserver} */
let observer = Object.assign(new MutationObserver(callback), {name})
let disconnect = observer.disconnect.bind(observer)
let disconnected = false
observer.disconnect = () => {
if (disconnected) return
disconnected = true
disconnect()
for (let map of observerMaps) map.delete(name)
onDisconnect?.()
if (logObserverDisconnects) {
log(`disconnected ${name} observer`)
}
}
if (observerMaps[0].has(name)) {
log(`disconnecting existing ${name} observer`)
logObserverDisconnects = false
observerMaps[0].get(name).disconnect()
logObserverDisconnects = true
}
for (let map of observerMaps) map.set(name, observer)
if (logElement) {
log(`observing ${name}`, $target)
} else {
log(`observing ${name}`)
}
observer.observe($target, mutationObserverOptions)
if (leading) {
callback([], observer)
}
return observer
}
/**
* Uses a MutationObserver to wait for a specific element. If found, the
* observer will be disconnected. If the observer is disconnected first, the
* resolved value will be null.
*
* @param {Node} $target
* @param {(mutations: MutationRecord[]) => HTMLElement} getter
* @param {{
* logElement?: boolean
* name: string
* targetName: string
* observers: Map<string, import("./types").Disconnectable>
* }} options
* @param {MutationObserverInit} [mutationObserverOptions]
* @return {Promise<HTMLElement>}
*/
function observeForElement($target, getter, options, mutationObserverOptions) {
let {targetName, ...observeElementOptions} = options
return new Promise((resolve) => {
let found = false
let startTime = Date.now()
observeElement($target, (mutations, observer) => {
let $result = getter(mutations)
if ($result) {
found = true
if (Date.now() > startTime) {
log(`${targetName} appeared after`, Date.now() - startTime, 'ms')
}
observer.disconnect()
resolve($result)
}
}, {
...observeElementOptions,
onDisconnect() {
if (!found) resolve(null)
},
}, mutationObserverOptions)
})
}
/**
* @param {number} n
* @returns {string}
*/
function s(n) {
return n == 1 ? '' : 's'
}
//#endregion
//#region CSS
const configureCss = (() => {
/** @type {HTMLStyleElement} */
let $style
return function configureCss() {
if (!config.enabled) {
log('removing stylesheet')
$style?.remove()
$style = null
return
}
let cssRules = []
let hideCssSelectors = []
if (config.skipAds) {
// Display a black overlay while ads are playing
cssRules.push(`
.ytp-ad-player-overlay, .ytp-ad-player-overlay-layout, .ytp-ad-action-interstitial {
background: black;
z-index: 10;
}
`)
// Hide elements while an ad is showing
hideCssSelectors.push(
// Thumbnail for cued ad when autoplay is disabled
'#movie_player.ad-showing .ytp-cued-thumbnail-overlay-image',
// Ad video
'#movie_player.ad-showing video',
// Ad title
'#movie_player.ad-showing .ytp-chrome-top',
// Ad overlay content
'#movie_player.ad-showing .ytp-ad-player-overlay > div',
'#movie_player.ad-showing .ytp-ad-player-overlay-layout > div',
'#movie_player.ad-showing .ytp-ad-action-interstitial > div',
// Yellow ad progress bar
'#movie_player.ad-showing .ytp-play-progress',
// Ad time display
'#movie_player.ad-showing .ytp-time-display',
)
}
if (config.disableAutoplay) {
if (desktop) {
hideCssSelectors.push('button[data-tooltip-target-id="ytp-autonav-toggle-button"]')
}
if (mobile) {
hideCssSelectors.push('button.ytm-autonav-toggle-button-container')
}
}
if (config.disableHomeFeed && loggedIn) {
if (desktop) {
hideCssSelectors.push(
// Prevent flash of content while redirecting
'ytd-browse[page-subtype="home"]',
// Hide Home links
'ytd-guide-entry-renderer:has(> a[href="/"])',
'ytd-mini-guide-entry-renderer:has(> a[href="/"])',
)
}
if (mobile) {
hideCssSelectors.push(
// Prevent flash of content while redirecting
'.tab-content[tab-identifier="FEwhat_to_watch"]',
// Bottom nav item
'ytm-pivot-bar-item-renderer:has(> div.pivot-w2w)',
)
}
}
if (config.hideHomeCategories) {
if (desktop) {
hideCssSelectors.push('ytd-browse[page-subtype="home"] #header')
}
if (mobile) {
hideCssSelectors.push('.tab-content[tab-identifier="FEwhat_to_watch"] .rich-grid-sticky-header')
}
}
// We only hide channels in Home, Search and Related videos
if (config.hideChannels) {
if (config.hiddenChannels.length > 0) {
if (debugManualHiding) {
cssRules.push(`.${Classes.HIDE_CHANNEL} { outline: 2px solid red !important; }`)
} else {
hideCssSelectors.push(`.${Classes.HIDE_CHANNEL}`)
}
}
if (desktop) {
// Custom elements can't be cloned so we need to style our own menu items
cssRules.push(`
.cpfyt-menu-item {
align-items: center;
cursor: pointer;
display: flex !important;
min-height: 36px;
padding: 0 12px 0 16px;
}
.cpfyt-menu-item:focus {
position: relative;
background-color: var(--paper-item-focused-background-color);
outline: 0;
}
.cpfyt-menu-item:focus::before {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
pointer-events: none;
background: var(--paper-item-focused-before-background, currentColor);
border-radius: var(--paper-item-focused-before-border-radius, 0);
content: var(--paper-item-focused-before-content, "");
opacity: var(--paper-item-focused-before-opacity, var(--dark-divider-opacity, 0.12));
}
.cpfyt-menu-item:hover {
background-color: var(--yt-spec-10-percent-layer);
}
.cpfyt-menu-icon {
color: var(--yt-spec-text-primary);
fill: currentColor;
height: 24px;
margin-right: 16px;
width: 24px;
}
.cpfyt-menu-text {
color: var(--yt-spec-text-primary);
flex-basis: 0.000000001px;
flex: 1;
font-family: "Roboto","Arial",sans-serif;
font-size: 1.4rem;
font-weight: 400;
line-height: 2rem;
margin-right: 24px;
white-space: nowrap;
}
`)
}
} else {
// Hide menu item if config is changed after it's added
hideCssSelectors.push('#cpfyt-hide-channel-menu-item')
}
if (config.hideChat) {
if (desktop) {
hideCssSelectors.push('#chat-container')
}
}
if (config.hideComments) {
if (desktop) {
hideCssSelectors.push('#comments')
}
if (mobile) {
hideCssSelectors.push('ytm-item-section-renderer[section-identifier="comments-entry-point"]')
}
}
if (config.hideHiddenVideos) {
// The mobile version doesn't have any HTML hooks for appearance mode, so
// we'll just use the current backgroundColor.
let bgColor = getComputedStyle(document.documentElement).backgroundColor
cssRules.push(`
.cpfyt-pie {
--cpfyt-pie-background-color: ${bgColor};
--cpfyt-pie-color: ${bgColor == 'rgb(255, 255, 255)' ? '#065fd4' : '#3ea6ff'};
--cpfyt-pie-delay: 0ms;
--cpfyt-pie-direction: normal;
--cpfyt-pie-duration: ${undoHideDelayMs}ms;
width: 1em;
height: 1em;
font-size: 200%;
position: relative;
border-radius: 50%;
margin: 0.5em;
display: inline-block;
}
.cpfyt-pie::before,
.cpfyt-pie::after {
content: "";
width: 50%;
height: 100%;
position: absolute;
left: 0;
border-radius: 0.5em 0 0 0.5em;
transform-origin: center right;
animation-delay: var(--cpfyt-pie-delay);
animation-direction: var(--cpfyt-pie-direction);
animation-duration: var(--cpfyt-pie-duration);
}
.cpfyt-pie::before {
z-index: 1;
background-color: var(--cpfyt-pie-background-color);
animation-name: cpfyt-mask;
animation-timing-function: steps(1);
}
.cpfyt-pie::after {
background-color: var(--cpfyt-pie-color);
animation-name: cpfyt-rotate;
animation-timing-function: linear;
}
@keyframes cpfyt-rotate {
to { transform: rotate(1turn); }
}
@keyframes cpfyt-mask {
50%, 100% {
background-color: var(--cpfyt-pie-color);
transform: rotate(0.5turn);
}
}
`)
if (debugManualHiding) {
cssRules.push(`.${Classes.HIDE_HIDDEN} { outline: 2px solid magenta !important; }`)
} else {
hideCssSelectors.push(`.${Classes.HIDE_HIDDEN}`)
}
}
if (config.hideLive) {
if (desktop) {
hideCssSelectors.push(
// Grid item (Home, Subscriptions)
'ytd-browse:not([page-subtype="channels"]) ytd-rich-item-renderer:has(ytd-thumbnail[is-live-video])',
// List item (Search)
'ytd-video-renderer:has(ytd-thumbnail[is-live-video])',
// Related video
'ytd-compact-video-renderer:has(> .ytd-compact-video-renderer > ytd-thumbnail[is-live-video])',
)
}
if (mobile) {
hideCssSelectors.push(
// Home
'ytm-rich-item-renderer:has(ytm-thumbnail-overlay-time-status-renderer[data-style="LIVE"])',
// Subscriptions
'.tab-content[tab-identifier="FEsubscriptions"] ytm-item-section-renderer:has(ytm-thumbnail-overlay-time-status-renderer[data-style="LIVE"])',
// Search
'ytm-search ytm-video-with-context-renderer:has(ytm-thumbnail-overlay-time-status-renderer[data-style="LIVE"])',
// Large item in Related videos
'ytm-item-section-renderer[section-identifier="related-items"] > lazy-list > ytm-compact-autoplay-renderer:has(ytm-thumbnail-overlay-time-status-renderer[data-style="LIVE"])',
// Related videos
'ytm-item-section-renderer[section-identifier="related-items"] > lazy-list > ytm-video-with-context-renderer:has(ytm-thumbnail-overlay-time-status-renderer[data-style="LIVE"])',
)
}
}
if (config.hideMetadata) {
if (desktop) {
hideCssSelectors.push(
// Channel name / Videos / About (but not Transcript or their mutual container)
'#structured-description .ytd-structured-description-content-renderer:not(#items, ytd-video-description-transcript-section-renderer)',
// Game name and Gaming link
'#above-the-fold + ytd-metadata-row-container-renderer',
)
}
if (mobile) {
hideCssSelectors.push(
// Game name and Gaming link
'ytm-structured-description-content-renderer yt-video-attributes-section-view-model',
'ytm-video-description-gaming-section-renderer',
// Channel name / Videos / About
'ytm-structured-description-content-renderer ytm-video-description-infocards-section-renderer',
)
}
}
if (config.hideMixes) {
if (desktop) {
hideCssSelectors.push(
// Chip in Home
`yt-chip-cloud-chip-renderer:has(> yt-formatted-string[title="${getString('MIXES')}"])`,
// Grid item
'ytd-rich-item-renderer:has(a[href$="start_radio=1"])',
// List item
'ytd-radio-renderer',
// Related video
'ytd-compact-radio-renderer',
)
}
if (mobile) {
hideCssSelectors.push(
// Chip in Home
`ytm-chip-cloud-chip-renderer:has(> .chip-container[aria-label="${getString('MIXES')}"])`,
// Home
'ytm-rich-item-renderer:has(> ytm-radio-renderer)',
// Search result
'ytm-compact-radio-renderer',
)
}
}
if (config.hideNextButton) {
if (desktop) {
// Hide the Next by default so it doesn't flash in and out of visibility
// Show Next is Previous is enabled (e.g. when viewing a playlist video)
cssRules.push(`
.ytp-chrome-controls .ytp-next-button {
display: none !important;
}
.ytp-chrome-controls .ytp-prev-button[aria-disabled="false"] ~ .ytp-next-button {
display: revert !important;
}
`)
}
if (mobile) {
hideCssSelectors.push(
// Hide the Previous button when it's disabled, as it otherwise takes you to the previously-watched video
`.player-controls-middle-core-buttons > button[aria-label="${getString('PREVIOUS_VIDEO')}"][aria-disabled="true"]`,
// Always hide the Next button as it takes you to a random video, even if you just used Previous
`.player-controls-middle-core-buttons > button[aria-label="${getString('NEXT_VIDEO')}"]`,
)
}
}
if (config.hideRelated) {
if (desktop) {
hideCssSelectors.push('#related')
}
if (mobile) {
hideCssSelectors.push('ytm-item-section-renderer[section-identifier="related-items"]')
}
}
if (config.hideShareThanksClip) {
if (desktop) {
hideCssSelectors.push(
// Buttons
`ytd-menu-renderer yt-button-view-model:has(> button-view-model > button[aria-label="${getString('SHARE')}"])`,
`ytd-menu-renderer yt-button-view-model:has(> button-view-model > button[aria-label="${getString('THANKS')}"])`,
`ytd-menu-renderer yt-button-view-model:has(> button-view-model > button[aria-label="${getString('CLIP')}"])`,
// Menu items
`.${Classes.HIDE_SHARE_THANKS_CLIP}`,
)
}
if (mobile) {
hideCssSelectors.push(
`ytm-slim-video-action-bar-renderer button-view-model:has(> button[aria-label="${getString('SHARE')}"])`,
)
}
}
if (config.hideShorts) {
if (desktop) {
hideCssSelectors.push(
// Side nav item
`ytd-guide-entry-renderer:has(> a[title="${getString('SHORTS')}"])`,
// Mini side nav item
`ytd-mini-guide-entry-renderer[aria-label="${getString('SHORTS')}"]`,
// Grid shelf
'ytd-rich-section-renderer:has(> #content > ytd-rich-shelf-renderer[is-shorts])',
// Chips
`yt-chip-cloud-chip-renderer:has(> yt-formatted-string[title="${getString('SHORTS')}"])`,
// List shelf (except History, so watched Shorts can be removed)
'ytd-browse:not([page-subtype="history"]) ytd-reel-shelf-renderer',
'ytd-search ytd-reel-shelf-renderer',
// List item (except History, so watched Shorts can be removed)
'ytd-browse:not([page-subtype="history"]) ytd-video-renderer:has(a[href^="/shorts"])',
'ytd-search ytd-video-renderer:has(a[href^="/shorts"])',
// Under video
'#structured-description ytd-reel-shelf-renderer',
// In related
'#related ytd-reel-shelf-renderer',
)
}
if (mobile) {
hideCssSelectors.push(
// Bottom nav item
'ytm-pivot-bar-item-renderer:has(> div.pivot-shorts)',
// Home shelf
'ytm-rich-section-renderer:has(ytm-reel-shelf-renderer)',
// Subscriptions shelf
'.tab-content[tab-identifier="FEsubscriptions"] ytm-item-section-renderer:has(ytm-reel-shelf-renderer)',
// Search shelf
'ytm-search lazy-list > ytm-reel-shelf-renderer',
// Search
'ytm-search ytm-video-with-context-renderer:has(a[href^="/shorts"])',
// Under video
'ytm-structured-description-content-renderer ytm-reel-shelf-renderer',
// In related
'ytm-item-section-renderer[data-content-type="related"] ytm-video-with-context-renderer:has(a[href^="/shorts"])',
)
}
}
if (config.hideSponsored) {
if (desktop) {
hideCssSelectors.push(
// Big ads and promos on Home screen
'#masthead-ad',
'#big-yoodle ytd-statement-banner-renderer',
'ytd-rich-section-renderer:has(> #content > ytd-statement-banner-renderer)',
'ytd-rich-section-renderer:has(> #content > ytd-rich-shelf-renderer[has-paygated-featured-badge])',
'ytd-rich-section-renderer:has(> #content > ytd-brand-video-shelf-renderer)',
'ytd-rich-section-renderer:has(> #content > ytd-brand-video-singleton-renderer)',
'ytd-rich-section-renderer:has(> #content > ytd-inline-survey-renderer)',
// Bottom of screen promo
'tp-yt-paper-dialog:has(> #mealbar-promo-renderer)',
// Video listings
'ytd-rich-item-renderer:has(> .ytd-rich-item-renderer > ytd-ad-slot-renderer)',
// Search results
'ytd-search-pyv-renderer.ytd-item-section-renderer',
'ytd-ad-slot-renderer.ytd-item-section-renderer',
// When an ad is playing
'ytd-engagement-panel-section-list-renderer[target-id="engagement-panel-ads"]',
// Suggestd action buttons in player overlay
'#movie_player .ytp-suggested-action',
// Panels linked to those buttons
'#below #panels',
// After an ad
'.ytp-ad-action-interstitial',
// Paid content overlay
'.ytp-paid-content-overlay',
// Above Related videos
'#player-ads',
// In Related videos
'#items > ytd-ad-slot-renderer',
)
}
if (mobile) {
hideCssSelectors.push(
// Big promo on Home screen
'ytm-statement-banner-renderer',
// Bottom of screen promo
'.mealbar-promo-renderer',
// Search results
'ytm-search ytm-item-section-renderer:has(> lazy-list > ad-slot-renderer)',
// Paid content overlay
'ytm-paid-content-overlay-renderer',
// Directly under video
'ytm-companion-slot:has(> ytm-companion-ad-renderer)',
// Directly under comments entry point (narrow)
'.related-chips-slot-wrapper ytm-item-section-renderer[section-identifier="comments-entry-point"] + ytm-item-section-renderer:has(> lazy-list > ad-slot-renderer)',
// In Relatd videos (narrow)
'ytm-watch ytm-item-section-renderer[data-content-type="result"]:has(> lazy-list > ad-slot-renderer)',
// In Related videos (wide)
'ytm-item-section-renderer[section-identifier="related-items"] > lazy-list > ad-slot-renderer',
)
}
}
if (config.hideStreamed) {
if (debugManualHiding) {
cssRules.push(`.${Classes.HIDE_STREAMED} { outline: 2px solid blue; }`)
} else {
hideCssSelectors.push(`.${Classes.HIDE_STREAMED}`)
}
}
if (config.hideSuggestedSections) {
if (desktop) {
hideCssSelectors.push(
// Shelves in Home
'ytd-browse[page-subtype="home"] ytd-rich-section-renderer:not(:has(> #content > ytd-rich-shelf-renderer[is-shorts]))',
// Looking for something different? tile in Home
'ytd-browse[page-subtype="home"] ytd-rich-item-renderer:has(> #content > ytd-feed-nudge-renderer)',
// Suggested content shelves in Search
`ytd-search #contents.ytd-item-section-renderer > ytd-shelf-renderer`,
// People also search for in Search
'ytd-search #contents.ytd-item-section-renderer > ytd-horizontal-card-list-renderer',
// Recommended videos in a Playlist
'ytd-browse[page-subtype="playlist"] ytd-item-section-renderer[is-playlist-video-container]',
// Recommended playlists in a Playlist
'ytd-browse[page-subtype="playlist"] ytd-item-section-renderer[is-playlist-video-container] + ytd-item-section-renderer',
)
}
if (mobile) {
// Logged-out users can get a "Try searching to get started" Home page
// section which this would hide.
if (loggedIn) {
hideCssSelectors.push(
// Shelves in Home
'.tab-content[tab-identifier="FEwhat_to_watch"] ytm-rich-section-renderer',
)
}
}
}
if (config.hideUpcoming) {
if (desktop) {
hideCssSelectors.push(
// Grid item
'ytd-browse:not([page-subtype="channels"]) ytd-rich-item-renderer:has(ytd-thumbnail-overlay-time-status-renderer[overlay-style="UPCOMING"])',
// List item
'ytd-video-renderer:has(ytd-thumbnail-overlay-time-status-renderer[overlay-style="UPCOMING"])',
)
}
if (mobile) {
hideCssSelectors.push(
// Subscriptions
'.tab-content[tab-identifier="FEsubscriptions"] ytm-item-section-renderer:has(ytm-thumbnail-overlay-time-status-renderer[data-style="UPCOMING"])'
)
}
}
if (config.hideVoiceSearch) {
if (desktop) {
hideCssSelectors.push('#voice-search-button')
}
if (mobile) {
hideCssSelectors.push('.searchbox-voice-search-wrapper')
}
}
if (config.hideWatched) {
if (debugManualHiding) {
cssRules.push(`.${Classes.HIDE_WATCHED} { outline: 2px solid green; }`)
} else {
hideCssSelectors.push(`.${Classes.HIDE_WATCHED}`)
}
}
//#region Desktop-only
if (desktop) {
// Fix spaces & gaps caused by left gutter margin on first column items
cssRules.push(`
/* Remove left gutter margin from first column items */
ytd-browse:is([page-subtype="home"], [page-subtype="subscriptions"]) ytd-rich-item-renderer[rendered-from-rich-grid][is-in-first-column] {
margin-left: calc(var(--ytd-rich-grid-item-margin, 16px) / 2) !important;
}
/* Apply the left gutter as padding in the grid contents instead */
ytd-browse:is([page-subtype="home"], [page-subtype="subscriptions"]) #contents.ytd-rich-grid-renderer {
padding-left: calc(var(--ytd-rich-grid-gutter-margin, 16px) * 2) !important;
}
/* Adjust non-grid items so they don't double the gutter */
ytd-browse:is([page-subtype="home"], [page-subtype="subscriptions"]) #contents.ytd-rich-grid-renderer > :not(ytd-rich-item-renderer) {
margin-left: calc(var(--ytd-rich-grid-gutter-margin, 16px) * -1) !important;
}
`)
if (config.fullSizeTheaterMode) {
// 56px is the height of #container.ytd-masthead
cssRules.push(`
ytd-watch-flexy[theater]:not([fullscreen]) #full-bleed-container {
max-height: calc(100vh - 56px);
}
`)
}
if (config.hideEndCards) {
hideCssSelectors.push('#movie_player .ytp-ce-element')
}
if (config.hideEndVideos) {
hideCssSelectors.push('#movie_player .ytp-endscreen-content')
}
if (config.hideMerchEtc) {
hideCssSelectors.push(
// Tickets
'#ticket-shelf',
// Merch
'ytd-merch-shelf-renderer',
// Offers
'#offer-module',
)
}
if (config.hideMiniplayerButton) {
hideCssSelectors.push('#movie_player .ytp-miniplayer-button')
}
if (config.hideSubscriptionsLatestBar) {
hideCssSelectors.push(
'ytd-browse[page-subtype="subscriptions"] ytd-rich-grid-renderer > #contents > ytd-rich-section-renderer:first-child'
)
}
if (config.minimumGridItemsPerRow != 'auto') {
let gridItemsPerRow = Number(config.minimumGridItemsPerRow)
let exclude = []
for (let i = 6; i > gridItemsPerRow; i--) {
exclude.push(`[elements-per-row="${i}"]`)
}
cssRules.push(`
ytd-browse:is([page-subtype="home"], [page-subtype="subscriptions"]) ytd-rich-grid-renderer${exclude.length > 0 ? `:not(${exclude.join(', ')})` : ''} {
--ytd-rich-grid-items-per-row: ${gridItemsPerRow} !important;
}
`)
}
if (config.removePink) {
cssRules.push(`
.ytp-cairo-refresh-signature-moments .ytp-play-progress,
#progress.ytd-thumbnail-overlay-resume-playback-renderer {
background: #f03 !important;
}
`)
}
if (config.searchThumbnailSize != 'large') {
cssRules.push(`
ytd-search ytd-video-renderer ytd-thumbnail.ytd-video-renderer,
ytd-search yt-lockup-view-model .yt-lockup-view-model-wiz__content-image {
max-width: ${{
medium: 420,
small: 360,
}[config.searchThumbnailSize]}px !important;
}
`)
}
if (config.tidyGuideSidebar) {
hideCssSelectors.push(
// Logged in
// Subscriptions (2nd of 5)
'#sections.ytd-guide-renderer > ytd-guide-section-renderer:nth-child(2):nth-last-child(4)',
// Explore (3rd of 5)
'#sections.ytd-guide-renderer > ytd-guide-section-renderer:nth-child(3):nth-last-child(3)',
// More from YouTube (4th of 5)
'#sections.ytd-guide-renderer > ytd-guide-section-renderer:nth-child(4):nth-last-child(2)',
// Logged out
/*
// Subscriptions - prompts you to log in
'#sections.ytd-guide-renderer > ytd-guide-section-renderer:nth-child(1):nth-last-child(7) > #items > ytd-guide-entry-renderer:has(> a[href="/feed/subscriptions"])',
// You (2nd of 7) - prompts you to log in
'#sections.ytd-guide-renderer > ytd-guide-section-renderer:nth-child(2):nth-last-child(6)',
// Sign in prompt - already have one in the top corner
'#sections.ytd-guide-renderer > ytd-guide-signin-promo-renderer',
*/
// Explore (4th of 7)
'#sections.ytd-guide-renderer > ytd-guide-section-renderer:nth-child(4):nth-last-child(4)',
// Browse Channels (5th of 7)
'#sections.ytd-guide-renderer > ytd-guide-section-renderer:nth-child(5):nth-last-child(3)',
// More from YouTube (6th of 7)
'#sections.ytd-guide-renderer > ytd-guide-section-renderer:nth-child(6):nth-last-child(2)',
// Footer
'#footer.ytd-guide-renderer',