-
Notifications
You must be signed in to change notification settings - Fork 4
/
youtube-element-blocker.js
236 lines (191 loc) · 6.49 KB
/
youtube-element-blocker.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
// ==UserScript==
// @name YouTube element blocker
// @description Block specific elements of YouTube, like the Feed, Comments, Subscriptions bar and more
//
// @version 1.5.2
// @license MIT
// @author Syndamia
//
// @source https://github.com/Syndamia/min-youtube-element-blocker
// @supportURL https://github.com/Syndamia/min-youtube-element-blocker/issues
// @homepage https://greasyfork.org/en/scripts/419701-youtube-element-blocker
// @icon https://upload.wikimedia.org/wikipedia/commons/1/1a/YouTube_play_button_dark_rounded_square_%282013-2017%29.svg
//
// @namespace Syndamia
// @match *://*.youtube.com/*
// @run-at document-start
// ==/UserScript==
/* Change the word after the name of a setting (and after the column character) to
* true to enable it and to false to disable it (DO NOT REMOVE THE COMMA AFTER THE WORD)
* For example, enabled hideFeed will look like this: "hideFeed" : true,
*/
var generalSettings = {
// The feed is the collection of videos, shown on the home page
"hideFeed" : false,
// The guide drawer is the drawer (sidebar) to the left
// which is used for navigating Playlists, Subscriptions, ...
"hideGuideDrawer" : false,
"hideGuideHomeTab" : false,
"hideGuideTrendingTab" : false,
"hideGuideShortsTab" : false,
"hideGuideLibraryTab" : false,
"hideGuideMoreFromYouTube" : false,
// The last section is the part under "More from YouTube",
// where you can find the buttons for "Help", "Send Feedback", ...
"hideGuideLastSection" : false,
// The footer is the part at the very bottom of the guide drawer
// that shows links like "About", "Terms", "Contact us", ...
"hideGuideFooter" : false,
// Related videos are the recommendations at the end of a video
"hideRelated" : false,
"hideChat" : false,
// The sidebar is the section to the right of a video
// where you can find video and playlist suggestions
"hideSidebar" : false,
"hideMerch" : false,
"hideComments" : false,
// Makes comments at the top of the page visible when printing
// Note: also loses navigation button. Can hide 'skip navigation' button only.
"hideMasthead": false,
"hideSkipNavButton": false,
};
/* The whole YouTube website can also be blocked (independently of the other settings)
* depending on the time of day and the day in the week. This feature is called timeout.
*/
var timeout = {
"enabled" : false,
// Determines days, in which the timeout will be active. Each day is separated
// by a comma. Can be 0 to 6, where 0 is Sunday, 1 is Monday and 6 is Saturday.
"activeDays" : [0, 1, 2, 3, 4, 5, 6],
// Determines time from which the timeout will block YouTube.
// Must be numbers, from 0 to 24 for hour and from 0 to 59 for minutes.
"startHour" : 9,
"startMinutes" : 0,
// Determines end of time from which the timeout will block YouTube.
// Must be numbers, from 0 to 24 for hour and from 0 to 59 for minutes.
"endHour" : 17,
"endMinutes" : 0,
};
/************************************/
/* END OF USER CONFIGURABLE OPTIONS */
/************************************/
/* CSS that is added to page for hiding the elements */
var css = {
"hideFeed": `
#feed, ytd-browse[page-subtype=home] {
display: none !important;
}`,
"hideGuideDrawer": `
#appbar-guide-menu {
width: 0;
}
app-drawer#guide {
display: none !important;
}
ytd-mini-guide-renderer {
display: none !important;
}
#guide-button {
display: none !important;
}`,
"hideGuideHomeTab": `
#home-guide-item {
display: none !important;
}
ytd-guide-section-renderer:first-child #items > ytd-guide-entry-renderer:first-child {
display: none !important;
}
#appbar-nav li:first-child {
display: none !important;
}
ytd-mini-guide-renderer #items ytd-mini-guide-entry-renderer:first-child {
display: none !important;
}`,
"hideGuideTrendingTab": `
#trending-guide-item {
display: none !important;
}
#appbar-nav li:nth-child(2) {
display: none !important;
}
ytd-mini-guide-renderer #items ytd-mini-guide-entry-renderer:nth-child(2) {
display: none !important;
}`,
"hideGuideShortsTab": `
ytd-guide-section-renderer:first-child #items > ytd-guide-entry-renderer:nth-child(2) {
display: none !important;
}
#appbar-nav li:nth-child(3) {
display: none !important;
}
ytd-mini-guide-renderer #items ytd-mini-guide-entry-renderer:nth-child(3) {
display: none !important;
}`,
"hideGuideLibraryTab" : `
ytd-guide-section-renderer:first-child #items > ytd-guide-collapsible-section-entry-renderer > #header {
display: none !important;
}`,
"hideGuideMoreFromYouTube": `
ytd-guide-section-renderer:nth-last-child(2) {
display: none !important;
}`,
"hideGuideLastSection": `
ytd-guide-section-renderer:last-child {
display: none !important;
}`,
"hideGuideFooter": `
#footer {
display: none !important;
}`,
"hideRelated": `
.ytp-endscreen-content {
display: none !important;
}
.ytp-ce-video {
display: none !important;
}`,
"hideChat": `
ytd-live-chat-frame {
display: none !important;
}`,
"hideSidebar": `
#watch7-sidebar-contents, #related {
display: none !important;
}`,
"hideMerch": `
.ytd-merch-shelf-renderer {
display: none !important;
}`,
"hideComments": `
#watch-discussion, #comments {
display: none !important;
}`,
"hideSkipNavButton": `
#skip-navigation.ytd-masthead {
display: none !important;
}`,
"hideMasthead": `
#container.ytd-masthead {
display: none !important;
}`,
};
// Element, that will contain CSS of activated settings
var style = document.createElement('style');
if(timeout.enabled) {
var now = new Date(),
start = new Date(),
end = new Date();
start.setHours(timeout.startHour, timeout.startMinutes, 0);
end.setHours(timeout.endHour, timeout.endMinutes, 0);
if (now >= start && now < end && timeout.activeDays.includes(now.getDay())) {
style.textContent = "body { display: none !important; }"
}
}
// Execute general settings, only if the timeout isn't active
if (style.textContent === "") {
for (var setting in generalSettings) {
if (!generalSettings[setting]) continue;
style.textContent += css[setting];
}
}
document.head.appendChild(style);