-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontent.js
57 lines (46 loc) · 1.41 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
const rotatedClass = '__mirror-extension-rotated__';
const duration = 500;
let target = null;
document.onmouseup = e => {
if (e.button !== 2 || e.shiftKey !== true) return;
target = e.target.querySelector('video') || e.target;
}
document.oncontextmenu = (e) => {
target = e.target.querySelector('video') || e.target;
}
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (target === null || request.id !== 'mirror') return;
mirror();
});
function mirror() {
if (target.classList.contains(rotatedClass) !== true) {
target.animate(
[
{ transform: 'rotateY(0)' },
{ transform: 'rotateY(180deg)' }
],
{
duration: duration,
iterations: 1,
fill: 'both'
}
);
target.classList.add(rotatedClass);
target.setAttribute('data-mirror-angle', `180`);
} else {
const angle = parseInt(target.getAttribute('data-mirror-angle'));
target.animate(
[
{ transform: `rotateY(${angle}deg)` },
{ transform: `rotateY(${angle + 180}deg)` },
],
{
duration: duration,
iterations: 1,
fill: 'both'
}
);
target.setAttribute('data-mirror-angle', `${angle + 180}`);
}
target = null;
}