-
Notifications
You must be signed in to change notification settings - Fork 2
/
hide_youtube_recommendations.user.js
97 lines (76 loc) · 2.79 KB
/
hide_youtube_recommendations.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
// ==UserScript==
// @id hide-youtube-recommendations@artli
// @name Hide YouTube recommendations
// @version 0.5.6
// @author https://github.com/artli
// @license Mozilla Public License 2.0
// @namespace https://github.com/artli/hide-youtube-recommendations
// @description Remove thumbnails and censor video titles of the recommended videos on the main page and in the recommendation sidebar.
// @downloadURL https://raw.githubusercontent.com/artli/hide-youtube-recommendations/latestRelease/hide_youtube_recommendations.user.js
// @include https://youtube.com/*
// @include https://*.youtube.com/*
// ==/UserScript==
var hideRule = function(selector) {
return selector + ' { display: none !important; }';
}
var censorRule = function(selector, color) {
color = color || 'black';
return (
selector + ' { color: transparent !important; background-color: ' + color + ' !important; }\n'
+ selector + ':hover { color: ' + color + ' !important; }');
}
var RULES = [
censorRule('#video-title:not(.ytd-playlist-panel-video-renderer)', '#030303'),
hideRule('ytd-thumbnail:not(.ytd-playlist-panel-video-renderer)')];
var URL_BLACKLIST = ['subscriptions', 'library', 'history', 'videos', 'playlist', 'results', 'channel', '/c/', 'user'];
var createStyle = function(css) {
var style = document.createElement('style');
style.type = 'text/css';
style.appendChild(document.createTextNode(css));
return style;
}
function StyleHolder(cssRules) {
this.elements = cssRules.map(createStyle);
}
StyleHolder.prototype.apply = function() {
this.elements.map(document.head.appendChild.bind(document.head));
}
StyleHolder.prototype.revert = function() {
this.elements.map(document.head.removeChild.bind(document.head));
}
function UrlWatcher(urlBlacklist, apply, revert, interval) {
this.urlBlacklist = urlBlacklist;
this.apply = apply;
this.revert = revert;
this.enabled = false;
this.tick();
this.interval = setInterval(this.tick.bind(this), interval || 300);
}
UrlWatcher.prototype.checkUrl = function(url) {
for (var i = 0; i < this.urlBlacklist.length; i++) {
if (url.search(this.urlBlacklist[i]) != -1) {
return false;
}
}
return true;
};
UrlWatcher.prototype.tick = function() {
var enable = this.checkUrl(unsafeWindow.location.href);
if (enable == this.enabled) {
return;
}
this.enabled = enable;
if (enable) {
this.apply();
} else {
this.revert();
}
};
var init = function() {
var styleHolder = new StyleHolder(RULES);
var urlWatcher = new UrlWatcher(
URL_BLACKLIST,
styleHolder.apply.bind(styleHolder),
styleHolder.revert.bind(styleHolder));
}
init();