This repository was archived by the owner on Dec 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebfsr.content.js
More file actions
138 lines (109 loc) · 3.46 KB
/
webfsr.content.js
File metadata and controls
138 lines (109 loc) · 3.46 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
129
130
131
132
133
134
135
136
137
138
function getAllVideoTags() {
return document.getElementsByTagName("video");
}
function getAllImageTags() {
return document.getElementsByTagName("img");
}
function getAllCanvasTags() {
return document.getElementsByTagName("canvas");
}
function getVideoResolution(htmlVideo) {
let width = htmlVideo.videoWidth;
let height = htmlVideo.videoHeight;
return { width, height };
}
function getClientResolution(htmlElement) {
let scale = window.devicePixelRatio;
let width = htmlElement.clientWidth * scale;
let height = htmlElement.clientHeight * scale;
return { width, height };
}
function isVideoResolutionSmallerThanViewport(videoElement) {
let videoResolution = getVideoResolution(videoElement);
let clientResolution = getClientResolution(videoElement);
return videoResolution.width < clientResolution.width || videoResolution.height < clientResolution.height;
}
let videoTags = Array.from(getAllVideoTags());
let imgTags = Array.from(getAllImageTags());
function hookVideoOnLoad(htmlVideo) {
htmlVideo.addEventListener('loadeddata', function () {
const vidFilter = new ImageShader();
htmlVideo.after(vidFilter.canvas);
htmlVideo.crossorigin = 'anonymous';
vidFilter.canvas.height = htmlVideo.height;
vidFilter.canvas.width = htmlVideo.width;
vidFilter.className = htmlVideo.className;
//htmlVideo.style.display = "none";
//do video element processing
if (isVideoResolutionSmallerThanViewport(htmlVideo)) {
//apply easu
}
const draw = () => {
if(htmlVideo.paused)
return;
requestAnimationFrame(draw);
vidFilter.setImage(htmlVideo);
vidFilter.render();
}
htmlVideo.addEventListener('play', function() {
draw();
});
//apply rcas
});
}
function hookImgTag(imgTag) {
const imgFilter = new ImageShader();
imgFilter.setImage(imgTag);
imgFilter.render();
//imgTag.src = filteredImage.toDataURL();
//replacing is somehow faster
//imgFilter.canvas.className = imgTag.className;
//imgTag.replaceWith(imgFilter.canvas);
imgTag.src = imgFilter.canvas.toDataURL();
imgFilter.destroy();
}
function hookAllVideoTags() {
videoTags.forEach(videoTag => {
hookVideoOnLoad(videoTag);
});
}
function hookAllImgTags() {
imgTags.forEach(imgTag => {
hookImgTag(imgTag);
});
}
function hookAllTags() {
//hookAllVideoTags();
hookAllImgTags();
}
hookAllTags();
const observer = new MutationObserver(function (mutationsList, observer) {
for (let mutation of mutationsList) {
for (let addedNode of mutation.addedNodes) {
switch (addedNode.nodeName) {
case "video":
break;
case "img":
break;
case "canvas":
break;
default:
break;
}
}
}
});
observer.observe(document, { childList: true, subtree: true });
function printAllVideoTagsWithRes() {
let videoTags = getAllVideoTags();
}
chrome.runtime.sendMessage({ videoCount: videoTags.length });
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
switch (request.msg) {
case "update":
sendResponse({ videoCount: videoTags.length });
break;
}
}
)