Skip to content

Commit 862b167

Browse files
authored
Merge pull request #71 from SentienceAPI/sync-extension-v2.0.6
Sync Extension: v2.0.6
2 parents 1d87278 + 8a40db7 commit 862b167

File tree

5 files changed

+221
-30
lines changed

5 files changed

+221
-30
lines changed

sentience/extension/content.js

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ window.addEventListener('message', (event) => {
2525
handleSnapshotRequest(event.data);
2626
break;
2727

28+
case 'SENTIENCE_SHOW_OVERLAY':
29+
handleShowOverlay(event.data);
30+
break;
31+
32+
case 'SENTIENCE_CLEAR_OVERLAY':
33+
handleClearOverlay();
34+
break;
35+
2836
default:
2937
// Ignore unknown message types
3038
break;
@@ -135,4 +143,156 @@ function handleSnapshotRequest(data) {
135143
}
136144
}
137145

146+
// ============================================================================
147+
// Visual Overlay - Shadow DOM Implementation
148+
// ============================================================================
149+
150+
const OVERLAY_HOST_ID = 'sentience-overlay-host';
151+
let overlayTimeout = null;
152+
153+
/**
154+
* Show visual overlay highlighting elements using Shadow DOM
155+
* @param {Object} data - Message data with elements and targetElementId
156+
*/
157+
function handleShowOverlay(data) {
158+
const { elements, targetElementId } = data;
159+
160+
if (!elements || !Array.isArray(elements)) {
161+
console.warn('[Sentience Bridge] showOverlay: elements must be an array');
162+
return;
163+
}
164+
165+
removeOverlay();
166+
167+
// Create host with Shadow DOM for CSS isolation
168+
const host = document.createElement('div');
169+
host.id = OVERLAY_HOST_ID;
170+
host.style.cssText = `
171+
position: fixed !important;
172+
top: 0 !important;
173+
left: 0 !important;
174+
width: 100vw !important;
175+
height: 100vh !important;
176+
pointer-events: none !important;
177+
z-index: 2147483647 !important;
178+
margin: 0 !important;
179+
padding: 0 !important;
180+
`;
181+
document.body.appendChild(host);
182+
183+
// Attach shadow root (closed mode for security and CSS isolation)
184+
const shadow = host.attachShadow({ mode: 'closed' });
185+
186+
// Calculate max importance for scaling
187+
const maxImportance = Math.max(...elements.map(e => e.importance || 0), 1);
188+
189+
elements.forEach((element) => {
190+
const bbox = element.bbox;
191+
if (!bbox) return;
192+
193+
const isTarget = element.id === targetElementId;
194+
const isPrimary = element.visual_cues?.is_primary || false;
195+
const importance = element.importance || 0;
196+
197+
// Color: Red (target), Blue (primary), Green (regular)
198+
let color;
199+
if (isTarget) color = '#FF0000';
200+
else if (isPrimary) color = '#0066FF';
201+
else color = '#00FF00';
202+
203+
// Scale opacity and border width based on importance
204+
const importanceRatio = maxImportance > 0 ? importance / maxImportance : 0.5;
205+
const borderOpacity = isTarget ? 1.0 : (isPrimary ? 0.9 : Math.max(0.4, 0.5 + importanceRatio * 0.5));
206+
const fillOpacity = borderOpacity * 0.2;
207+
const borderWidth = isTarget ? 2 : (isPrimary ? 1.5 : Math.max(0.5, Math.round(importanceRatio * 2)));
208+
209+
// Convert fill opacity to hex for background-color
210+
const hexOpacity = Math.round(fillOpacity * 255).toString(16).padStart(2, '0');
211+
212+
// Create box with semi-transparent fill
213+
const box = document.createElement('div');
214+
box.style.cssText = `
215+
position: absolute;
216+
left: ${bbox.x}px;
217+
top: ${bbox.y}px;
218+
width: ${bbox.width}px;
219+
height: ${bbox.height}px;
220+
border: ${borderWidth}px solid ${color};
221+
background-color: ${color}${hexOpacity};
222+
box-sizing: border-box;
223+
opacity: ${borderOpacity};
224+
pointer-events: none;
225+
`;
226+
227+
// Add badge showing importance score
228+
if (importance > 0 || isPrimary) {
229+
const badge = document.createElement('span');
230+
badge.textContent = isPrimary ? `⭐${importance}` : `${importance}`;
231+
badge.style.cssText = `
232+
position: absolute;
233+
top: -18px;
234+
left: 0;
235+
background: ${color};
236+
color: white;
237+
font-size: 11px;
238+
font-weight: bold;
239+
padding: 2px 6px;
240+
font-family: Arial, sans-serif;
241+
border-radius: 3px;
242+
opacity: 0.95;
243+
white-space: nowrap;
244+
pointer-events: none;
245+
`;
246+
box.appendChild(badge);
247+
}
248+
249+
// Add target emoji for target element
250+
if (isTarget) {
251+
const targetIndicator = document.createElement('span');
252+
targetIndicator.textContent = '🎯';
253+
targetIndicator.style.cssText = `
254+
position: absolute;
255+
top: -18px;
256+
right: 0;
257+
font-size: 16px;
258+
pointer-events: none;
259+
`;
260+
box.appendChild(targetIndicator);
261+
}
262+
263+
shadow.appendChild(box);
264+
});
265+
266+
console.log(`[Sentience Bridge] Overlay shown for ${elements.length} elements`);
267+
268+
// Auto-remove after 5 seconds
269+
overlayTimeout = setTimeout(() => {
270+
removeOverlay();
271+
console.log('[Sentience Bridge] Overlay auto-cleared after 5 seconds');
272+
}, 5000);
273+
}
274+
275+
/**
276+
* Clear overlay manually
277+
*/
278+
function handleClearOverlay() {
279+
removeOverlay();
280+
console.log('[Sentience Bridge] Overlay cleared manually');
281+
}
282+
283+
/**
284+
* Remove overlay from DOM
285+
*/
286+
function removeOverlay() {
287+
const existing = document.getElementById(OVERLAY_HOST_ID);
288+
if (existing) {
289+
existing.remove();
290+
}
291+
292+
if (overlayTimeout) {
293+
clearTimeout(overlayTimeout);
294+
overlayTimeout = null;
295+
}
296+
}
297+
138298
// console.log('[Sentience Bridge] Ready - Extension ID:', chrome.runtime.id);

sentience/extension/injected_api.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,5 +1435,36 @@
14351435
}
14361436
};
14371437

1438+
/**
1439+
* Show overlay highlighting specific elements with Shadow DOM
1440+
* @param {Array} elements - List of elements with bbox, importance, visual_cues
1441+
* @param {number} targetElementId - Optional ID of target element (shown in red)
1442+
*/
1443+
window.sentience.showOverlay = function(elements, targetElementId = null) {
1444+
if (!elements || !Array.isArray(elements)) {
1445+
console.warn('[Sentience] showOverlay: elements must be an array');
1446+
return;
1447+
}
1448+
1449+
window.postMessage({
1450+
type: 'SENTIENCE_SHOW_OVERLAY',
1451+
elements: elements,
1452+
targetElementId: targetElementId,
1453+
timestamp: Date.now()
1454+
}, '*');
1455+
1456+
console.log(`[Sentience] Overlay requested for ${elements.length} elements`);
1457+
};
1458+
1459+
/**
1460+
* Clear overlay manually
1461+
*/
1462+
window.sentience.clearOverlay = function() {
1463+
window.postMessage({
1464+
type: 'SENTIENCE_CLEAR_OVERLAY'
1465+
}, '*');
1466+
console.log('[Sentience] Overlay cleared');
1467+
};
1468+
14381469
console.log('[SentienceAPI] ✓ Ready! (CSP-Resistant - WASM runs in background)');
14391470
})();

sentience/extension/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "Sentience Semantic Visual Grounding Extractor",
4-
"version": "2.0.5",
4+
"version": "2.0.6",
55
"description": "Extract semantic visual grounding data from web pages",
66
"permissions": ["activeTab", "scripting"],
77
"host_permissions": ["<all_urls>"],
0 Bytes
Binary file not shown.

sentience/extension/release.json

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
2-
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273049720",
3-
"assets_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273049720/assets",
4-
"upload_url": "https://uploads.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273049720/assets{?name,label}",
5-
"html_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/tag/v2.0.5",
6-
"id": 273049720,
2+
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273088651",
3+
"assets_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273088651/assets",
4+
"upload_url": "https://uploads.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273088651/assets{?name,label}",
5+
"html_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/tag/v2.0.6",
6+
"id": 273088651,
77
"author": {
88
"login": "rcholic",
99
"id": 135060,
@@ -25,21 +25,21 @@
2525
"user_view_type": "public",
2626
"site_admin": false
2727
},
28-
"node_id": "RE_kwDOQshiJ84QRmh4",
29-
"tag_name": "v2.0.5",
28+
"node_id": "RE_kwDOQshiJ84QRwCL",
29+
"tag_name": "v2.0.6",
3030
"target_commitish": "main",
31-
"name": "Release v2.0.5",
31+
"name": "Release v2.0.6",
3232
"draft": false,
3333
"immutable": false,
3434
"prerelease": false,
35-
"created_at": "2025-12-28T06:21:06Z",
36-
"updated_at": "2025-12-28T06:52:14Z",
37-
"published_at": "2025-12-28T06:52:03Z",
35+
"created_at": "2025-12-28T18:16:01Z",
36+
"updated_at": "2025-12-28T18:16:59Z",
37+
"published_at": "2025-12-28T18:16:49Z",
3838
"assets": [
3939
{
40-
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/333698157",
41-
"id": 333698157,
42-
"node_id": "RA_kwDOQshiJ84T49Rt",
40+
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/333817321",
41+
"id": 333817321,
42+
"node_id": "RA_kwDOQshiJ84T5aXp",
4343
"name": "extension-files.tar.gz",
4444
"label": "",
4545
"uploader": {
@@ -65,17 +65,17 @@
6565
},
6666
"content_type": "application/gzip",
6767
"state": "uploaded",
68-
"size": 76157,
69-
"digest": "sha256:726e388826fc3a5c401250db27ebd663167a96205594608b1bed2c98196cabab",
68+
"size": 78026,
69+
"digest": "sha256:d8ff48cfac38e8a3fe2408f7dacc93fb1c76e4772e7f981545c920aea18998ba",
7070
"download_count": 0,
71-
"created_at": "2025-12-28T06:52:13Z",
72-
"updated_at": "2025-12-28T06:52:14Z",
73-
"browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.0.5/extension-files.tar.gz"
71+
"created_at": "2025-12-28T18:16:59Z",
72+
"updated_at": "2025-12-28T18:16:59Z",
73+
"browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.0.6/extension-files.tar.gz"
7474
},
7575
{
76-
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/333698156",
77-
"id": 333698156,
78-
"node_id": "RA_kwDOQshiJ84T49Rs",
76+
"url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/333817320",
77+
"id": 333817320,
78+
"node_id": "RA_kwDOQshiJ84T5aXo",
7979
"name": "extension-package.zip",
8080
"label": "",
8181
"uploader": {
@@ -101,15 +101,15 @@
101101
},
102102
"content_type": "application/zip",
103103
"state": "uploaded",
104-
"size": 78281,
105-
"digest": "sha256:311a65065fef9c6d4b02597e4680e9e3f408f0d721a1d7595f6090ad3d794793",
104+
"size": 80099,
105+
"digest": "sha256:4cb46868d668337ea10ae7ea1b9ff07fc87b947bad3f877d3f4250902fe8610f",
106106
"download_count": 0,
107-
"created_at": "2025-12-28T06:52:13Z",
108-
"updated_at": "2025-12-28T06:52:13Z",
109-
"browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.0.5/extension-package.zip"
107+
"created_at": "2025-12-28T18:16:59Z",
108+
"updated_at": "2025-12-28T18:16:59Z",
109+
"browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.0.6/extension-package.zip"
110110
}
111111
],
112-
"tarball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/tarball/v2.0.5",
113-
"zipball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/zipball/v2.0.5",
112+
"tarball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/tarball/v2.0.6",
113+
"zipball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/zipball/v2.0.6",
114114
"body": ""
115115
}

0 commit comments

Comments
 (0)