moving
Some checks failed
Installer Smoke / installer-smoke (push) Has been cancelled

This commit is contained in:
Oleg Maslov
2026-09-02 10:10:29 +02:00
commit 0c3e2ead3b
3841 changed files with 970576 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
// Waggle Companion content script — runs on every page, responds to
// "extract" messages from the popup with the current selection + the
// page's main text. Page-text extraction is intentionally simple
// (innerText of the body, trimmed) — the right place to do article
// extraction is server-side once the user opts in.
chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => {
if (msg?.type !== 'extract') return;
try {
const selection = String(window.getSelection?.() || '').trim();
const bodyText = (document.body?.innerText || '').replace(/\s+\n/g, '\n').trim();
sendResponse({
selection,
page: {
url: location.href,
title: document.title || location.href,
// Cap at 12k chars so popup → background message-passing stays snappy.
// Server-side ingest pipeline can re-fetch the URL for the full body.
text: bodyText.slice(0, 12000),
},
});
} catch (err) {
sendResponse({ selection: '', page: null, error: String(err) });
}
// Returning true keeps the message channel open for the async sendResponse.
return true;
});