From 66c13e2952882556054798e4908744d488342893 Mon Sep 17 00:00:00 2001 From: rcholic Date: Sun, 28 Dec 2025 06:56:13 +0000 Subject: [PATCH] chore: sync extension files from sentience-chrome v2.0.5 --- sentience-chrome/injected_api.js | 148 +++++++++++++++++++++++++++++++ sentience-chrome/manifest.json | 2 +- sentience-chrome/release.json | 93 ++++++++++--------- 3 files changed, 195 insertions(+), 48 deletions(-) diff --git a/sentience-chrome/injected_api.js b/sentience-chrome/injected_api.js index 1cff1d6e..dac0f552 100644 --- a/sentience-chrome/injected_api.js +++ b/sentience-chrome/injected_api.js @@ -1083,6 +1083,154 @@ }; }, + // 2b. Find Text Rectangle - Get exact pixel coordinates of specific text + findTextRect: (options = {}) => { + const { + text, + containerElement = document.body, + caseSensitive = false, + wholeWord = false, + maxResults = 10 + } = options; + + if (!text || text.trim().length === 0) { + return { + status: "error", + error: "Text parameter is required" + }; + } + + const results = []; + const searchText = caseSensitive ? text : text.toLowerCase(); + + // Helper function to find text in a single text node + function findInTextNode(textNode) { + const nodeText = textNode.nodeValue; + const searchableText = caseSensitive ? nodeText : nodeText.toLowerCase(); + + let startIndex = 0; + while (startIndex < nodeText.length && results.length < maxResults) { + const foundIndex = searchableText.indexOf(searchText, startIndex); + + if (foundIndex === -1) break; + + // Check whole word matching if required + if (wholeWord) { + const before = foundIndex > 0 ? nodeText[foundIndex - 1] : ' '; + const after = foundIndex + text.length < nodeText.length + ? nodeText[foundIndex + text.length] + : ' '; + + // Check if surrounded by word boundaries + if (!/\s/.test(before) || !/\s/.test(after)) { + startIndex = foundIndex + 1; + continue; + } + } + + try { + // Create range for this occurrence + const range = document.createRange(); + range.setStart(textNode, foundIndex); + range.setEnd(textNode, foundIndex + text.length); + + const rect = range.getBoundingClientRect(); + + // Only include visible rectangles + if (rect.width > 0 && rect.height > 0) { + results.push({ + text: nodeText.substring(foundIndex, foundIndex + text.length), + rect: { + x: rect.left + window.scrollX, + y: rect.top + window.scrollY, + width: rect.width, + height: rect.height, + left: rect.left + window.scrollX, + top: rect.top + window.scrollY, + right: rect.right + window.scrollX, + bottom: rect.bottom + window.scrollY + }, + viewport_rect: { + x: rect.left, + y: rect.top, + width: rect.width, + height: rect.height + }, + context: { + before: nodeText.substring(Math.max(0, foundIndex - 20), foundIndex), + after: nodeText.substring(foundIndex + text.length, Math.min(nodeText.length, foundIndex + text.length + 20)) + }, + in_viewport: ( + rect.top >= 0 && + rect.left >= 0 && + rect.bottom <= window.innerHeight && + rect.right <= window.innerWidth + ) + }); + } + } catch (e) { + console.warn('[SentienceAPI] Failed to get rect for text:', e); + } + + startIndex = foundIndex + 1; + } + } + + // Tree walker to find all text nodes + const walker = document.createTreeWalker( + containerElement, + NodeFilter.SHOW_TEXT, + { + acceptNode: function(node) { + // Skip script, style, and empty text nodes + const parent = node.parentElement; + if (!parent) return NodeFilter.FILTER_REJECT; + + const tagName = parent.tagName.toLowerCase(); + if (tagName === 'script' || tagName === 'style' || tagName === 'noscript') { + return NodeFilter.FILTER_REJECT; + } + + // Skip whitespace-only nodes + if (!node.nodeValue || node.nodeValue.trim().length === 0) { + return NodeFilter.FILTER_REJECT; + } + + // Check if element is visible + const computedStyle = window.getComputedStyle(parent); + if (computedStyle.display === 'none' || + computedStyle.visibility === 'hidden' || + computedStyle.opacity === '0') { + return NodeFilter.FILTER_REJECT; + } + + return NodeFilter.FILTER_ACCEPT; + } + } + ); + + // Walk through all text nodes + let currentNode; + while ((currentNode = walker.nextNode()) && results.length < maxResults) { + findInTextNode(currentNode); + } + + return { + status: "success", + query: text, + case_sensitive: caseSensitive, + whole_word: wholeWord, + matches: results.length, + results: results, + viewport: { + width: window.innerWidth, + height: window.innerHeight, + scroll_x: window.scrollX, + scroll_y: window.scrollY + } + }; + }, + // 3. Click Action (unchanged) click: (id) => { const el = window.sentience_registry[id]; diff --git a/sentience-chrome/manifest.json b/sentience-chrome/manifest.json index e55a0356..2fb72489 100644 --- a/sentience-chrome/manifest.json +++ b/sentience-chrome/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "Sentience Semantic Visual Grounding Extractor", - "version": "2.0.4", + "version": "2.0.5", "description": "Extract semantic visual grounding data from web pages", "permissions": ["activeTab", "scripting"], "host_permissions": [""], diff --git a/sentience-chrome/release.json b/sentience-chrome/release.json index e3db148a..8f835b6e 100644 --- a/sentience-chrome/release.json +++ b/sentience-chrome/release.json @@ -1,45 +1,45 @@ { - "url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273046101", - "assets_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273046101/assets", - "upload_url": "https://uploads.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273046101/assets{?name,label}", - "html_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/tag/v2.0.4", - "id": 273046101, + "url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273049720", + "assets_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273049720/assets", + "upload_url": "https://uploads.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/273049720/assets{?name,label}", + "html_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/tag/v2.0.5", + "id": 273049720, "author": { - "login": "github-actions[bot]", - "id": 41898282, - "node_id": "MDM6Qm90NDE4OTgyODI=", - "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "login": "rcholic", + "id": 135060, + "node_id": "MDQ6VXNlcjEzNTA2MA==", + "avatar_url": "https://avatars.githubusercontent.com/u/135060?v=4", "gravatar_id": "", - "url": "https://api.github.com/users/github-actions%5Bbot%5D", - "html_url": "https://github.com/apps/github-actions", - "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", - "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", - "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", - "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", - "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", - "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", - "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", - "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", - "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", - "type": "Bot", + "url": "https://api.github.com/users/rcholic", + "html_url": "https://github.com/rcholic", + "followers_url": "https://api.github.com/users/rcholic/followers", + "following_url": "https://api.github.com/users/rcholic/following{/other_user}", + "gists_url": "https://api.github.com/users/rcholic/gists{/gist_id}", + "starred_url": "https://api.github.com/users/rcholic/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/rcholic/subscriptions", + "organizations_url": "https://api.github.com/users/rcholic/orgs", + "repos_url": "https://api.github.com/users/rcholic/repos", + "events_url": "https://api.github.com/users/rcholic/events{/privacy}", + "received_events_url": "https://api.github.com/users/rcholic/received_events", + "type": "User", "user_view_type": "public", "site_admin": false }, - "node_id": "RE_kwDOQshiJ84QRlpV", - "tag_name": "v2.0.4", + "node_id": "RE_kwDOQshiJ84QRmh4", + "tag_name": "v2.0.5", "target_commitish": "main", - "name": "Release v2.0.4", + "name": "Release v2.0.5", "draft": false, "immutable": false, "prerelease": false, - "created_at": "2025-12-28T05:42:53Z", - "updated_at": "2025-12-28T05:44:58Z", - "published_at": "2025-12-28T05:44:57Z", + "created_at": "2025-12-28T06:21:06Z", + "updated_at": "2025-12-28T06:52:14Z", + "published_at": "2025-12-28T06:52:03Z", "assets": [ { - "url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/333683577", - "id": 333683577, - "node_id": "RA_kwDOQshiJ84T45t5", + "url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/333698157", + "id": 333698157, + "node_id": "RA_kwDOQshiJ84T49Rt", "name": "extension-files.tar.gz", "label": "", "uploader": { @@ -65,17 +65,17 @@ }, "content_type": "application/gzip", "state": "uploaded", - "size": 73579, - "digest": "sha256:664d4476dc5741e0df63d6264db43a63b9ab2a4deac3049a1e61e084ebf2639c", + "size": 76157, + "digest": "sha256:726e388826fc3a5c401250db27ebd663167a96205594608b1bed2c98196cabab", "download_count": 0, - "created_at": "2025-12-28T05:44:58Z", - "updated_at": "2025-12-28T05:44:58Z", - "browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.0.4/extension-files.tar.gz" + "created_at": "2025-12-28T06:52:13Z", + "updated_at": "2025-12-28T06:52:14Z", + "browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.0.5/extension-files.tar.gz" }, { - "url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/333683578", - "id": 333683578, - "node_id": "RA_kwDOQshiJ84T45t6", + "url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/assets/333698156", + "id": 333698156, + "node_id": "RA_kwDOQshiJ84T49Rs", "name": "extension-package.zip", "label": "", "uploader": { @@ -101,16 +101,15 @@ }, "content_type": "application/zip", "state": "uploaded", - "size": 75736, - "digest": "sha256:b817ac0bba53872e6f725b38e16063c476790b8498953c1bec3d645ebcbebfb4", + "size": 78281, + "digest": "sha256:311a65065fef9c6d4b02597e4680e9e3f408f0d721a1d7595f6090ad3d794793", "download_count": 0, - "created_at": "2025-12-28T05:44:58Z", - "updated_at": "2025-12-28T05:44:58Z", - "browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.0.4/extension-package.zip" + "created_at": "2025-12-28T06:52:13Z", + "updated_at": "2025-12-28T06:52:13Z", + "browser_download_url": "https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/releases/download/v2.0.5/extension-package.zip" } ], - "tarball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/tarball/v2.0.4", - "zipball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/zipball/v2.0.4", - "body": "## What's Changed\n* short iframe wait form 10 to 5; skip ad junk sites by @rcholic in https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/pull/18\n\n\n**Full Changelog**: https://github.com/SentienceAPI/Sentience-Geometry-Chrome-Extension/compare/v2.0.2...v2.0.4", - "mentions_count": 1 + "tarball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/tarball/v2.0.5", + "zipball_url": "https://api.github.com/repos/SentienceAPI/Sentience-Geometry-Chrome-Extension/zipball/v2.0.5", + "body": "" }