-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinject.js
More file actions
executable file
·79 lines (68 loc) · 2.24 KB
/
inject.js
File metadata and controls
executable file
·79 lines (68 loc) · 2.24 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
function imdifferenter() {
let addedPopup = false;
let isKeyDown = {'a': false, 's': false};
let left = null;
let right = null;
let popup = null;
function compare() {
if (!left || !right) {
return;
}
if (!addedPopup) {
addedPopup = true;
popup = document.createElement('CANVAS');
popup.style.position = 'fixed';
popup.style.cursor = 'pointer';
popup.style.border = 'solid red 1px';
popup.style.zIndex = 9999;
popup.style.left = 0;
popup.style.top = 0;
document.body.appendChild(popup);
}
const maxWidth = window.innerWidth * 0.75;
const maxHeight = window.innerHeight * 0.75;
let lw = Math.max(left.width, left.naturalWidth);
let rw = Math.max(right.width, right.naturalWidth);
let lh = Math.max(left.height, left.naturalHeight);
let rh = Math.max(right.height, right.naturalHeight);
popup.width = Math.min(Math.max(lw, rw), maxWidth);
popup.height = Math.min(Math.max(lh, rh), maxHeight);
let leftScale = Math.min(popup.width / lw, popup.height / lh);
let rightScale = Math.min(popup.width / rw, popup.height / rh);
popup.width = Math.max(lw * leftScale, rw * rightScale);
popup.height = Math.max(lh * leftScale, rh * rightScale);
popup.style.display = 'block';
let c = popup.getContext('2d');
c.save();
c.drawImage(left, 0, 0, lw, lh, 0, 0, lw * leftScale, lh * leftScale);
c.globalCompositeOperation = 'difference';
c.drawImage(right, 0, 0, rw, rh, 0, 0, rw * rightScale, rh * rightScale);
c.globalCompositeOperation = 'source-over';
c.filter = 'brightness(200%)';
c.drawImage(popup, 0, 0);
c.restore();
}
window.addEventListener('click', (e) => {
let target = e.path[0];
if (target === popup) {
popup.style.display = 'none';
return;
}
if (target.nodeName === 'CANVAS' || target.nodeName === 'IMG') {
if (isKeyDown.a) {
left = target;
compare();
}
if (isKeyDown.s) {
right = target;
compare();
}
}
});
window.addEventListener('keydown', (e) => {
isKeyDown[e.key.toLowerCase()] = true;
});
window.addEventListener('keyup', (e) => {
isKeyDown[e.key.toLowerCase()] = false;
});
}; imdifferenter();