-
Notifications
You must be signed in to change notification settings - Fork 1
/
inject.js
85 lines (71 loc) · 2.08 KB
/
inject.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
chrome.storage.local.get().then(setMode);
chrome.storage.onChanged.addListener(() => {
chrome.storage.local.get().then(setMode);
});
function setMode(data) {
if (!data || !data.chosenMode/* || !data.chosenMode.contains(['brain', 'focus', 'default'])*/) {
console.log('Wrong chosenMode!', data.chosenMode);
return;
}
if (data.chosenMode === 'brain') {
brain();
} else if (data.chosenMode === 'focus') {
focus();
} else {
normal();
}
}
function normal() {
if (document.getElementById('youtubeFocusBrain')) {
document.head.removeChild(document.getElementById('youtubeFocusBrain'));
}
}
function brain() {
if (document.getElementById('youtubeFocusBrain')) {
document.head.removeChild(document.getElementById('youtubeFocusBrain'));
}
var style = document.createElement('style');
style.type = 'text/css';
style.id = 'youtubeFocusBrain';
style.innerHTML = `
*[page-subtype~="home"],
*[href*="/feed/trending"],
.ytp-endscreen-content,
#related #contents,
#related #upnext,
#related #items,
#related ytd-compact-video-renderer,
#related ytd-compact-playlist-renderer,
#related ytd-compact-radio-renderer,
.watch-sidebar-body,
#feed-main-what_to_watch{
display: none !important;
}
`;
document.head.appendChild(style);
}
function focus() {
if (document.getElementById('youtubeFocusBrain')) {
document.head.removeChild(document.getElementById('youtubeFocusBrain'));
}
var style = document.createElement('style');
style.type = 'text/css';
style.id = 'youtubeFocusBrain';
style.innerHTML = `
*[page-subtype~="home"],
*[href*="/feed/trending"],
.ytp-endscreen-content,
ytd-compact-video-renderer:nth-child(n+4),
#related ytd-compact-playlist-renderer,
#related ytd-compact-radio-renderer,
.watch-sidebar-body,
#feed-main-what_to_watch{
display: none !important;
}
`;
document.head.appendChild(style);
/*var autoplay = document.getElementById('toggle');
if (autoplay && autoplay.checked) {
autoplay.checked = false;
}*/
}