-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontent-script.js
79 lines (68 loc) · 1.89 KB
/
content-script.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
chrome.extension.onMessage.addListener(function(message, sender, sendResponse) {
switch (message.type) {
case "scroll-down":
scrollDown();
break;
case "scroll-up":
scrollUp();
break;
}
});
function scrollDown() {
$("html, body").animate({
scrollTop: $(document).scrollTop() + window.innerHeight - 100
}, 400);
}
function scrollUp() {
$("html, body").animate({
scrollTop: $(document).scrollTop() - window.innerHeight + 100
}, 400);
}
// var video = null;
// var canvas = null;
// var ctx = null;
// createVideoHUD();
// createCanvas();
// startSnapshotting();
function createVideoHUD() {
video = document.createElement('video');
video.setAttribute('autoplay', '');
video.setAttribute('width', '320');
video.setAttribute('height', '240');
video.style.position = 'fixed';
video.style.top = 0;
video.style.right = 0;
document.body.appendChild(video);
if (navigator.getUserMedia) {
navigator.getUserMedia({ video: true }, handleVideo, videoError);
}
function handleVideo(stream) {
video.src = window.URL.createObjectURL(stream);
video.play();
}
function videoError(e) {
alert("Error with webcam video.");
console.log(e);
}
}
function createCanvas() {
canvas = document.createElement('canvas');
canvas.setAttribute('width', '300');
canvas.setAttribute('height', '240');
canvas.style.position = 'fixed';
canvas.style.top = 0;
canvas.style.left = 0;
document.body.appendChild(canvas);
}
function startSnapshotting() {
ctx = canvas.getContext('2d');
var timer = setInterval(sendSnapshot, 20);
}
function sendSnapshot() {
ctx.drawImage(video, 0, 0, 300, 240);
var data = canvas.toDataURL('image/png');
chrome.extension.sendMessage({
type: "snapshot",
payload: data
});
}