// Name: Chrome Tab Link Harvester // Description: Executes JS in the active Google Chrome tab to collect all link hrefs and displays them in an editor. // Author: tayiorbeii // GitHub: tayiorbeii import "@johnlindquist/kit" const activeUrl = await getActiveTab('Google Chrome').catch(() => '') const js = `JSON.stringify(Array.from(document.querySelectorAll('a')).map(a => a.href).filter(Boolean))` const escapeForAppleScript = (s: string) => s.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n') const as = ` tell application "Google Chrome" if not (exists front window) then return "" set t to active tab of front window execute t javascript "${escapeForAppleScript(js)}" end tell ` let result = '' try { result = await applescript(as) } catch (e) { await notify('Failed to execute script in Google Chrome') exit() } let hrefs: string[] = [] try { hrefs = JSON.parse(result || '[]') } catch { hrefs = (result || '').split(/\r?\n/).filter(Boolean) } hrefs = Array.from(new Set(hrefs)).filter(Boolean) const header = activeUrl ? `# Links from ${activeUrl}\n\n` : `# Links from active Google Chrome tab\n\n` await editor(header + hrefs.join('\n'))