-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuniversal-video-sharpness-css-filter.user.js
More file actions
128 lines (113 loc) · 3.75 KB
/
universal-video-sharpness-css-filter.user.js
File metadata and controls
128 lines (113 loc) · 3.75 KB
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
// ==UserScript==
// @name Universal Video Sharpener (CSS Filter)
// @namespace http://tampermonkey.net/
// @version 1.3
// @description Applies video sharpening using CSS filters across websites
// @match *://*/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_registerMenuCommand
// @grant GM_notification
// @license MIT
// ==/UserScript==
(function() {
'use strict';
// Configuration
const CONFIG = {
contrast: 1.1,
brightness: 1.2,
saturate: 1.1,
debugMode: false
};
// Logging function
function log(message) {
if (CONFIG.debugMode) {
console.log(`[Video Sharpener] ${message}`);
}
}
// Detect if an element is likely a video
function isVideoElement(element) {
return element instanceof HTMLVideoElement &&
element.videoWidth > 0 &&
element.videoHeight > 0;
}
// Apply CSS sharpness filter
function applySharpnessFilter(video, isEnabled) {
if (!video) return;
try {
if (isEnabled) {
const { contrast, brightness, saturate } = CONFIG;
video.style.filter = `
contrast(${contrast})
brightness(${brightness})
saturate(${saturate})
`;
video.dataset.sharpened = 'true';
log('CSS Sharpness filter applied');
} else {
video.style.filter = 'none';
delete video.dataset.sharpened;
log('Sharpness filter removed');
}
} catch (error) {
console.error('Error applying sharpness filter:', error);
}
}
// Update all videos on the page
function updateAllVideos(isEnabled) {
const videos = document.querySelectorAll('video');
videos.forEach(video => {
if (isVideoElement(video)) {
applySharpnessFilter(video, isEnabled);
}
});
}
// Main processing function
function processVideos() {
const isScriptEnabled = GM_getValue('universalSharpenerEnabled', false);
const videos = document.querySelectorAll('video:not([data-sharpened])');
videos.forEach(video => {
if (isVideoElement(video)) {
applySharpnessFilter(video, isScriptEnabled);
}
});
}
// Toggle function with notification
function toggleSharpener() {
const currentState = GM_getValue('universalSharpenerEnabled', false);
const newState = !currentState;
GM_setValue('universalSharpenerEnabled', newState);
// Update all existing videos
updateAllVideos(newState);
// Show notification
GM_notification({
text: `Video Sharpener: ${newState ? 'Enabled' : 'Disabled'}`,
timeout: 2000,
title: 'Video Sharpener'
});
}
// Initialize script
function initScript() {
// Get initial state
const isEnabled = GM_getValue('universalSharpenerEnabled', false);
// Register menu command with state indicator
GM_registerMenuCommand(
`${isEnabled ? '✓' : '✗'} Toggle Video Sharpener`,
toggleSharpener
);
// Use MutationObserver for dynamic content
const observer = new MutationObserver(() => {
processVideos();
});
// Observe the entire document for changes
observer.observe(document.body, {
childList: true,
subtree: true
});
// Initial processing and periodic check
processVideos();
setInterval(processVideos, 3000);
}
// Start script
initScript();
})();