-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_script.js
More file actions
61 lines (52 loc) · 1.85 KB
/
content_script.js
File metadata and controls
61 lines (52 loc) · 1.85 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
// content_script.js
// This script injects WebGazer and our main functionality into the page
// First, inject our actual implementation into the page context
function injectScript() {
// Create a script element to load WebGazer
const webgazerScript = document.createElement("script");
webgazerScript.src = chrome.runtime.getURL("webgazer.js");
webgazerScript.onload = function () {
// Once WebGazer is loaded, inject our main functionality
const mainScript = document.createElement("script");
mainScript.src = chrome.runtime.getURL("main.js");
document.head.appendChild(mainScript);
console.log("WebGazer and main script injected successfully");
};
document.head.appendChild(webgazerScript);
// Add our status elements
createStatusElements();
}
// Create UI elements for feedback and status
function createStatusElements() {
// Create eye tracker indicator
const indicator = document.createElement("div");
indicator.id = "eye-tracker-indicator";
indicator.style.display = "none";
document.body.appendChild(indicator);
// Create status overlay
const status = document.createElement("div");
status.id = "eye-tracker-status";
status.style.display = "none";
document.body.appendChild(status);
}
// Add CSS to the page
function injectCSS() {
const link = document.createElement("link");
link.rel = "stylesheet";
link.type = "text/css";
link.href = chrome.runtime.getURL("content.css");
document.head.appendChild(link);
}
// Listen for messages from the popup
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
// Forward messages to the page script using window events
window.dispatchEvent(
new CustomEvent("eyeTrackerExtensionMessage", {
detail: request,
})
);
});
// Initialize everything
injectCSS();
injectScript();
console.log("Eye-tracking content script initialized");