Compare commits
4 Commits
a2afeff8e0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| bf30e64d59 | |||
| 7fdd0fc543 | |||
| 0cb2daa402 | |||
| cb6c077541 |
@@ -1367,27 +1367,43 @@ const FETCH_EXTRACT = `(async () => {
|
||||
return { url: location.href, status, text: document.body ? document.body.innerText : '' };
|
||||
})()`;
|
||||
|
||||
const SEARCH_EXTRACT = `(() => {
|
||||
const SEARCH_EXTRACT = `(async () => {
|
||||
const parse = () => {
|
||||
const clean = (s) => String(s || '').replace(/\\s+/g, ' ').trim();
|
||||
const out = []; const seen = new Set();
|
||||
// Engine-agnostic organic parse: a result headline is a heading inside a
|
||||
// link on Google and Bing alike — layout class names drift, this doesn't.
|
||||
for (const a of document.querySelectorAll('a[href]')) {
|
||||
const heading = a.querySelector('h2, h3');
|
||||
if (!heading) continue;
|
||||
let url = a.href;
|
||||
if (url.startsWith('/url?')) { const m = url.match(/[?&]url=([^&]+)/); if (m) { try { url = decodeURIComponent(m[1]); } catch {} } }
|
||||
if (!/^https?:/i.test(url) || seen.has(url)) continue;
|
||||
const title = clean(heading.innerText);
|
||||
const selfUrl = (u) => /^https?:\\/\\/(?:www\\.)?(?:bing|google|duckduckgo)\\./i.test(u);
|
||||
// Organic result headlines come in both directions now: heading inside the
|
||||
// link (Google: a > h3) AND link inside the heading (Bing: h2 > a). Match
|
||||
// both — engine class names drift, the heading/link nesting does not.
|
||||
for (const node of document.querySelectorAll('h2 a, h3 a, a h2, a h3')) {
|
||||
if (out.length >= 20) break;
|
||||
const link = node.matches('a') ? node : node.closest('a');
|
||||
if (!link) continue;
|
||||
let url = link.href;
|
||||
// Engines wrap organic URLs: Google /url?url=..., Bing /ck/a?u=a1<base64>.
|
||||
// Unwrap first — then apply the own-domain filter, or the wrappers eat
|
||||
// every real result.
|
||||
{ const m = url.match(/[?&]u=([^&]+)/); if (m) { let v = m[1]; if (v.startsWith('a1')) v = v.slice(2); try { const d = atob(v.replace(/-/g, '+').replace(/_/g, '/')); if (/^https?:/i.test(d)) url = d; } catch {} } }
|
||||
{ const m = url.match(/[?&](?:url|q)=([^&]+)/); if (m) { try { const d = decodeURIComponent(m[1]); if (/^https?:/i.test(d)) url = d; } catch {} } }
|
||||
if (!/^https?:/i.test(url) || seen.has(url) || selfUrl(url)) continue;
|
||||
const title = clean(link.innerText);
|
||||
if (!title || title.length < 4) continue;
|
||||
const box = a.closest('li,div.g,div.tF2Cxc,li.b_algo') || a.parentElement;
|
||||
const box = link.closest('li,div.g,div.tF2Cxc,li.b_algo,div.b_title,div[class*=result]') || link.parentElement;
|
||||
let snippet = box ? clean(box.innerText) : '';
|
||||
if (snippet.startsWith(title)) snippet = snippet.slice(title.length).trim();
|
||||
seen.add(url);
|
||||
out.push({ url, title: title.slice(0, 200), ...(snippet ? { snippet: snippet.slice(0, 400) } : {}) });
|
||||
if (out.length >= 20) break;
|
||||
}
|
||||
return { sources: out, page: { url: location.href, title: clean(document.title) } };
|
||||
return { sources: out, page: { url: location.href, title: clean(document.title) } };
|
||||
};
|
||||
// Engines serving datacenter exits hand back a redirect shell first
|
||||
// (Bing: &rdr=1&rdrig=…) and hydrate organics after readyState — poll
|
||||
// in-page until real results exist (max ~6s) instead of parsing the shell.
|
||||
for (let i = 0; i < 12; i++) {
|
||||
const r = parse();
|
||||
if (r.sources.length || i >= 11) return r;
|
||||
await new Promise((res) => setTimeout(res, 500));
|
||||
}
|
||||
})()`;
|
||||
|
||||
const edgeFetchProvider = {
|
||||
@@ -1409,7 +1425,7 @@ const edgeSearchProvider = {
|
||||
async search(request, signal) {
|
||||
const n = Math.min(Math.max(request.maxResults ?? 10, 1), 20);
|
||||
const q = encodeURIComponent(request.query);
|
||||
const engine = cfgVal('searchEngine', 'google') === 'bing' ? 'bing' : 'google';
|
||||
const engine = cfgVal('searchEngine', 'bing') === 'google' ? 'google' : 'bing';
|
||||
const build = (e) => e === 'bing'
|
||||
? `https://www.bing.com/search?q=${q}&count=${Math.min(n * 2, 30)}`
|
||||
: `https://www.google.com/search?q=${q}&num=${Math.min(n * 2, 20)}`;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@local/edge-kit-easy",
|
||||
"version": "3.6.4",
|
||||
"version": "3.6.8",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"description": "Edge Kit Browser — human-style browsing for agents in Edge, Chrome, or Firefox: see, click, type, video understanding, gameplay; live-attach-first over CDP/BiDi with a native settings page and the native web seam",
|
||||
|
||||
Reference in New Issue
Block a user