-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo-enhancement-control-panel.user.js
241 lines (209 loc) · 8.57 KB
/
video-enhancement-control-panel.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
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
// ==UserScript==
// @name Video Enhancement Control Panel
// @namespace http://tampermonkey.net/
// @version 1.2
// @description Advanced video sharpening and enhancement with real-time controls
// @match *://*/*
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_addStyle
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// Configuration
const DEFAULT_ENABLED = true;
const DEFAULT_CONTRAST = 1.0;
const DEFAULT_SATURATION = 1.0;
// Shared panel variable
let enhancementPanel = null;
// Create enhancement control panel
function createEnhancementPanel() {
// If panel already exists, just show it
if (enhancementPanel) {
enhancementPanel.style.display = 'block';
return enhancementPanel;
}
// Create panel container
const panel = document.createElement('div');
panel.id = 'video-enhancement-panel';
panel.innerHTML = `
<div class="panel-header">Video Enhancement Controls</div>
<div class="panel-content">
<div class="control-group">
<label>Sharpening:</label>
<input type="checkbox" id="sharpening-toggle">
</div>
<div class="control-group">
<label>Contrast:</label>
<input type="range" id="contrast-slider" min="0.5" max="2.0" step="0.1" value="${DEFAULT_CONTRAST}">
<span id="contrast-value">${DEFAULT_CONTRAST}</span>
</div>
<div class="control-group">
<label>Saturation:</label>
<input type="range" id="saturation-slider" min="0.0" max="2.0" step="0.1" value="${DEFAULT_SATURATION}">
<span id="saturation-value">${DEFAULT_SATURATION}</span>
</div>
<div class="panel-actions">
<button id="save-settings">Save</button>
<button id="close-panel">Close</button>
</div>
</div>
`;
// Add styles
GM_addStyle(`
#video-enhancement-panel {
position: fixed;
top: 20px;
right: 20px;
width: 300px;
background: white;
border: 2px solid #333;
border-radius: 8px;
z-index: 10000;
box-shadow: 0 4px 6px rgba(0,0,0,0.1);
font-family: Arial, sans-serif;
}
#video-enhancement-panel .panel-header {
background: #f0f0f0;
padding: 10px;
font-weight: bold;
text-align: center;
}
#video-enhancement-panel .panel-content {
padding: 15px;
}
#video-enhancement-panel .control-group {
margin-bottom: 15px;
display: flex;
align-items: center;
}
#video-enhancement-panel label {
flex: 1;
margin-right: 10px;
}
#video-enhancement-panel input[type="range"] {
flex: 2;
margin-right: 10px;
}
#video-enhancement-panel .panel-actions {
display: flex;
justify-content: space-between;
}
#video-enhancement-panel button {
padding: 5px 10px;
cursor: pointer;
}
`);
// Append to body
document.body.appendChild(panel);
// Setup event listeners
setupPanelEventListeners(panel);
// Store reference
enhancementPanel = panel;
return panel;
}
// Setup event listeners for the panel
function setupPanelEventListeners(panel) {
// Get control elements
const sharpeningToggle = panel.querySelector('#sharpening-toggle');
const contrastSlider = panel.querySelector('#contrast-slider');
const contrastValue = panel.querySelector('#contrast-value');
const saturationSlider = panel.querySelector('#saturation-slider');
const saturationValue = panel.querySelector('#saturation-value');
const saveButton = panel.querySelector('#save-settings');
const closeButton = panel.querySelector('#close-panel');
// Initialize control states
sharpeningToggle.checked = GM_getValue('videoEnhancementEnabled', DEFAULT_ENABLED);
contrastSlider.value = GM_getValue('videoContrast', DEFAULT_CONTRAST);
contrastValue.textContent = contrastSlider.value;
saturationSlider.value = GM_getValue('videoSaturation', DEFAULT_SATURATION);
saturationValue.textContent = saturationSlider.value;
// Real-time preview for contrast
contrastSlider.addEventListener('input', () => {
contrastValue.textContent = contrastSlider.value;
processVideos();
});
// Real-time preview for saturation
saturationSlider.addEventListener('input', () => {
saturationValue.textContent = saturationSlider.value;
processVideos();
});
// Sharpening toggle
sharpeningToggle.addEventListener('change', () => {
processVideos();
});
// Save button
saveButton.addEventListener('click', () => {
GM_setValue('videoEnhancementEnabled', sharpeningToggle.checked);
GM_setValue('videoContrast', parseFloat(contrastSlider.value));
GM_setValue('videoSaturation', parseFloat(saturationSlider.value));
processVideos();
});
// Close button
closeButton.addEventListener('click', () => {
panel.style.display = 'none';
});
}
// Create SVG filter
function createSharpeningFilter() {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
svg.setAttribute('style', 'display:none');
const filter = document.createElementNS('http://www.w3.org/2000/svg', 'filter');
filter.setAttribute('id', 'video-enhancement-filter');
const feConvolveMatrix = document.createElementNS('http://www.w3.org/2000/svg', 'feConvolveMatrix');
feConvolveMatrix.setAttribute('order', '3');
feConvolveMatrix.setAttribute('kernelMatrix', '1 -1 1 -1 -1 -1 1 -1 1');
filter.appendChild(feConvolveMatrix);
svg.appendChild(filter);
return svg;
}
// Apply filter to video
function applyVideoFilter(video, contrast, saturation, isEnabled) {
if (isEnabled) {
video.style.filter = `url(#video-enhancement-filter) contrast(${contrast}) saturate(${saturation})`;
video.videoEnhancementApplied = true;
} else {
video.style.filter = '';
video.videoEnhancementApplied = false;
}
}
// Main function to process videos
function processVideos() {
const isEnabled = GM_getValue('videoEnhancementEnabled', DEFAULT_ENABLED);
const contrast = GM_getValue('videoContrast', DEFAULT_CONTRAST);
const saturation = GM_getValue('videoSaturation', DEFAULT_SATURATION);
const videos = document.querySelectorAll('video');
videos.forEach(video => {
applyVideoFilter(video, contrast, saturation, isEnabled);
});
}
// Initialization
function init() {
// Append SVG filter to document
document.body.appendChild(createSharpeningFilter());
// Initial video processing
processVideos();
// MutationObserver to handle dynamically added videos
const observer = new MutationObserver(processVideos);
observer.observe(document.body, { childList: true, subtree: true });
// Register Tampermonkey menu commands
GM_registerMenuCommand('Open Video Enhancement Panel', () => {
createEnhancementPanel();
});
GM_registerMenuCommand('Toggle Video Enhancement', () => {
const currentState = GM_getValue('videoEnhancementEnabled', DEFAULT_ENABLED);
GM_setValue('videoEnhancementEnabled', !currentState);
processVideos();
});
GM_registerMenuCommand('Reset to Default Settings', () => {
GM_setValue('videoEnhancementEnabled', DEFAULT_ENABLED);
GM_setValue('videoContrast', DEFAULT_CONTRAST);
GM_setValue('videoSaturation', DEFAULT_SATURATION);
processVideos();
});
}
// Run initialization
init();
})();