-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
190 lines (173 loc) · 9.4 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
//{
var k2Val=1.010;
var filters = new Array("rgba(0,0,0,0)");
var svgfilter = new Array(
`<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><filter id="myfilter"><feGaussianBlur stdDeviation="1" /><feConvolveMatrix preserveAlpha="true" kernelMatrix="-1 -1 -1 -1 8 -1 -1 -1 -1" /></filter></defs></svg>`,/*Color Normal*/
`<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><filter id="myfilter"><feGaussianBlur stdDeviation="1" /><feColorMatrix type="matrix" values="0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0"/><feConvolveMatrix preserveAlpha="true" kernelMatrix="-1 -1 -1 -1 8 -1 -1 -1 -1" /></filter></defs></svg>`/*Green Normal--*/,
`<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><filter id="myfilter"><feGaussianBlur stdDeviation="1" /><feColorMatrix type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0"/><feConvolveMatrix preserveAlpha="true" kernelMatrix="-1 -1 -1 -1 8 -1 -1 -1 -1" /></filter></defs></svg>`/*Yellow Normal--*/,
`<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><filter id="myfilter"><feGaussianBlur stdDeviation="1" /><feColorMatrix type="matrix" values="1 0 0 0 0 0 0.5 0 0 0 0 0 0 0 0 0 0 0 1 0"/><feConvolveMatrix preserveAlpha="true" kernelMatrix="-1 -1 -1 -1 8 -1 -1 -1 -1" /></filter></defs></svg>`/*Orange Normal--*/,
`<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><filter id="myfilter"><feGaussianBlur stdDeviation="1" /><feColorMatrix type="matrix" values="1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0"/><feConvolveMatrix preserveAlpha="true" kernelMatrix="-1 -1 -1 -1 8 -1 -1 -1 -1" /></filter></defs></svg>`/*Red Normal--*/,
`<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><filter id="myfilter"><feGaussianBlur stdDeviation="1" /><feColorMatrix type="saturate" values="0.10"/><feConvolveMatrix preserveAlpha="true" kernelMatrix="-1 -1 -1 -1 8 -1 -1 -1 -1" /></filter></defs></svg>`/*Black-White Normal--*/,
`<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><filter id="myfilter"><feGaussianBlur stdDeviation="1" /><feConvolveMatrix preserveAlpha="true" kernelMatrix="-1 -1 -1 -1 8 -1 -1 -1 -1" /><feComposite in="SourceGraphic" in2="specOut" operator="arithmetic" k1="0.5" k2="0.050" k3="0.030" k4="0"/></filter></defs></svg>`,/*Natural Color Normal*/
`<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"><defs><filter id="myfilter"><feGaussianBlur stdDeviation="1" /><feConvolveMatrix preserveAlpha="true" kernelMatrix="-1 -1 -1 -1 8 -1 -1 -1 -1" /><feComposite in="SourceGraphic" in2="specOut" operator="arithmetic" k1="0.5" k2=0.050 k3="0.030" k4="0"/><feColorMatrix type="matrix" values= "1 0 0 0 0
0 1 0 0 0
0 0 0.9987 0 0
0 0 0 1 0"/></filter></defs></svg>`,/*Natural Colors with edges Blue Light filter*/
);
//}
var selected = 0;
var state = null;
var _thread_mask = setInterval(function(){
var video = document.getElementsByTagName("video");
if(video.length>0){
clearInterval(_thread_mask);
addMask();
}
}, 50);
window.addEventListener('keydown', function(kevent){
if(kevent.keyCode==120){//F9
P2P();
}
});
function addMask(){
if(location.href.indexOf("youtube.com")>0 || location.href.indexOf("youtube-nocookie.com")>0)
if (document.getElementById('ytp-video-filters-htcom') == null) {
var video = document.getElementsByTagName("video");
if (video.length > 0) {
var holder = video[0].parentElement.parentElement;
var filter = document.createElement("div");
filter.setAttribute("id", "ytp-video-filters-htcom");
filter.style.position = "absolute";
filter.style.width = "100%";
filter.style.height = "100%";
filter.style.top = 0;
filter.style.left = 0;
filter.style.zIndex = "10";
filter.style.pointerEvents = "none";
filter.style.background = filters[selected];
holder.appendChild(filter);
}
}
}
function applyFilter(index, manual) {
var videos = document.getElementsByTagName("video");
if (videos.length > 0) {
var video = videos[0];
var y = videos[0].parentElement;
var filter = document.getElementById("ytp-video-filters-htcom");
var len = filters.length;
var lenSvg = svgfilter.length;
var lastFilterIndex = len + lenSvg - 1;
if (filter != null && filter != undefined) {
if (index < len) {
video.style.filter = "";
filter.style.background = filters[index];
y.style.filter = '';
filter.style.backgroundSize = 'cover';
} else {
var innerHtmlFilter = svgfilter[index - len];
if(index == lastFilterIndex && manual!=null)
{
var man = JSON.parse(manual);
var k2Val = 0.01 * parseInt(man[0]);
var blueLight = 0.05 * parseInt(man[1]);
innerHtmlFilter = innerHtmlFilter.replace("k2=0.050", "k2=" + k2Val);
innerHtmlFilter = innerHtmlFilter.replace("0.9987", "" + blueLight);
}
filter.innerHTML = innerHtmlFilter;
video.style.filter = "url(#myfilter)";
filter.style.background = "";
filter.style.backgroundSize = 'unset';
y.style.filter = 'brightness(140%) contrast(156%)';
}
}
}
}
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.youtube_filter_selected_index !== undefined) {
selected = request.youtube_filter_selected_index;
var manual = null;
if(request.youtube_video_filters_manual!==undefined)
manual = request.youtube_video_filters_manual;
var _thread_apply_filter = setInterval(function(){
if (document.getElementById('ytp-video-filters-htcom') != null){
clearInterval(_thread_apply_filter);
applyFilter(selected, manual);
}
}, 50);
}
if (request.youtube_darkmode_clicked !== undefined) {
state = ((request.youtube_darkmode_clicked === "true") || (request.youtube_darkmode_clicked === true) ? true : false);
if(window.self == window.top && window.location.hostname.indexOf(".youtube.com")>=0){//not in iframe
toggleDarkMode(state);
}
}
}
);
function toggleDarkMode(s) {
if (s == true) {
document.documentElement.removeAttribute("style");
document.documentElement.setAttribute("style", "font-size: 10px; font-family: Roboto, Arial, sans-serif; background-color: rgb(19, 19, 19);");
document.documentElement.setAttribute("dark", "true");
var masthead = document.getElementById('masthead');
if(masthead!=null&&masthead!=undefined){
masthead.setAttribute("style", "--yt-swatch-primary:rgb(35,35,35); --yt-swatch-primary-darker:rgb(32,32,32); --yt-swatch-text:rgb(255,255,255); --yt-swatch-important-text:rgb(255,255,255); --yt-swatch-input-text:rgba(255,255,255,1); --yt-swatch-textbox-bg:rgba(19,19,19,1); --yt-swatch-logo-override:rgb(255,255,255); --yt-swatch-icon-color:rgba(136,136,136,1);");
masthead.setAttribute("dark", "");
}
} else {
document.documentElement.removeAttribute("style");
document.documentElement.setAttribute("style", "font-size: 10px; font-family: Roboto, Arial, sans-serif; background-color: rgb(255, 255, 255);");
document.documentElement.removeAttribute("dark");
var masthead = document.getElementById('masthead');
if(masthead!=null&&masthead!=undefined){
masthead.setAttribute("style", "--yt-swatch-primary:rgb(255,255,255); --yt-swatch-primary-darker:rgb(230,230,230); --yt-swatch-text:rgba(17,17,17,0.4); --yt-swatch-input-text:rgba(17,17,17,1); --yt-swatch-textbox-bg:rgba(255,255,255,1); --yt-swatch-icon-color:rgba(136,136,136,1)");
masthead.removeAttribute("dark");
}
}
forceMasthead2Dark(state);
}
function forceMasthead2Dark(s){
var _mh = document.getElementById('forceMasthead2Dark');
if(_mh!=null){
_mh.remove();
}
var style = document.createElement('style');
style.setAttribute('id', 'forceMasthead2Dark');
style.type = "text/css";
if(s==true){
var css = `
ytd-masthead#masthead{
--yt-swatch-primary:rgb(35,35,35) !important;
--yt-swatch-primary-darker:rgb(32,32,32) !important;
--yt-swatch-text:rgb(255,255,255) !important;
--yt-swatch-important-text:rgb(255,255,255) !important;
--yt-swatch-input-text:rgba(255,255,255,1) !important;
--yt-swatch-textbox-bg:rgba(19,19,19,1) !important;
--yt-swatch-logo-override:rgb(255,255,255) !important;
--yt-swatch-icon-color:rgba(136,136,136,1) !important;
}
paper-button, ytd-guide-entry-renderer[active], ytd-topbar-logo-renderer#logo{filter:hue-rotate(45deg) !important;}
`;
style.appendChild(document.createTextNode(css));
}else{
var css = `
ytd-masthead#masthead{
--yt-swatch-primary:rgb(255,255,255) !important;
--yt-swatch-primary-darker:rgb(230,230,230) !important;
--yt-swatch-text:rgba(17,17,17,0.4) !important;
--yt-swatch-input-text:rgba(17,17,17,1) !important;
--yt-swatch-textbox-bg:rgba(255,255,255,1) !important;
--yt-swatch-icon-color:rgba(136,136,136,1) !important;
}
`;
style.appendChild(document.createTextNode(css));
}
document.body.appendChild(style);
}
function P2P(){//F9
//if(document.pictureInPictureEnabled){
video = document.querySelector('video');
video.requestPictureInPicture();
//}
}