@cloro-dev/response-parser 0.4.5 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -109,12 +109,12 @@ Parse an AI response with auto-detected provider.
109
109
  **Options:**
110
110
 
111
111
  - `removeLinks`: `boolean` - Remove all hyperlinks from HTML (default: `false`)
112
- - `removeHeader`: `boolean` - Remove navigation bar/header (default: `false`, Perplexity, Gemini, Copilot, AI Overview & AI Mode)
113
- - `removeFooter`: `boolean` - Remove follow-up input box/footer (default: `false`, ChatGPT, Perplexity, Gemini, Copilot, AI Overview & AI Mode)
112
+ - `removeHeader`: `boolean` - Remove navigation bar/header (default: `false`; `true` for AI Overview & AI Mode. ChatGPT, Perplexity, Gemini, Copilot, Grok, AI Overview & AI Mode)
113
+ - `removeFooter`: `boolean` - Remove follow-up input box/footer (default: `false`; `true` for AI Overview & AI Mode. ChatGPT, Perplexity, Gemini, Copilot, Grok, AI Overview & AI Mode)
114
114
  - `removeSidebar`: `boolean` - Remove sidebar (default: `false`, ChatGPT, Gemini, Perplexity, Copilot & AI Mode)
115
- - `removeSources`: `boolean` - Remove sources/references panel (default: `false`, Gemini, Perplexity, Copilot & Grok)
115
+ - `removeSources`: `boolean` - Remove sources/references panel (default: `false`, ChatGPT, Gemini, Perplexity, Copilot & Grok)
116
116
 
117
- > **Note:** Cookie/privacy banners are automatically removed for ChatGPT, AI Mode, Copilot, Grok, and Perplexity — no option needed.
117
+ > **Note:** Cookie/privacy banners are automatically removed for ChatGPT, AI Mode, Copilot, Grok, and Perplexity — no option needed. Sign-in prompts are automatically removed for Gemini and Perplexity.
118
118
 
119
119
  **Returns:** `ParsedResponse | null`
120
120
 
@@ -236,6 +236,23 @@ The core parsing logic is identical - you just need to handle the HTML rendering
236
236
 
237
237
  ## What's Changed
238
238
 
239
+ ### v0.5.1
240
+
241
+ - ✅ **Fixed** ChatGPT `removeSources` now hides the open sources dialog of the mobile page
242
+
243
+ ### v0.5.0
244
+
245
+ - ✅ **Fixed** `require("@cloro-dev/response-parser")` failed with `exports is not defined`. The CommonJS build is now `dist/index.cjs`
246
+ - ✅ **Fixed** Perplexity `removeSources` now hides the open "Sources" popover
247
+ - ✅ **Fixed** Perplexity cookie banner (new markup) and sign-in prompts are now always hidden
248
+ - ✅ **Fixed** Copilot `removeHeader` and `removeSidebar` no longer break the page layout. `removeSidebar` no longer hides the references panel
249
+ - ✅ **Fixed** Copilot `removeHeader` now hides the date divider
250
+ - ✅ **Fixed** ChatGPT `removeSources` now hides the sources flyout and the sources sheet on all pages
251
+ - ✅ **Fixed** ChatGPT `removeFooter` and `removeSidebar` no longer change the page structure
252
+ - ✅ **Fixed** Gemini sign-in prompt is now always hidden
253
+ - ✅ **Fixed** AI Overview `removeFooter` now hides the Google footer
254
+ - ✅ **Fixed** Provider detection no longer depends on pattern order for Gemini pages, and no longer reports a Google result page that links to Gemini as Gemini
255
+
239
256
  ### v0.4.3
240
257
 
241
258
  - ✅ **Added** Perplexity `removeSidebar` support (left navigation removal)
@@ -306,9 +323,6 @@ pnpm install
306
323
  # Build
307
324
  pnpm build
308
325
 
309
- # Test
310
- pnpm test
311
-
312
326
  # Development mode
313
327
  pnpm dev
314
328
 
@@ -319,6 +333,40 @@ pnpm type-check
319
333
  pnpm lint
320
334
  ```
321
335
 
336
+ ## Release
337
+
338
+ 1. Log in to npm with an account that can publish to `@cloro-dev`:
339
+
340
+ ```bash
341
+ npm login
342
+ ```
343
+
344
+ 2. Run the checks and the build:
345
+
346
+ ```bash
347
+ pnpm type-check && pnpm lint && pnpm build
348
+ ```
349
+
350
+ 3. Increase the version. This changes `package.json` and creates a git commit and tag:
351
+
352
+ ```bash
353
+ npm version patch # 0.4.5 → 0.4.6
354
+ npm version minor # 0.4.5 → 0.5.0
355
+ npm version major # 0.4.5 → 1.0.0
356
+ ```
357
+
358
+ 4. Publish. `prepublishOnly` builds the package again before the upload:
359
+
360
+ ```bash
361
+ npm publish
362
+ ```
363
+
364
+ 5. Push the commit and the tag, and add an entry under "What's Changed":
365
+
366
+ ```bash
367
+ git push --follow-tags
368
+ ```
369
+
322
370
  ## License
323
371
 
324
372
  MIT © cloro
@@ -1 +1 @@
1
- {"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../../src/core/detector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEvD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAkFvC;IAEF;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,GAAG,gBAAgB,GAAG,IAAI;IA4CrD;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,GAAG,GAAG,gBAAgB,EAAE;IA2BzD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO;CAI9D"}
1
+ {"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../../src/core/detector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAEvD,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAoFvC;IAEF;;OAEG;IACH,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,GAAG,GAAG,gBAAgB,GAAG,IAAI;IA4CrD;;OAEG;IACH,MAAM,CAAC,eAAe,CAAC,QAAQ,EAAE,GAAG,GAAG,gBAAgB,EAAE;IA2BzD;;OAEG;IACH,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,UAAU,GAAG,OAAO;CAI9D"}
package/dist/index.cjs ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";function e(e){let t="",r="",o=e;return e.result&&(o=e.result),"string"==typeof o?o.trim().startsWith("<")&&o.includes(">")?t=o:r=o:"object"==typeof o&&null!==o&&(o.html?t=o.html:o.content?o.content.trim().startsWith("<")?t=o.content:r=o.content:o.text&&(r=o.text)),{html:t,text:r}}class t{static detect(e){const t={CHATGPT:0,GEMINI:0,PERPLEXITY:0,COPILOT:0,AIOVERVIEW:0,AIMODE:0,GROK:0};for(const[r,o]of Object.entries(this.PROVIDER_PATTERNS))for(const n of o)try{n(e)&&t[r]++}catch(e){}let r=0,o=null;for(const[e,n]of Object.entries(t))n>r&&(r=n,o=e);return 0===r?null:{provider:o,confidence:r/Object.values(t).reduce((e,t)=>Math.max(e,t),1)}}static getAllProviders(e){const t=[];for(const[r,o]of Object.entries(this.PROVIDER_PATTERNS)){let n=0;for(const t of o)try{t(e)&&n++}catch(e){}n>0&&t.push({provider:r,confidence:n/o.length})}return t.sort((e,t)=>t.confidence-e.confidence)}static validate(e,t){const r=this.detect(e);return(null==r?void 0:r.provider)===t&&r.confidence>.5}}t.PROVIDER_PATTERNS={CHATGPT:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("bg-token-bg-primary")||r.includes("text-token-text-secondary")},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("chatgpt.com")||r.includes("openai.com")}],GEMINI:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("bard-sidenav")||r.includes("mat-sidenav")},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("<chat-app")||r.includes("gem-sys-color")}],PERPLEXITY:[e=>{var t;return((null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"").includes("perplexity.ai")},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("prose")&&!r.includes("grok.com")&&!r.includes("chatgpt.com")}],COPILOT:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("copilot.microsoft.com")||r.includes('data-testid="sidebar-container"')}],AIOVERVIEW:[e=>{var t,r,o;return!!(null===(r=null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.aioverview)||void 0===r?void 0:r.text)||!!(null===(o=null==e?void 0:e.aioverview)||void 0===o?void 0:o.text)},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes('id="gsr"')&&!r.includes("aim-mars")&&!r.includes("ho072b")}],AIMODE:[e=>{var t;return((null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"").includes("aim-mars")},e=>{var t;return((null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"").includes("ho072b")}],GROK:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("grok.com")||r.includes("x.ai")},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("cdn.grok.com")||r.includes("vaul-drawer")}]};class r{extractContentCommon(t,r=!1){var o;const n=e(t);if(r){let e=[];const r=t.result||t;return"object"==typeof r&&null!==r&&((null===(o=r.aioverview)||void 0===o?void 0:o.sources)?e=r.aioverview.sources:r.sources&&(e=r.sources)),{...n,sources:e}}return n}injectStyles(e,t){let r=e;(null==t?void 0:t.baseUrl)&&!e.includes("<base ")&&(r=r.includes("<head>")?r.replace("<head>",`<head><base href="${t.baseUrl}">`):r.replace(/(<html[^>]*>)/i,`$1<head><base href="${t.baseUrl}"></head>`));const o=(null==t?void 0:t.customCSS)||"";return o&&r.includes("<head>")?r=r.replace("<head>",`<head><style>${o}</style>`):o&&(r=r.replace(/(<html[^>]*>)/i,`$1<head><style>${o}</style></head>`)),r}sanitizeHtml(e){let t=e.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gim,"");return t=t.replace(/<noscript[\s\S]*?<\/noscript>/gi,""),t}isFullDocument(e){return/^\s*(<html|<!DOCTYPE)/i.test(e)}removeLinks(e){return e.replace(/<a\b[^>]*>([\s\S]*?)<\/a>/gim,"$1")}wrapFragment(e){return`<!DOCTYPE html>\n<html>\n<head>\n <meta charset="utf-8">\n <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'none'; style-src 'unsafe-inline';">\n <style>\n body {\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, sans-serif;\n white-space: pre-wrap;\n word-wrap: break-word;\n }\n img { max-width: 100%; height: auto; }\n body {\n pointer-events: none;\n user-select: none;\n }\n </style>\n</head>\n<body>\n ${e}\n</body>\n</html>`}}class o extends r{constructor(){super(...arguments),this.name="CHATGPT",this.baseUrl="https://chatgpt.com"}extractContent(e){return this.extractContentCommon(e)}removeLinks(e){return e.replace(/<a\b([^>]*)>/gi,(e,t)=>{const r=t.replace(/\s+href\s*=\s*["'][^"']*["']/gi,"").replace(/\s+alt\s*=\s*["'][^"']*["']/gi,"").replace(/\s+rel\s*=\s*["'][^"']*["']/gi,"").replace(/\s+target\s*=\s*["'][^"']*["']/gi,"").trim();return`<span${r?" "+r:""}>`}).replace(/<\/a>/gi,"</span>")}removeHeader(e){let t=e;return t=t.replace(/<header[^>]*id="page-header"[^>]*>.*?<\/header>/gis,""),t}removeSidebar(e){return e.replace(/<nav[^>]*>.*?<\/nav>/gis,"")}removeFooter(e){return e}removeCookieBanner(e){return e.replace(/<div[^>]*role="dialog"[^>]*>[\s\S]*?openai\.com\/policies\/cookie-policy[\s\S]*?<\/div><\/div><\/div><\/div><\/div><\/div>/gi,"")}removeSources(e){return e}parse(e,t){var r;const{html:o,text:n}=this.extractContent(e);if(!o)throw new Error("No HTML content found in ChatGPT response");let i=o;const s=null!==(r=null==t?void 0:t.removeFooter)&&void 0!==r&&r;i=this.sanitizeHtml(i),i=this.removeCookieBanner(i),(null==t?void 0:t.removeHeader)&&(i=this.removeHeader(i)),(null==t?void 0:t.removeSidebar)&&(i=this.removeSidebar(i)),s&&(i=this.removeFooter(i)),(null==t?void 0:t.removeSources)&&(i=this.removeSources(i)),(null==t?void 0:t.removeLinks)&&(i=this.removeLinks(i));let l="";return(null==t?void 0:t.removeSidebar)&&(l+="\n #stage-slideover-sidebar { display: none !important; }\n [data-sidebar-item] { display: none !important; }\n [data-skip-to-content] { display: none !important; }\n .h-svh { height: auto !important; }\n "),s&&(l+='\n #thread-bottom-container { display: none !important; }\n form[data-type="unified-composer"] { display: none !important; }\n #thread { min-height: auto !important; }\n '),(null==t?void 0:t.removeSources)&&(l+='\n /* Side flyout, the modal sheet that replaces it on narrow pages, and\n the sources dialog of the mobile page */\n [data-testid="stage-thread-flyout"],\n [data-sheet-travel-state],\n #assistant-sources-dialog {\n display: none !important;\n }\n '),i=this.injectStyles(i,{baseUrl:this.baseUrl,customCSS:l}),{provider:this.name,html:i,text:n,metadata:{isFullDocument:this.isFullDocument(i),cookieBannerRemoved:!0,headerRemoved:(null==t?void 0:t.removeHeader)||!1,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,footerRemoved:s,sourcesRemoved:(null==t?void 0:t.removeSources)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class n extends r{constructor(){super(...arguments),this.name="GEMINI",this.baseUrl="https://gemini.google.com"}extractContent(e){return this.extractContentCommon(e,!0)}removeHeader(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*boqOnegoogleliteOgbOneGoogleBar[^"]*"[^>]*>.*?<\/div><\/div><\/div><\/div>/gis,""),t=t.replace(/<top-bar-actions[^>]*>.*?<\/top-bar-actions>/gis,""),t=t.replace(/<div[^>]*class="[^"]*desktop-ogb-buffer[^"]*"[^>]*><\/div>/gis,""),t}removeFooter(e){return e.replace(/<input-container[^>]*>.*?<\/input-container>/gis,"")}removeSidebar(e){return e.replace(/<bard-sidenav[^>]*>.*?<\/bard-sidenav>/gis,"")}removeSources(e){let t=e;return t=t.replace(/<context-sidebar[^>]*>[\s\S]*?<\/context-sidebar>/gi,""),t=t.replace(/<sources-sidebar-button[^>]*>[\s\S]*?<\/sources-sidebar-button>/gi,""),t}parse(e,t){var r,o;const{html:n,text:i,sources:s}=this.extractContent(e);if(!n)throw new Error("No HTML content found in Gemini response");let l=n;const a=null!==(r=null==t?void 0:t.removeHeader)&&void 0!==r&&r,d=null!==(o=null==t?void 0:t.removeFooter)&&void 0!==o&&o;l=this.sanitizeHtml(l),a&&(l=this.removeHeader(l)),d&&(l=this.removeFooter(l)),(null==t?void 0:t.removeSidebar)&&(l=this.removeSidebar(l)),(null==t?void 0:t.removeSources)&&(l=this.removeSources(l)),(null==t?void 0:t.removeLinks)&&(l=this.removeLinks(l));let v="\n sign-in-nudge { display: none !important; }\n ";return a&&(v+="\n .side-nav-menu-button { display: none !important; }\n "),l=this.injectStyles(l,{baseUrl:this.baseUrl,customCSS:v}),{provider:this.name,html:l,text:i,sources:s,metadata:{isFullDocument:this.isFullDocument(l),headerRemoved:a,footerRemoved:d,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,sourcesRemoved:(null==t?void 0:t.removeSources)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class i extends r{constructor(){super(...arguments),this.name="PERPLEXITY",this.baseUrl="https://www.perplexity.ai"}extractContent(e){return this.extractContentCommon(e)}removeHeader(e){return e.replace(/<div[^>]*class="[^"]*@container\/header[^"]*"[^>]*>.*?<div[^>]*class="[^"]*absolute bottom-0 inset-x-0 border-b[^"]*"[^>]*><\/div>/gis,"")}removeFooter(e){return e}removeSidebar(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*w-sideBarWidth[^"]*"[^>]*>[\s\S]*?<\/nav>[\s\S]*?<\/div>/gi,""),t}removeSources(e){return e}parse(e,t){var r,o;const{html:n,text:i}=this.extractContent(e);if(!n)throw new Error("No HTML content found in Perplexity response");let s=n;const l=null!==(r=null==t?void 0:t.removeHeader)&&void 0!==r&&r,a=null!==(o=null==t?void 0:t.removeFooter)&&void 0!==o&&o;s=this.sanitizeHtml(s),s=s.replace(/style="transition: none; overflow: hidden; height: 48px;"/gi,""),s=s.replace(/padding-right:\s*\d+px/gi,"padding-right: 0px"),l&&(s=this.removeHeader(s)),(null==t?void 0:t.removeSidebar)&&(s=this.removeSidebar(s)),a&&(s=this.removeFooter(s)),(null==t?void 0:t.removeSources)&&(s=this.removeSources(s)),(null==t?void 0:t.removeLinks)&&(s=this.removeLinks(s));let d='\n #cookie-consent,\n [role="dialog"]:has(#cookie-consent),\n div[role="dialog"][class*="fixed"][class*="bottom-2"] {\n display: none !important;\n }\n /* Login prompts: the full-page modal and the corner card. The #root\n prefix keeps the rule above the removeSidebar layout overrides. */\n [data-type="portal"]:has([data-testid="login-modal"]),\n #root div[class*="fixed"]:has([data-testid="login-modal"]),\n div[class*="fixed"]:has([data-testid="login-modal"]) {\n display: none !important;\n }\n [data-radix-focus-guard] {\n display: none !important;\n }\n ';return(null==t?void 0:t.removeSidebar)&&(d+='\n [class*="w-sideBarWidth"] { display: none !important; }\n #root, #root > div, #root > div > div {\n display: block !important;\n height: auto !important;\n max-height: none !important;\n width: 100% !important;\n padding: 0 !important;\n }\n main {\n display: block !important;\n height: auto !important;\n max-height: none !important;\n overflow: visible !important;\n }\n main > div {\n height: auto !important;\n overflow: visible !important;\n }\n [class*="scrollable-container"] {\n height: auto !important;\n overflow: visible !important;\n }\n [class*="max-w-threadContentWidth"] {\n max-width: 100% !important;\n }\n '),(null==t?void 0:t.removeSources)&&(d+='\n div[class*="fixed"][class*="inset-y-0"][class*="right-0"],\n [data-radix-popper-content-wrapper] {\n display: none !important;\n }\n '),a&&(d+='\n [class*="bottom-safeAreaInsetBottom"] {\n display: none !important;\n }\n '),s=this.injectStyles(s,{baseUrl:this.baseUrl,customCSS:d}),{provider:this.name,html:s,text:i,metadata:{isFullDocument:this.isFullDocument(s),linksRemoved:(null==t?void 0:t.removeLinks)||!1,headerRemoved:l,footerRemoved:a,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,cookieBannerRemoved:!0,sourcesRemoved:(null==t?void 0:t.removeSources)||!1}}}}class s extends r{constructor(){super(...arguments),this.name="COPILOT",this.baseUrl="https://copilot.microsoft.com"}extractContent(e){return this.extractContentCommon(e)}removeHeader(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*absolute flex end-6 origin-top-right flex-col items-end[^"]*"[^>]*data-testid="settings-wrapper"[^>]*>.*?<\/div><\/div>/gis,""),t}removeFooter(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*absolute bottom-0 w-full[^"]*"[^>]*>.*?<\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*mt-\[var\(--composer-container-height\)\][^"]*"[^>]*><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*pointer-events-none absolute flex justify-center z-20 inset-x-0 bottom-\[calc\(var\(--composer-container-height\)\+1rem\)\][^"]*"[^>]*>.*?<button[^>]*data-testid="scroll-to-bottom-button"[^>]*>.*?<\/button><\/div>/gis,""),t}removeCookieBanner(e){let t=e;return t=t.replace(/<div[^>]*id="cookie-banner"[^>]*>.*?<\/div>.*?<\/div>.*?<\/div>.*?<\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*max-w-cookie-banner[^"]*"[^>]*>.*?<\/div>.*?<\/div>.*?<\/div>.*?<\/div>/gis,""),t}removeSources(e){return e.replace(/<div[^>]*class="[^"]*relative h-full overflow-hidden will-change-auto[^"]*"[^>]*style="[^"]*width:\s*\d+px[^"]*"[^>]*>[\s\S]*?(?=<div[^>]*class="[^"]*pointer-events-none (?:fixed|absolute)[^"]*")/gi,"")}removeSidebar(e){return e}parse(e,t){var r,o;const{html:n,text:i}=this.extractContent(e);if(!n)throw new Error("No HTML content found in Copilot response");let s=n;const l=null!==(r=null==t?void 0:t.removeHeader)&&void 0!==r&&r,a=null!==(o=null==t?void 0:t.removeFooter)&&void 0!==o&&o;s=this.sanitizeHtml(s),s=this.removeCookieBanner(s),l&&(s=this.removeHeader(s)),a&&(s=this.removeFooter(s)),(null==t?void 0:t.removeSidebar)&&(s=this.removeSidebar(s)),(null==t?void 0:t.removeSources)&&(s=this.removeSources(s)),(null==t?void 0:t.removeLinks)&&(s=this.removeLinks(s));let d="";return l&&(d+='\n [data-testid="sticky-header"],\n [data-testid="backstage-chats"],\n div:has(> div > [data-testid="date-divider"]) {\n display: none !important;\n }\n '),(null==t?void 0:t.removeSidebar)&&(d+="\n div:has(> #sidebar-container) { display: none !important; }\n "),s=this.injectStyles(s,{baseUrl:this.baseUrl,customCSS:d}),{provider:this.name,html:s,text:i,metadata:{isFullDocument:this.isFullDocument(s),cookieBannerRemoved:!0,headerRemoved:l,footerRemoved:a,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,sourcesRemoved:(null==t?void 0:t.removeSources)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class l extends r{constructor(){super(...arguments),this.name="AIOVERVIEW",this.baseUrl="https://www.google.com"}extractContent(e){return this.extractContentCommon(e,!0)}removeHeader(e){return e}removeFooter(e){return e}removeSidebar(e){return e}parse(e,t){var r,o;const{html:n,sources:i}=this.extractContent(e);if(!n)throw new Error("No HTML content found in AI Overview response");let s=n;const l=null===(r=null==t?void 0:t.removeHeader)||void 0===r||r,a=null===(o=null==t?void 0:t.removeFooter)||void 0===o||o;s=this.sanitizeHtml(s),l&&(s=this.removeHeader(s)),a&&(s=this.removeFooter(s)),(null==t?void 0:t.removeSidebar)&&(s=this.removeSidebar(s)),(null==t?void 0:t.removeLinks)&&(s=this.removeLinks(s));let d="";return l&&(d+='\n /* Header hiding */\n header, #header, #searchform, .sfbg, #appbar,\n div[role="navigation"], #leftnav, #sidetogether,\n [role="banner"], .Fgvgjc, #hdtb, .hdtb-msb,\n .DZ13He, .wYq63b, .eT9Cje, .bNg8Rb, .S6VXfe, .Lu57id {\n display: none !important;\n }\n '),(null==t?void 0:t.removeSidebar)&&(d+="\n /* Sidebar hiding */\n #leftnav, #sidetogether {\n display: none !important;\n }\n "),a&&(d+='\n /* Footer hiding */\n footer, #footer, #sfooter, .fbar,\n .pdp-nav, [aria-label="Main menu"], .gb_Td, .gb_L {\n display: none !important;\n }\n '),s=this.injectStyles(s,{baseUrl:this.baseUrl,customCSS:d}),{provider:this.name,html:s,sources:i,metadata:{isFullDocument:this.isFullDocument(s),headerRemoved:l,footerRemoved:a,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class a extends r{constructor(){super(...arguments),this.name="AIMODE",this.baseUrl="https://www.google.com"}extractContent(e){return this.extractContentCommon(e)}removeHeader(e){let t=e;return t=t.replace(/<div[^>]*jsname="oEQ3x"[^>]*class="[^"]*DZ13He[^"]*"[^>]*>.*?<hr class="e9c7U">.*?<\/div><\/div><\/div><\/div><\/div>/gis,""),t}removeFooter(e){let t=e;return t=t.replace(/<div[^>]*data-xid="aim-mars-input-plate"[^>]*>[\s\S]*?<\/div><\/div><\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*jscontroller="P5gZDb"[^>]*>[\s\S]*?<\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*t0ITR hh3ttd[^"]*"[^>]*>[\s\S]*?<\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*y4VEUd vve6Ce[^"]*"[^>]*>[\s\S]*?<\/div><\/div>/gis,""),t}removeSidebar(e){let t=e;return t=t.replace(/<div[^>]*aria-label="AI Mode history"[^>]*class="[^"]*ho072b[^"]*"[^>]*>[\s\S]*?(?=<!--TgQPHd)/gi,""),t=t.replace(/<div[^>]*class="[^"]*ho072b[^"]*"[^>]*aria-label="AI Mode history"[^>]*>[\s\S]*?(?=<!--TgQPHd)/gi,""),t=t.replace(/<div[^>]*class="[^"]*OEwhSe[^"]*"[^>]*>[\s\S]*?<\/div><\/div>/gis,""),t=t.replace(/<button[^>]*aria-label="AI Mode history"[^>]*>[\s\S]*?<\/button>/gis,""),t}parse(e,t){var r,o;const{html:n,text:i}=this.extractContent(e);if(!n)throw new Error("No HTML content found in AI Mode response");let s=n;const l=null===(r=null==t?void 0:t.removeHeader)||void 0===r||r,a=null===(o=null==t?void 0:t.removeFooter)||void 0===o||o;s=this.sanitizeHtml(s),l&&(s=this.removeHeader(s)),a&&(s=this.removeFooter(s)),(null==t?void 0:t.removeSidebar)&&(s=this.removeSidebar(s)),(null==t?void 0:t.removeLinks)&&(s=this.removeLinks(s));let d="";return d+="\n .KxvlWc, #CXQnmb {\n display: none !important;\n }\n ",l&&(d+='\n /* Header hiding */\n header, #header, #searchform, .sfbg, #appbar,\n div[role="navigation"], #leftnav, #sidetogether,\n [role="banner"], .Fgvgjc, #hdtb, .hdtb-msb,\n .DZ13He, .wYq63b, .eT9Cje, .bNg8Rb, .S6VXfe, .Lu57id,\n .YHsVn, .UTNPFf {\n display: none !important;\n }\n '),a&&(d+='\n /* Footer hiding */\n footer, #footer, .fbar,\n .pdp-nav, [aria-label="Main menu"], .gb_Td, .gb_L {\n display: none !important;\n }\n /* Hide the "Ask anything" input bar */\n [data-xid="aim-mars-input-plate"],\n .UAbVe, .y4VEUd, .t0ITR.hh3ttd {\n display: none !important;\n }\n '),(null==t?void 0:t.removeSidebar)&&(d+="\n /* Hide AI Mode history panel */\n .ho072b, .OEwhSe, .qEn1od {\n display: none !important;\n }\n "),s=this.injectStyles(s,{baseUrl:this.baseUrl,customCSS:d}),{provider:this.name,html:s,text:i,metadata:{isFullDocument:this.isFullDocument(s),headerRemoved:l,footerRemoved:a,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class d extends r{constructor(){super(...arguments),this.name="GROK",this.baseUrl="https://grok.com"}extractContent(e){return this.extractContentCommon(e)}removeHeader(e){return e}removeFooter(e){return e}parse(e,t){const{html:r,text:o}=this.extractContent(e);if(!r)throw new Error("No HTML content found in Grok response");let n=r;n=this.sanitizeHtml(n);let i="";return i+='\n [data-cookie-banner],\n [data-cookie-banner="true"] {\n display: none !important;\n }\n ',i+='\n [data-sonner-toaster],\n [data-sonner-toast],\n [class*="sonner-toast"] {\n display: none !important;\n }\n ',(null==t?void 0:t.removeSources)&&(n=n.replace(/<div[^>]*class="[^"]*h-dvh[^"]*flex-shrink-0[^"]*max-w-[^"]*"[^>]*>[\s\S]*?<\/aside>[\s\S]*?(?=<section)/gi,""),i+='\n div[data-state] > div.flex.flex-row.gap-1.items-center.rounded-full.cursor-pointer {\n display: none !important;\n }\n [vaul-drawer][vaul-drawer-direction="right"],\n [vaul-overlay] {\n display: none !important;\n }\n '),(null==t?void 0:t.removeHeader)&&(i+='\n /* Header hiding - hide elements with Grok\'s header class pattern */\n div[class*="h-16"][class*="top-0"][class*="z-10"],\n div[class*="absolute"][class*="inset-x-0"][class*="top-0"] {\n display: none !important;\n }\n '),(null==t?void 0:t.removeFooter)&&(i+='\n /* Footer hiding - hide Grok\'s footer/input area */\n div[class*="absolute"][class*="inset-x-0"][class*="bottom-0"][class*="max-w-breakout"],\n div[class*="absolute"][class*="bottom-0"][class*="w-full"] {\n display: none !important;\n }\n '),(null==t?void 0:t.removeLinks)&&(n=this.removeLinks(n)),n=this.injectStyles(n,{baseUrl:this.baseUrl,customCSS:i}),{provider:this.name,html:n,text:o,metadata:{isFullDocument:this.isFullDocument(n),linksRemoved:(null==t?void 0:t.removeLinks)||!1,headerRemoved:(null==t?void 0:t.removeHeader)||!1,footerRemoved:(null==t?void 0:t.removeFooter)||!1,cookieBannerRemoved:!0,sourcesRemoved:(null==t?void 0:t.removeSources)||!1}}}}class v{constructor(){this.providers=new Map,this.providers.set("CHATGPT",new o),this.providers.set("GEMINI",new n),this.providers.set("PERPLEXITY",new i),this.providers.set("COPILOT",new s),this.providers.set("AIOVERVIEW",new l),this.providers.set("AIMODE",new a),this.providers.set("GROK",new d)}parse(e,r){const o=t.detect(e);if(!o)return this.parseGeneric(e);const n=this.providers.get(o.provider);if(!n)return null;try{const t=n.parse(e,r);return{...t,metadata:{...t.metadata,detectionConfidence:o.confidence}}}catch(e){return console.error(`Failed to parse response with ${o.provider}:`,e),null}}parseWithProvider(e,t,r){const o=this.providers.get(t);if(!o)throw new Error(`Unknown provider: ${t}`);try{return o.parse(e,r)}catch(e){return console.error(`Failed to parse response with ${t}:`,e),null}}detectProvider(e){const r=t.detect(e);return(null==r?void 0:r.provider)||null}detectAllProviders(e){return t.getAllProviders(e)}parseGeneric(t){const{html:r,text:o}=e(t);if(!r&&!o)return null;let n=r;return n&&(n=n.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gim,""),n=n.replace(/<noscript[\s\S]*?<\/noscript>/gi,"")),{provider:"CHATGPT",html:n||"",text:o||"",metadata:{isGeneric:!0}}}getSupportedProviders(){return Array.from(this.providers.keys())}registerProvider(e,t){this.providers.set(e,t)}}const c=new v;exports.AIModeProvider=a,exports.AIOverviewProvider=l,exports.AIResponseParser=v,exports.BaseProvider=r,exports.ChatGPTProvider=o,exports.CopilotProvider=s,exports.GeminiProvider=n,exports.GrokProvider=d,exports.PerplexityProvider=i,exports.ProviderDetector=t,exports.detectProvider=e=>c.detectProvider(e),exports.parseAiResponse=(e,t)=>c.parse(e,t),exports.parser=c;
2
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/core/types.ts","../src/core/detector.ts","../src/providers/base-provider.ts","../src/providers/chatgpt.ts","../src/providers/gemini.ts","../src/providers/perplexity.ts","../src/providers/copilot.ts","../src/providers/ai-overview.ts","../src/providers/ai-mode.ts","../src/providers/grok.ts","../src/core/parser.ts"],"sourcesContent":["export type AIProvider =\n | 'CHATGPT'\n | 'GEMINI'\n | 'PERPLEXITY'\n | 'COPILOT'\n | 'AIOVERVIEW'\n | 'AIMODE'\n | 'GROK';\n\nexport interface ParsedResponse {\n provider: AIProvider;\n html: string;\n text?: string;\n sources?: any[];\n metadata?: Record<string, any>;\n}\n\nexport interface ParseOptions {\n removeLinks?: boolean;\n removeHeader?: boolean;\n removeFooter?: boolean;\n removeSidebar?: boolean;\n removeSources?: boolean;\n}\n\nexport interface ProviderConfig {\n name: AIProvider;\n baseUrl: string;\n}\n\nexport interface DetectedProvider {\n provider: AIProvider;\n confidence: number;\n}\n\nexport interface StyleOptions {\n customCSS?: string;\n hideUI?: boolean;\n baseUrl?: string;\n}\n\nexport type ContentExtraction = {\n html?: string;\n text?: string;\n sources?: any[];\n};\n\n/**\n * Standardized metadata for provider responses\n */\nexport interface ProviderMetadata {\n isFullDocument?: boolean;\n headerRemoved?: boolean;\n footerRemoved?: boolean;\n sidebarRemoved?: boolean;\n linksRemoved?: boolean;\n cookieBannerRemoved?: boolean;\n sourcesRemoved?: boolean;\n detectionConfidence?: number;\n}\n\n/**\n * Common content extraction utility - shared across providers and parser\n */\nexport function extractContentCommon(response: any): ContentExtraction {\n let html = '';\n let text = '';\n\n // Handle nested structure\n let dataToCheck = response;\n if (response.result) {\n dataToCheck = response.result;\n }\n\n // Extract content\n if (typeof dataToCheck === 'string') {\n if (dataToCheck.trim().startsWith('<') && dataToCheck.includes('>')) {\n html = dataToCheck;\n } else {\n text = dataToCheck;\n }\n } else if (typeof dataToCheck === 'object' && dataToCheck !== null) {\n if (dataToCheck.html) {\n html = dataToCheck.html;\n } else if (dataToCheck.content) {\n if (dataToCheck.content.trim().startsWith('<')) {\n html = dataToCheck.content;\n } else {\n text = dataToCheck.content;\n }\n } else if (dataToCheck.text) {\n text = dataToCheck.text;\n }\n }\n\n return { html, text };\n}","import { AIProvider, DetectedProvider } from './types';\n\nexport class ProviderDetector {\n private static readonly PROVIDER_PATTERNS = {\n CHATGPT: [\n // Check for token-based CSS classes\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('bg-token-bg-primary') || html.includes('text-token-text-secondary');\n },\n // Check for OpenAI-specific patterns\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('chatgpt.com') || html.includes('openai.com');\n },\n ],\n GEMINI: [\n // Check for Material Design components\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('bard-sidenav') || html.includes('mat-sidenav');\n },\n // Check for Gemini-specific markup. The domain name alone also occurs in\n // Google result pages that link to Gemini.\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('<chat-app') || html.includes('gem-sys-color');\n },\n ],\n PERPLEXITY: [\n // Check for Perplexity domain\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('perplexity.ai');\n },\n // Check for Perplexity-specific structure\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('prose') && !html.includes('grok.com') && !html.includes('chatgpt.com');\n },\n ],\n COPILOT: [\n // Check for Copilot-specific elements\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('copilot.microsoft.com') || html.includes('data-testid=\"sidebar-container\"');\n },\n ],\n AIOVERVIEW: [\n // Check for AI Overview specific structure\n (response: any) => {\n if (response?.result?.aioverview?.text) return true;\n if (response?.aioverview?.text) return true;\n return false;\n },\n // Check for a Google result page without AI Mode markers.\n // WIZ_global_data alone also occurs in Gemini pages.\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('id=\"gsr\"') && !html.includes('aim-mars') && !html.includes('ho072b');\n },\n ],\n AIMODE: [\n // Check for the AI Mode input and turn containers. The DZ13He header\n // class also occurs in every Google result page.\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('aim-mars');\n },\n // Check for the AI Mode history panel\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('ho072b');\n },\n ],\n GROK: [\n // Check for Grok domain\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('grok.com') || html.includes('x.ai');\n },\n // Check for Grok CDN or app-specific patterns\n (response: any) => {\n const html = response?.result?.html || response?.html || '';\n return html.includes('cdn.grok.com') || html.includes('vaul-drawer');\n },\n ],\n };\n\n /**\n * Detect the AI provider from the response\n */\n static detect(response: any): DetectedProvider | null {\n const scores: Record<AIProvider, number> = {\n CHATGPT: 0,\n GEMINI: 0,\n PERPLEXITY: 0,\n COPILOT: 0,\n AIOVERVIEW: 0,\n AIMODE: 0,\n GROK: 0,\n };\n\n // Score each provider based on pattern matches\n for (const [provider, patterns] of Object.entries(this.PROVIDER_PATTERNS)) {\n for (const pattern of patterns) {\n try {\n if (pattern(response)) {\n scores[provider as AIProvider]++;\n }\n } catch {\n // Ignore pattern errors\n }\n }\n }\n\n // Find the provider with the highest score\n let maxScore = 0;\n let detectedProvider: AIProvider | null = null;\n\n for (const [provider, score] of Object.entries(scores)) {\n if (score > maxScore) {\n maxScore = score;\n detectedProvider = provider as AIProvider;\n }\n }\n\n // Return null if no patterns matched\n if (maxScore === 0) return null;\n\n return {\n provider: detectedProvider!,\n confidence: maxScore / Object.values(scores).reduce((a, b) => Math.max(a, b), 1),\n };\n }\n\n /**\n * Get all possible providers with their confidence scores\n */\n static getAllProviders(response: any): DetectedProvider[] {\n const providers: DetectedProvider[] = [];\n\n for (const [provider, patterns] of Object.entries(this.PROVIDER_PATTERNS)) {\n let matches = 0;\n for (const pattern of patterns) {\n try {\n if (pattern(response)) {\n matches++;\n }\n } catch {\n // Ignore pattern errors\n }\n }\n\n if (matches > 0) {\n providers.push({\n provider: provider as AIProvider,\n confidence: matches / patterns.length,\n });\n }\n }\n\n // Sort by confidence (highest first)\n return providers.sort((a, b) => b.confidence - a.confidence);\n }\n\n /**\n * Validate if a detected provider is likely correct\n */\n static validate(response: any, provider: AIProvider): boolean {\n const detected = this.detect(response);\n return detected?.provider === provider && detected.confidence > 0.5;\n }\n}","import { AIProvider, ParsedResponse, ParseOptions, StyleOptions, ContentExtraction, extractContentCommon } from '../core/types';\n\nexport abstract class BaseProvider {\n abstract readonly name: AIProvider;\n abstract readonly baseUrl: string;\n\n /**\n * Parse an AI response and return structured content\n */\n abstract parse(response: any, options?: ParseOptions): ParsedResponse;\n\n /**\n * Extract content from the response object\n */\n abstract extractContent(response: any): ContentExtraction;\n\n /**\n * Common content extraction logic - can be used by providers\n */\n protected extractContentCommon(response: any, includeSources = false): ContentExtraction {\n const result = extractContentCommon(response);\n\n if (includeSources) {\n let sources: any[] = [];\n const dataToCheck = response.result || response;\n\n if (typeof dataToCheck === 'object' && dataToCheck !== null) {\n if (dataToCheck.aioverview?.sources) {\n sources = dataToCheck.aioverview.sources;\n } else if (dataToCheck.sources) {\n sources = dataToCheck.sources;\n }\n }\n\n return { ...result, sources };\n }\n\n return result;\n }\n\n /**\n * Inject provider-specific styles into HTML\n */\n injectStyles(html: string, options?: StyleOptions): string {\n let styledHtml = html;\n\n // Inject base URL if not already present\n if (options?.baseUrl && !html.includes('<base ')) {\n if (styledHtml.includes('<head>')) {\n styledHtml = styledHtml.replace(\n '<head>',\n `<head><base href=\"${options.baseUrl}\">`,\n );\n } else {\n styledHtml = styledHtml.replace(\n /(<html[^>]*>)/i,\n `$1<head><base href=\"${options.baseUrl}\"></head>`,\n );\n }\n }\n\n // Inject styles only if customCSS is provided\n const styles = options?.customCSS || '';\n\n if (styles && styledHtml.includes('<head>')) {\n styledHtml = styledHtml.replace('<head>', `<head><style>${styles}</style>`);\n } else if (styles) {\n styledHtml = styledHtml.replace(\n /(<html[^>]*>)/i,\n `$1<head><style>${styles}</style></head>`,\n );\n }\n\n return styledHtml;\n }\n\n /**\n * Sanitize HTML content\n */\n sanitizeHtml(html: string): string {\n // Remove scripts\n let sanitized = html.replace(/<script\\b[^>]*>[\\s\\S]*?<\\/script>/gim, '');\n\n // Remove noscript tags\n sanitized = sanitized.replace(/<noscript[\\s\\S]*?<\\/noscript>/gi, '');\n\n return sanitized;\n }\n\n /**\n * Check if content is a full HTML document\n */\n isFullDocument(html: string): boolean {\n return /^\\s*(<html|<!DOCTYPE)/i.test(html);\n }\n\n /**\n * Remove all links from HTML, keeping the text content\n */\n removeLinks(html: string): string {\n // Replace anchor tags with their text content\n return html.replace(/<a\\b[^>]*>([\\s\\S]*?)<\\/a>/gim, '$1');\n }\n\n /**\n * Wrap HTML fragment in a document\n */\n wrapFragment(html: string): string {\n return `<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"utf-8\">\n <meta http-equiv=\"Content-Security-Policy\" content=\"default-src 'none'; script-src 'none'; style-src 'unsafe-inline';\">\n <style>\n body {\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, sans-serif;\n white-space: pre-wrap;\n word-wrap: break-word;\n }\n img { max-width: 100%; height: auto; }\n body {\n pointer-events: none;\n user-select: none;\n }\n </style>\n</head>\n<body>\n ${html}\n</body>\n</html>`;\n }\n}","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class ChatGPTProvider extends BaseProvider {\n readonly name: AIProvider = \"CHATGPT\";\n readonly baseUrl = \"https://chatgpt.com\";\n\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove links from HTML, preserving badge styling\n * Converts <a> tags to <span> while keeping class attributes\n */\n removeLinks(html: string): string {\n // Replace anchor tags with span tags, keeping all attributes except href/alt/rel/target\n return html\n .replace(/<a\\b([^>]*)>/gi, (match, attributes) => {\n // Remove link-specific attributes but keep others (class, style, etc.)\n const cleanedAttrs = attributes\n .replace(/\\s+href\\s*=\\s*[\"'][^\"']*[\"']/gi, \"\")\n .replace(/\\s+alt\\s*=\\s*[\"'][^\"']*[\"']/gi, \"\")\n .replace(/\\s+rel\\s*=\\s*[\"'][^\"']*[\"']/gi, \"\")\n .replace(/\\s+target\\s*=\\s*[\"'][^\"']*[\"']/gi, \"\")\n .trim();\n return `<span${cleanedAttrs ? \" \" + cleanedAttrs : \"\"}>`;\n })\n .replace(/<\\/a>/gi, \"</span>\");\n }\n\n /**\n * Remove ChatGPT header from HTML\n */\n removeHeader(html: string): string {\n let cleaned = html;\n\n // Remove page header by id\n cleaned = cleaned.replace(\n /<header[^>]*id=\"page-header\"[^>]*>.*?<\\/header>/gis,\n \"\"\n );\n\n return cleaned;\n }\n\n /**\n * Remove ChatGPT sidebar from HTML\n */\n removeSidebar(html: string): string {\n // The sidebar wrapper is hidden with CSS in parse(). Its nested <div>s\n // cannot be balanced with a regex.\n return html.replace(/<nav[^>]*>.*?<\\/nav>/gis, \"\");\n }\n\n /**\n * Remove ChatGPT footer/composer from HTML.\n * Handled with CSS in parse(). A regex cannot balance the nested <div>s of\n * the composer, and a partial removal changes the page structure.\n */\n removeFooter(html: string): string {\n return html;\n }\n\n /**\n * Remove ChatGPT cookie banner from HTML\n */\n removeCookieBanner(html: string): string {\n // Remove the cookie dialog banner (matched by cookie-policy URL, language-agnostic)\n return html.replace(/<div[^>]*role=\"dialog\"[^>]*>[\\s\\S]*?openai\\.com\\/policies\\/cookie-policy[\\s\\S]*?<\\/div><\\/div><\\/div><\\/div><\\/div><\\/div>/gi, '');\n }\n\n /**\n * Remove ChatGPT sources/search flyout panel from HTML.\n * Handled with CSS in parse().\n */\n removeSources(html: string): string {\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in ChatGPT response\");\n }\n\n let finalHtml = html;\n\n const removeFooter = options?.removeFooter ?? false;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Always remove cookie banner\n finalHtml = this.removeCookieBanner(finalHtml);\n\n // Remove header if requested\n if (options?.removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sources panel if requested\n if (options?.removeSources) {\n finalHtml = this.removeSources(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Build CSS overrides conditionally based on which remove* options are active\n let customCSS = '';\n\n if (options?.removeSidebar) {\n customCSS += `\n #stage-slideover-sidebar { display: none !important; }\n [data-sidebar-item] { display: none !important; }\n [data-skip-to-content] { display: none !important; }\n .h-svh { height: auto !important; }\n `;\n }\n\n if (removeFooter) {\n customCSS += `\n #thread-bottom-container { display: none !important; }\n form[data-type=\"unified-composer\"] { display: none !important; }\n #thread { min-height: auto !important; }\n `;\n }\n\n if (options?.removeSources) {\n customCSS += `\n /* Side flyout, the modal sheet that replaces it on narrow pages, and\n the sources dialog of the mobile page */\n [data-testid=\"stage-thread-flyout\"],\n [data-sheet-travel-state],\n #assistant-sources-dialog {\n display: none !important;\n }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n cookieBannerRemoved: true,\n headerRemoved: options?.removeHeader || false,\n sidebarRemoved: options?.removeSidebar || false,\n footerRemoved: removeFooter,\n sourcesRemoved: options?.removeSources || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from './base-provider';\nimport { AIProvider, ParsedResponse, ParseOptions, ContentExtraction, ProviderMetadata } from '../core/types';\n\nexport class GeminiProvider extends BaseProvider {\n readonly name: AIProvider = 'GEMINI';\n readonly baseUrl = 'https://gemini.google.com';\n\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response, true);\n }\n\n /**\n * Remove Gemini header/navbar from HTML\n */\n removeHeader(html: string): string {\n let cleaned = html;\n\n // Remove the Google navbar with boqOnegoogleliteOgbOneGoogleBar class\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*boqOnegoogleliteOgbOneGoogleBar[^\"]*\"[^>]*>.*?<\\/div><\\/div><\\/div><\\/div>/gis, '');\n\n // Remove top-bar-actions (About Gemini, Gemini App, Subscriptions, For Business links)\n cleaned = cleaned.replace(/<top-bar-actions[^>]*>.*?<\\/top-bar-actions>/gis, '');\n\n // Remove desktop-ogb-buffer\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*desktop-ogb-buffer[^\"]*\"[^>]*><\\/div>/gis, '');\n\n return cleaned;\n }\n\n /**\n * Remove Gemini footer/follow-up input box from HTML\n */\n removeFooter(html: string): string {\n // Remove input-container (text input, upload button, send button, disclaimer)\n return html.replace(/<input-container[^>]*>.*?<\\/input-container>/gis, '');\n }\n\n /**\n * Remove Gemini sidebar from HTML\n */\n removeSidebar(html: string): string {\n // Remove bard-sidenav element\n return html.replace(/<bard-sidenav[^>]*>.*?<\\/bard-sidenav>/gis, '');\n }\n\n /**\n * Remove Gemini sources panel from HTML\n */\n removeSources(html: string): string {\n let cleaned = html;\n\n // Remove the context-sidebar element (contains source cards)\n cleaned = cleaned.replace(/<context-sidebar[^>]*>[\\s\\S]*?<\\/context-sidebar>/gi, '');\n\n // Remove the sources-sidebar-button trigger\n cleaned = cleaned.replace(/<sources-sidebar-button[^>]*>[\\s\\S]*?<\\/sources-sidebar-button>/gi, '');\n\n return cleaned;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text, sources } = this.extractContent(response);\n\n if (!html) {\n throw new Error('No HTML content found in Gemini response');\n }\n\n let finalHtml = html;\n\n const removeHeader = options?.removeHeader ?? false;\n const removeFooter = options?.removeFooter ?? false;\n\n // Sanitize HTML (remove scripts and noscript)\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove sources panel if requested\n if (options?.removeSources) {\n finalHtml = this.removeSources(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Always-on: hide the \"Sign in\" prompt above the input box\n let customCSS = `\n sign-in-nudge { display: none !important; }\n `;\n\n // The hamburger button has nested <div>s that a regex cannot balance\n if (removeHeader) {\n customCSS += `\n .side-nav-menu-button { display: none !important; }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n sources,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n sourcesRemoved: options?.removeSources || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class PerplexityProvider extends BaseProvider {\n readonly name: AIProvider = \"PERPLEXITY\";\n readonly baseUrl = \"https://www.perplexity.ai\";\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove Perplexity header/navbar from HTML\n */\n removeHeader(html: string): string {\n // Remove navbar by targeting the unique @container/header class\n // Matches from the navbar opening div through the border divider at the bottom\n return html.replace(\n /<div[^>]*class=\"[^\"]*@container\\/header[^\"]*\"[^>]*>.*?<div[^>]*class=\"[^\"]*absolute bottom-0 inset-x-0 border-b[^\"]*\"[^>]*><\\/div>/gis,\n \"\"\n );\n }\n\n /**\n * Remove Perplexity footer/followup input from HTML.\n * Uses CSS hiding — the footer's deeply nested DOM makes regex counting\n * of closing </div> tags fragile across Perplexity versions.\n */\n removeFooter(_html: string): string {\n // Handled via CSS injection in parse() for reliability\n return _html;\n }\n\n /**\n * Remove Perplexity left sidebar navigation from HTML\n */\n removeSidebar(html: string): string {\n let cleaned = html;\n // Remove the sidebar nav element and its width-holder parent\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*w-sideBarWidth[^\"]*\"[^>]*>[\\s\\S]*?<\\/nav>[\\s\\S]*?<\\/div>/gi,\n \"\"\n );\n return cleaned;\n }\n\n /**\n * Remove Perplexity sources panel from HTML.\n *\n * Why: Perplexity's sources panel is the deeply-nested\n * `fixed inset-y-0 right-0` container that wraps a citations tabpanel.\n * We can't reliably balance its nested </div>s with regex, and a partial\n * strip orphans the panel's children visibly. CSS-only hiding (see\n * parse()) is the load-bearing approach — `display:none` on the wrapper\n * collapses every descendant. The same rule hides the open \"Sources\"\n * popover, which Perplexity renders in a Radix popper at the body root.\n */\n removeSources(html: string): string {\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in Perplexity response\");\n }\n\n let finalHtml = html;\n\n const removeHeader = options?.removeHeader ?? false;\n const removeFooter = options?.removeFooter ?? false;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Fix collapsed answer container: Perplexity uses JS animation to expand the\n // answer area from height:48px. Without scripts, it stays collapsed.\n finalHtml = finalHtml.replace(\n /style=\"transition: none; overflow: hidden; height: 48px;\"/gi,\n ''\n );\n\n // Strip inline padding-right used for the sources sidecar panel\n // (e.g. padding-right: 500px) which squeezes content when sources are removed\n finalHtml = finalHtml.replace(\n /padding-right:\\s*\\d+px/gi,\n 'padding-right: 0px'\n );\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sources panel if requested\n if (options?.removeSources) {\n finalHtml = this.removeSources(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Build CSS overrides conditionally based on which remove* options are active\n let customCSS = `\n #cookie-consent,\n [role=\"dialog\"]:has(#cookie-consent),\n div[role=\"dialog\"][class*=\"fixed\"][class*=\"bottom-2\"] {\n display: none !important;\n }\n /* Login prompts: the full-page modal and the corner card. The #root\n prefix keeps the rule above the removeSidebar layout overrides. */\n [data-type=\"portal\"]:has([data-testid=\"login-modal\"]),\n #root div[class*=\"fixed\"]:has([data-testid=\"login-modal\"]),\n div[class*=\"fixed\"]:has([data-testid=\"login-modal\"]) {\n display: none !important;\n }\n [data-radix-focus-guard] {\n display: none !important;\n }\n `;\n\n if (options?.removeSidebar) {\n customCSS += `\n [class*=\"w-sideBarWidth\"] { display: none !important; }\n #root, #root > div, #root > div > div {\n display: block !important;\n height: auto !important;\n max-height: none !important;\n width: 100% !important;\n padding: 0 !important;\n }\n main {\n display: block !important;\n height: auto !important;\n max-height: none !important;\n overflow: visible !important;\n }\n main > div {\n height: auto !important;\n overflow: visible !important;\n }\n [class*=\"scrollable-container\"] {\n height: auto !important;\n overflow: visible !important;\n }\n [class*=\"max-w-threadContentWidth\"] {\n max-width: 100% !important;\n }\n `;\n }\n\n if (options?.removeSources) {\n customCSS += `\n div[class*=\"fixed\"][class*=\"inset-y-0\"][class*=\"right-0\"],\n [data-radix-popper-content-wrapper] {\n display: none !important;\n }\n `;\n }\n\n if (removeFooter) {\n customCSS += `\n [class*=\"bottom-safeAreaInsetBottom\"] {\n display: none !important;\n }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n linksRemoved: options?.removeLinks || false,\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n cookieBannerRemoved: true,\n sourcesRemoved: options?.removeSources || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from './base-provider';\nimport { AIProvider, ParsedResponse, ParseOptions, ContentExtraction, ProviderMetadata } from '../core/types';\n\nexport class CopilotProvider extends BaseProvider {\n readonly name: AIProvider = 'COPILOT';\n readonly baseUrl = 'https://copilot.microsoft.com';\n\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove Copilot header/navbar from HTML\n */\n removeHeader(html: string): string {\n let cleaned = html;\n\n // Remove settings wrapper (share/settings buttons in top-right corner)\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*absolute flex end-6 origin-top-right flex-col items-end[^\"]*\"[^>]*data-testid=\"settings-wrapper\"[^>]*>.*?<\\/div><\\/div>/gis, '');\n\n return cleaned;\n }\n\n /**\n * Remove Copilot footer/followup input box from HTML\n */\n removeFooter(html: string): string {\n let cleaned = html;\n\n // Remove the composer (input box at bottom)\n // Starts with: <div class=\"absolute bottom-0 w-full\">\n // Contains: file input, composer content with textarea, buttons (home, attach, chat mode, audio call)\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*absolute bottom-0 w-full[^\"]*\"[^>]*>.*?<\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div><\\/div>/gis, '');\n\n // Remove spacer div for composer height\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*mt-\\[var\\(--composer-container-height\\)\\][^\"]*\"[^>]*><\\/div>/gis, '');\n\n // Remove \"scroll to bottom\" button (full container with button and inner content)\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*pointer-events-none absolute flex justify-center z-20 inset-x-0 bottom-\\[calc\\(var\\(--composer-container-height\\)\\+1rem\\)\\][^\"]*\"[^>]*>.*?<button[^>]*data-testid=\"scroll-to-bottom-button\"[^>]*>.*?<\\/button><\\/div>/gis, '');\n\n return cleaned;\n }\n\n /**\n * Remove Copilot cookie banner from HTML\n */\n removeCookieBanner(html: string): string {\n let cleaned = html;\n\n // Remove cookie banner by id\n cleaned = cleaned.replace(/<div[^>]*id=\"cookie-banner\"[^>]*>.*?<\\/div>.*?<\\/div>.*?<\\/div>.*?<\\/div>/gis, '');\n\n // Remove cookie banner by max-w-cookie-banner class (outer container)\n cleaned = cleaned.replace(/<div[^>]*class=\"[^\"]*max-w-cookie-banner[^\"]*\"[^>]*>.*?<\\/div>.*?<\\/div>.*?<\\/div>.*?<\\/div>/gis, '');\n\n return cleaned;\n }\n\n /**\n * Remove Copilot sources/references panel from HTML\n */\n removeSources(html: string): string {\n // Remove the references panel (right-side panel with variable width containing citations)\n return html.replace(/<div[^>]*class=\"[^\"]*relative h-full overflow-hidden will-change-auto[^\"]*\"[^>]*style=\"[^\"]*width:\\s*\\d+px[^\"]*\"[^>]*>[\\s\\S]*?(?=<div[^>]*class=\"[^\"]*pointer-events-none (?:fixed|absolute)[^\"]*\")/gi, '');\n }\n\n /**\n * Remove Copilot sidebar from HTML\n */\n removeSidebar(html: string): string {\n // Handled with CSS in parse(). The sidebar shares a flex wrapper with\n // <main>, and a regex removes the opening tag of that wrapper.\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error('No HTML content found in Copilot response');\n }\n\n let finalHtml = html;\n\n const removeHeader = options?.removeHeader ?? false;\n const removeFooter = options?.removeFooter ?? false;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Remove cookie banner (always)\n finalHtml = this.removeCookieBanner(finalHtml);\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove sources/references panel if requested\n if (options?.removeSources) {\n finalHtml = this.removeSources(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n let customCSS = '';\n\n if (removeHeader) {\n customCSS += `\n [data-testid=\"sticky-header\"],\n [data-testid=\"backstage-chats\"],\n div:has(> div > [data-testid=\"date-divider\"]) {\n display: none !important;\n }\n `;\n }\n\n if (options?.removeSidebar) {\n customCSS += `\n div:has(> #sidebar-container) { display: none !important; }\n `;\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n cookieBannerRemoved: true,\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n sourcesRemoved: options?.removeSources || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class AIOverviewProvider extends BaseProvider {\n readonly name: AIProvider = \"AIOVERVIEW\";\n readonly baseUrl = \"https://www.google.com\";\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response, true);\n }\n\n /**\n * Remove Google Search header/navbar from HTML\n */\n removeHeader(html: string): string {\n // Remove header elements via CSS injection\n return html;\n }\n\n /**\n * Remove Google Search footer from HTML\n */\n removeFooter(html: string): string {\n // Remove footer elements via CSS injection\n return html;\n }\n\n /**\n * Remove Google Search sidebar from HTML\n */\n removeSidebar(html: string): string {\n // Remove sidebar elements via CSS injection\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, sources } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in AI Overview response\");\n }\n\n let finalHtml = html;\n\n // For AI Overview, default to removing header and footer for cleaner display\n const removeHeader = options?.removeHeader ?? true;\n const removeFooter = options?.removeFooter ?? true;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Build CSS based on options\n let stylesToInject = \"\";\n\n // Header removal styles\n if (removeHeader) {\n stylesToInject += `\n /* Header hiding */\n header, #header, #searchform, .sfbg, #appbar,\n div[role=\"navigation\"], #leftnav, #sidetogether,\n [role=\"banner\"], .Fgvgjc, #hdtb, .hdtb-msb,\n .DZ13He, .wYq63b, .eT9Cje, .bNg8Rb, .S6VXfe, .Lu57id {\n display: none !important;\n }\n `;\n }\n\n // Sidebar removal styles\n if (options?.removeSidebar) {\n stylesToInject += `\n /* Sidebar hiding */\n #leftnav, #sidetogether {\n display: none !important;\n }\n `;\n }\n\n // Footer removal styles\n if (removeFooter) {\n stylesToInject += `\n /* Footer hiding */\n footer, #footer, #sfooter, .fbar,\n .pdp-nav, [aria-label=\"Main menu\"], .gb_Td, .gb_L {\n display: none !important;\n }\n `;\n }\n\n // Inject base URL and styles\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS: stylesToInject,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n sources,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class AIModeProvider extends BaseProvider {\n readonly name: AIProvider = \"AIMODE\";\n readonly baseUrl = \"https://www.google.com\";\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove Google Search header/navbar from HTML\n */\n removeHeader(html: string): string {\n let cleaned = html;\n\n // Remove the AI Mode filter/header bar\n // Starts with <div jsname=\"oEQ3x\" class=\"DZ13He YNk70c EjQTId\">\n // Contains the Filters and Topics navigation (AI Mode, All, Images, Videos, News, More)\n // Ends with closing divs after <hr class=\"e9c7U\">\n cleaned = cleaned.replace(\n /<div[^>]*jsname=\"oEQ3x\"[^>]*class=\"[^\"]*DZ13He[^\"]*\"[^>]*>.*?<hr class=\"e9c7U\">.*?<\\/div><\\/div><\\/div><\\/div><\\/div>/gis,\n \"\"\n );\n\n return cleaned;\n }\n\n /**\n * Remove Google Search footer from HTML\n */\n removeFooter(html: string): string {\n let cleaned = html;\n\n // Remove the AI Mode input bar/footer\n // Target the most unique identifier: data-xid=\"aim-mars-input-plate\"\n // This element is deeply nested, so we need to match many closing divs\n cleaned = cleaned.replace(\n /<div[^>]*data-xid=\"aim-mars-input-plate\"[^>]*>[\\s\\S]*?<\\/div><\\/div><\\/div><\\/div><\\/div>/gis,\n \"\"\n );\n\n // Fallback: Target by jscontroller P5gZDb which wraps the input plate\n cleaned = cleaned.replace(\n /<div[^>]*jscontroller=\"P5gZDb\"[^>]*>[\\s\\S]*?<\\/div><\\/div><\\/div>/gis,\n \"\"\n );\n\n // Fallback: Target the t0ITR container\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*t0ITR hh3ttd[^\"]*\"[^>]*>[\\s\\S]*?<\\/div><\\/div>/gis,\n \"\"\n );\n\n // Fallback: Target outer y4VEUd vve6Ce wrapper\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*y4VEUd vve6Ce[^\"]*\"[^>]*>[\\s\\S]*?<\\/div><\\/div>/gis,\n \"\"\n );\n\n return cleaned;\n }\n\n /**\n * Remove Google Search sidebar from HTML\n */\n removeSidebar(html: string): string {\n let cleaned = html;\n\n // Remove the AI Mode history panel/dialog\n // Target by aria-label (handles both attribute orderings)\n cleaned = cleaned.replace(\n /<div[^>]*aria-label=\"AI Mode history\"[^>]*class=\"[^\"]*ho072b[^\"]*\"[^>]*>[\\s\\S]*?(?=<!--TgQPHd)/gi,\n \"\"\n );\n // Fallback: class before aria-label\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*ho072b[^\"]*\"[^>]*aria-label=\"AI Mode history\"[^>]*>[\\s\\S]*?(?=<!--TgQPHd)/gi,\n \"\"\n );\n\n // Remove the floating action buttons (OEwhSe wrapper)\n cleaned = cleaned.replace(\n /<div[^>]*class=\"[^\"]*OEwhSe[^\"]*\"[^>]*>[\\s\\S]*?<\\/div><\\/div>/gis,\n \"\"\n );\n\n // Remove buttons with aria-label\n cleaned = cleaned.replace(\n /<button[^>]*aria-label=\"AI Mode history\"[^>]*>[\\s\\S]*?<\\/button>/gis,\n \"\"\n );\n\n return cleaned;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in AI Mode response\");\n }\n\n let finalHtml = html;\n\n // For AI Mode, default to removing header and footer for cleaner display\n const removeHeader = options?.removeHeader ?? true;\n const removeFooter = options?.removeFooter ?? true;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Remove header if requested\n if (removeHeader) {\n finalHtml = this.removeHeader(finalHtml);\n }\n\n // Remove footer if requested\n if (removeFooter) {\n finalHtml = this.removeFooter(finalHtml);\n }\n\n // Remove sidebar if requested\n if (options?.removeSidebar) {\n finalHtml = this.removeSidebar(finalHtml);\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n // Build CSS based on options\n let stylesToInject = \"\";\n\n // Always inject general layout\n /* Remove cookie consent banner */\n stylesToInject += `\n .KxvlWc, #CXQnmb {\n display: none !important;\n }\n `;\n\n // Header removal styles\n if (removeHeader) {\n stylesToInject += `\n /* Header hiding */\n header, #header, #searchform, .sfbg, #appbar,\n div[role=\"navigation\"], #leftnav, #sidetogether,\n [role=\"banner\"], .Fgvgjc, #hdtb, .hdtb-msb,\n .DZ13He, .wYq63b, .eT9Cje, .bNg8Rb, .S6VXfe, .Lu57id,\n .YHsVn, .UTNPFf {\n display: none !important;\n }\n `;\n }\n\n // Footer removal styles\n if (removeFooter) {\n stylesToInject += `\n /* Footer hiding */\n footer, #footer, .fbar,\n .pdp-nav, [aria-label=\"Main menu\"], .gb_Td, .gb_L {\n display: none !important;\n }\n /* Hide the \"Ask anything\" input bar */\n [data-xid=\"aim-mars-input-plate\"],\n .UAbVe, .y4VEUd, .t0ITR.hh3ttd {\n display: none !important;\n }\n `;\n }\n\n // Sidebar removal styles\n if (options?.removeSidebar) {\n stylesToInject += `\n /* Hide AI Mode history panel */\n .ho072b, .OEwhSe, .qEn1od {\n display: none !important;\n }\n `;\n }\n\n // Inject base URL and styles\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS: stylesToInject,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n headerRemoved: removeHeader,\n footerRemoved: removeFooter,\n sidebarRemoved: options?.removeSidebar || false,\n linksRemoved: options?.removeLinks || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { BaseProvider } from \"./base-provider\";\nimport {\n AIProvider,\n ParsedResponse,\n ParseOptions,\n ContentExtraction,\n ProviderMetadata,\n} from \"../core/types\";\n\nexport class GrokProvider extends BaseProvider {\n readonly name: AIProvider = \"GROK\";\n readonly baseUrl = \"https://grok.com\";\n\n extractContent(response: any): ContentExtraction {\n return this.extractContentCommon(response);\n }\n\n /**\n * Remove Grok header from HTML (using CSS-based hiding)\n */\n removeHeader(html: string): string {\n // Header removal is now done via CSS in the parse method\n return html;\n }\n\n /**\n * Remove Grok footer/input area from HTML (using CSS-based hiding)\n */\n removeFooter(html: string): string {\n // Footer removal is now done via CSS in the parse method\n return html;\n }\n\n parse(response: any, options?: ParseOptions): ParsedResponse {\n const { html, text } = this.extractContent(response);\n\n if (!html) {\n throw new Error(\"No HTML content found in Grok response\");\n }\n\n let finalHtml = html;\n\n // Sanitize HTML\n finalHtml = this.sanitizeHtml(finalHtml);\n\n // Build CSS based on options\n let stylesToInject = '';\n\n // Always-on: hide cookie/privacy policy banner (Grok uses data-cookie-banner attribute)\n stylesToInject += `\n [data-cookie-banner],\n [data-cookie-banner=\"true\"] {\n display: none !important;\n }\n `;\n\n // Always-on: hide rate-limit banners and toast notifications\n stylesToInject += `\n [data-sonner-toaster],\n [data-sonner-toast],\n [class*=\"sonner-toast\"] {\n display: none !important;\n }\n `;\n\n // Sources panel removal via regex (CSS selectors don't reliably hide this element)\n if (options?.removeSources) {\n // Remove the sources panel wrapper containing the aside\n finalHtml = finalHtml.replace(/<div[^>]*class=\"[^\"]*h-dvh[^\"]*flex-shrink-0[^\"]*max-w-[^\"]*\"[^>]*>[\\s\\S]*?<\\/aside>[\\s\\S]*?(?=<section)/gi, '');\n\n // Hide the inline \"N sources\" trigger button and vaul-drawer overlay via CSS\n stylesToInject += `\n div[data-state] > div.flex.flex-row.gap-1.items-center.rounded-full.cursor-pointer {\n display: none !important;\n }\n [vaul-drawer][vaul-drawer-direction=\"right\"],\n [vaul-overlay] {\n display: none !important;\n }\n `;\n }\n\n // Header hiding via CSS\n if (options?.removeHeader) {\n stylesToInject += `\n /* Header hiding - hide elements with Grok's header class pattern */\n div[class*=\"h-16\"][class*=\"top-0\"][class*=\"z-10\"],\n div[class*=\"absolute\"][class*=\"inset-x-0\"][class*=\"top-0\"] {\n display: none !important;\n }\n `;\n }\n\n // Footer hiding via CSS\n if (options?.removeFooter) {\n stylesToInject += `\n /* Footer hiding - hide Grok's footer/input area */\n div[class*=\"absolute\"][class*=\"inset-x-0\"][class*=\"bottom-0\"][class*=\"max-w-breakout\"],\n div[class*=\"absolute\"][class*=\"bottom-0\"][class*=\"w-full\"] {\n display: none !important;\n }\n `;\n }\n\n // Remove links if requested\n if (options?.removeLinks) {\n finalHtml = this.removeLinks(finalHtml);\n }\n\n finalHtml = this.injectStyles(finalHtml, {\n baseUrl: this.baseUrl,\n customCSS: stylesToInject,\n });\n\n return {\n provider: this.name,\n html: finalHtml,\n text,\n metadata: {\n isFullDocument: this.isFullDocument(finalHtml),\n linksRemoved: options?.removeLinks || false,\n headerRemoved: options?.removeHeader || false,\n footerRemoved: options?.removeFooter || false,\n cookieBannerRemoved: true,\n sourcesRemoved: options?.removeSources || false,\n } as ProviderMetadata,\n };\n }\n}\n","import { AIProvider, ParsedResponse, ParseOptions, extractContentCommon } from './types';\nimport { ProviderDetector } from './detector';\nimport { ChatGPTProvider } from '../providers/chatgpt';\nimport { GeminiProvider } from '../providers/gemini';\nimport { PerplexityProvider } from '../providers/perplexity';\nimport { CopilotProvider } from '../providers/copilot';\nimport { AIOverviewProvider } from '../providers/ai-overview';\nimport { AIModeProvider } from '../providers/ai-mode';\nimport { GrokProvider } from '../providers/grok';\n\nexport class AIResponseParser {\n private providers: Map<AIProvider, any> = new Map();\n\n constructor() {\n this.providers.set('CHATGPT', new ChatGPTProvider());\n this.providers.set('GEMINI', new GeminiProvider());\n this.providers.set('PERPLEXITY', new PerplexityProvider());\n this.providers.set('COPILOT', new CopilotProvider());\n this.providers.set('AIOVERVIEW', new AIOverviewProvider());\n this.providers.set('AIMODE', new AIModeProvider());\n this.providers.set('GROK', new GrokProvider());\n }\n\n /**\n * Parse an AI response with auto-detected provider\n */\n parse(response: any, options?: ParseOptions): ParsedResponse | null {\n const detection = ProviderDetector.detect(response);\n\n if (!detection) {\n // Try to parse as generic HTML if no provider detected\n return this.parseGeneric(response);\n }\n\n const provider = this.providers.get(detection.provider);\n if (!provider) {\n return null;\n }\n\n try {\n const parsed = provider.parse(response, options);\n return {\n ...parsed,\n metadata: {\n ...parsed.metadata,\n detectionConfidence: detection.confidence,\n },\n };\n } catch (error) {\n console.error(`Failed to parse response with ${detection.provider}:`, error);\n return null;\n }\n }\n\n /**\n * Parse with explicit provider specification\n */\n parseWithProvider(\n response: any,\n provider: AIProvider,\n options?: ParseOptions\n ): ParsedResponse | null {\n const providerInstance = this.providers.get(provider);\n if (!providerInstance) {\n throw new Error(`Unknown provider: ${provider}`);\n }\n\n try {\n return providerInstance.parse(response, options);\n } catch (error) {\n console.error(`Failed to parse response with ${provider}:`, error);\n return null;\n }\n }\n\n /**\n * Detect the provider from a response\n */\n detectProvider(response: any): AIProvider | null {\n const detection = ProviderDetector.detect(response);\n return detection?.provider || null;\n }\n\n /**\n * Get all possible providers with confidence scores\n */\n detectAllProviders(response: any): Array<{ provider: AIProvider; confidence: number }> {\n return ProviderDetector.getAllProviders(response);\n }\n\n /**\n * Parse as generic HTML when no specific provider is detected\n */\n private parseGeneric(response: any): ParsedResponse | null {\n const { html, text } = extractContentCommon(response);\n\n if (!html && !text) {\n return null;\n }\n\n // Basic sanitization\n let sanitizedHtml = html;\n if (sanitizedHtml) {\n sanitizedHtml = sanitizedHtml.replace(/<script\\b[^>]*>[\\s\\S]*?<\\/script>/gim, '');\n sanitizedHtml = sanitizedHtml.replace(/<noscript[\\s\\S]*?<\\/noscript>/gi, '');\n }\n\n return {\n provider: 'CHATGPT' as AIProvider, // Default to ChatGPT for unknown\n html: sanitizedHtml || '',\n text: text || '',\n metadata: {\n isGeneric: true,\n },\n };\n }\n\n /**\n * Get list of supported providers\n */\n getSupportedProviders(): AIProvider[] {\n return Array.from(this.providers.keys());\n }\n\n /**\n * Register a custom provider\n */\n registerProvider(provider: AIProvider, instance: any): void {\n this.providers.set(provider, instance);\n }\n}\n\n// Export a singleton instance\nexport const parser = new AIResponseParser();\n\n// Convenience functions\nexport const parseAiResponse = (response: any, options?: ParseOptions) =>\n parser.parse(response, options);\n\nexport const detectProvider = (response: any) =>\n parser.detectProvider(response);"],"names":["extractContentCommon","response","html","text","dataToCheck","result","trim","startsWith","includes","content","ProviderDetector","detect","scores","CHATGPT","GEMINI","PERPLEXITY","COPILOT","AIOVERVIEW","AIMODE","GROK","provider","patterns","Object","entries","this","PROVIDER_PATTERNS","pattern","_a","maxScore","detectedProvider","score","confidence","values","reduce","a","b","Math","max","getAllProviders","providers","matches","push","length","sort","validate","detected","_b","aioverview","_c","BaseProvider","includeSources","sources","injectStyles","options","styledHtml","baseUrl","replace","styles","customCSS","sanitizeHtml","sanitized","isFullDocument","test","removeLinks","wrapFragment","ChatGPTProvider","constructor","name","extractContent","match","attributes","cleanedAttrs","removeHeader","cleaned","removeSidebar","removeFooter","removeCookieBanner","removeSources","parse","Error","finalHtml","metadata","cookieBannerRemoved","headerRemoved","sidebarRemoved","footerRemoved","sourcesRemoved","linksRemoved","GeminiProvider","PerplexityProvider","_html","CopilotProvider","AIOverviewProvider","stylesToInject","AIModeProvider","GrokProvider","AIResponseParser","Map","set","detection","parseGeneric","get","parsed","detectionConfidence","error","console","parseWithProvider","providerInstance","detectProvider","detectAllProviders","sanitizedHtml","isGeneric","getSupportedProviders","Array","from","keys","registerProvider","instance","parser"],"mappings":"aAgEM,SAAUA,EAAqBC,GACnC,IAAIC,EAAO,GACPC,EAAO,GAGPC,EAAcH,EA0BlB,OAzBIA,EAASI,SACXD,EAAcH,EAASI,QAIE,iBAAhBD,EACLA,EAAYE,OAAOC,WAAW,MAAQH,EAAYI,SAAS,KAC7DN,EAAOE,EAEPD,EAAOC,EAEuB,iBAAhBA,GAA4C,OAAhBA,IACxCA,EAAYF,KACdA,EAAOE,EAAYF,KACVE,EAAYK,QACjBL,EAAYK,QAAQH,OAAOC,WAAW,KACxCL,EAAOE,EAAYK,QAEnBN,EAAOC,EAAYK,QAEZL,EAAYD,OACrBA,EAAOC,EAAYD,OAIhB,CAAED,OAAMC,OACjB,OC9FaO,EA0FX,aAAOC,CAAOV,GACZ,MAAMW,EAAqC,CACzCC,QAAS,EACTC,OAAQ,EACRC,WAAY,EACZC,QAAS,EACTC,WAAY,EACZC,OAAQ,EACRC,KAAM,GAIR,IAAK,MAA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/D,IACT,CACF,CAKA,iBAAAE,CACEzG,EACAmB,EACAiC,GAEA,MAAMsD,EAAmBnF,KAAKe,UAAU8D,IAAIjF,GAC5C,IAAKuF,EACH,MAAM,IAAI5B,MAAM,qBAAqB3D,KAGvC,IACE,OAAOuF,EAAiB7B,MAAM7E,EAAUoD,EAC1C,CAAE,MAAOmD,GAEP,OADAC,QAAQD,MAAM,iCAAiCpF,KAAaoF,GACrD,IACT,CACF,CAKA,cAAAI,CAAe3G,GACb,MAAMkG,EAAYzF,EAAiBC,OAAOV,GAC1C,OAAOkG,aAAS,EAATA,EAAW/E,WAAY,IAChC,CAKA,kBAAAyF,CAAmB5G,GACjB,OAAOS,EAAiB4B,gBAAgBrC,EAC1C,CAKQ,YAAAmG,CAAanG,GACnB,MAAMC,KAAEA,EAAIC,KAAEA,GAASH,EAAqBC,GAE5C,IAAKC,IAASC,EACZ,OAAO,KAIT,IAAI2G,EAAgB5G,EAMpB,OALI4G,IACFA,EAAgBA,EAActD,QAAQ,uCAAwC,IAC9EsD,EAAgBA,EAActD,QAAQ,kCAAmC,KAGpE,CACLpC,SAAU,UACVlB,KAAM4G,GAAiB,GACvB3G,KAAMA,GAAQ,GACd8E,SAAU,CACR8B,WAAW,GAGjB,CAKA,qBAAAC,GACE,OAAOC,MAAMC,KAAK1F,KAAKe,UAAU4E,OACnC,CAKA,gBAAAC,CAAiBhG,EAAsBiG,GACrC7F,KAAKe,UAAU2D,IAAI9E,EAAUiG,EAC/B,EAIK,MAAMC,EAAS,IAAItB,6RAMK/F,GAC7BqH,EAAOV,eAAe3G,2BAJO,CAACA,EAAeoD,IAC7CiE,EAAOxC,MAAM7E,EAAUoD"}
package/dist/index.d.ts CHANGED
@@ -155,7 +155,9 @@ declare class ChatGPTProvider extends BaseProvider {
155
155
  */
156
156
  removeSidebar(html: string): string;
157
157
  /**
158
- * Remove ChatGPT footer/composer from HTML
158
+ * Remove ChatGPT footer/composer from HTML.
159
+ * Handled with CSS in parse(). A regex cannot balance the nested <div>s of
160
+ * the composer, and a partial removal changes the page structure.
159
161
  */
160
162
  removeFooter(html: string): string;
161
163
  /**
@@ -163,7 +165,8 @@ declare class ChatGPTProvider extends BaseProvider {
163
165
  */
164
166
  removeCookieBanner(html: string): string;
165
167
  /**
166
- * Remove ChatGPT sources/search flyout panel from HTML
168
+ * Remove ChatGPT sources/search flyout panel from HTML.
169
+ * Handled with CSS in parse().
167
170
  */
168
171
  removeSources(html: string): string;
169
172
  parse(response: any, options?: ParseOptions): ParsedResponse;
@@ -218,7 +221,8 @@ declare class PerplexityProvider extends BaseProvider {
218
221
  * We can't reliably balance its nested </div>s with regex, and a partial
219
222
  * strip orphans the panel's children visibly. CSS-only hiding (see
220
223
  * parse()) is the load-bearing approach — `display:none` on the wrapper
221
- * collapses every descendant.
224
+ * collapses every descendant. The same rule hides the open "Sources"
225
+ * popover, which Perplexity renders in a Radix popper at the body root.
222
226
  */
223
227
  removeSources(html: string): string;
224
228
  parse(response: any, options?: ParseOptions): ParsedResponse;
package/dist/index.esm.js CHANGED
@@ -1,2 +1,2 @@
1
- function e(e){let t="",r="",i=e;return e.result&&(i=e.result),"string"==typeof i?i.trim().startsWith("<")&&i.includes(">")?t=i:r=i:"object"==typeof i&&null!==i&&(i.html?t=i.html:i.content?i.content.trim().startsWith("<")?t=i.content:r=i.content:i.text&&(r=i.text)),{html:t,text:r}}class t{static detect(e){const t={CHATGPT:0,GEMINI:0,PERPLEXITY:0,COPILOT:0,AIOVERVIEW:0,AIMODE:0,GROK:0};for(const[r,i]of Object.entries(this.PROVIDER_PATTERNS))for(const o of i)try{o(e)&&t[r]++}catch(e){}let r=0,i=null;for(const[e,o]of Object.entries(t))o>r&&(r=o,i=e);return 0===r?null:{provider:i,confidence:r/Object.values(t).reduce((e,t)=>Math.max(e,t),1)}}static getAllProviders(e){const t=[];for(const[r,i]of Object.entries(this.PROVIDER_PATTERNS)){let o=0;for(const t of i)try{t(e)&&o++}catch(e){}o>0&&t.push({provider:r,confidence:o/i.length})}return t.sort((e,t)=>t.confidence-e.confidence)}static validate(e,t){const r=this.detect(e);return(null==r?void 0:r.provider)===t&&r.confidence>.5}}t.PROVIDER_PATTERNS={CHATGPT:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("bg-token-bg-primary")||r.includes("text-token-text-secondary")},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("chatgpt.com")||r.includes("openai.com")}],GEMINI:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("bard-sidenav")||r.includes("mat-sidenav")},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("gemini.google.com")||r.includes("gem-sys-color")}],PERPLEXITY:[e=>{var t;return((null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"").includes("perplexity.ai")},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("prose")&&!r.includes("grok.com")&&!r.includes("chatgpt.com")}],COPILOT:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("copilot.microsoft.com")||r.includes('data-testid="sidebar-container"')}],AIOVERVIEW:[e=>{var t,r,i,o;if(null===(r=null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.aioverview)||void 0===r?void 0:r.text)return!0;if(null===(i=null==e?void 0:e.aioverview)||void 0===i?void 0:i.text)return!0;return((null===(o=null==e?void 0:e.result)||void 0===o?void 0:o.html)||(null==e?void 0:e.html)||"").includes("DnVkpd")},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("WIZ_global_data")&&!r.includes("aim-mars")&&!r.includes("ho072b")}],AIMODE:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("DZ13He")||r.includes("wYq63b")||r.includes("AI Mode")},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("aim-mars")||r.includes("ho072b")}],GROK:[e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("grok.com")||r.includes("x.ai")},e=>{var t;const r=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return r.includes("cdn.grok.com")||r.includes("vaul-drawer")}]};class r{extractContentCommon(t,r=!1){var i;const o=e(t);if(r){let e=[];const r=t.result||t;return"object"==typeof r&&null!==r&&((null===(i=r.aioverview)||void 0===i?void 0:i.sources)?e=r.aioverview.sources:r.sources&&(e=r.sources)),{...o,sources:e}}return o}injectStyles(e,t){let r=e;(null==t?void 0:t.baseUrl)&&!e.includes("<base ")&&(r=r.includes("<head>")?r.replace("<head>",`<head><base href="${t.baseUrl}">`):r.replace(/(<html[^>]*>)/i,`$1<head><base href="${t.baseUrl}"></head>`));const i=(null==t?void 0:t.customCSS)||"";return i&&r.includes("<head>")?r=r.replace("<head>",`<head><style>${i}</style>`):i&&(r=r.replace(/(<html[^>]*>)/i,`$1<head><style>${i}</style></head>`)),r}sanitizeHtml(e){let t=e.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gim,"");return t=t.replace(/<noscript[\s\S]*?<\/noscript>/gi,""),t}isFullDocument(e){return/^\s*(<html|<!DOCTYPE)/i.test(e)}removeLinks(e){return e.replace(/<a\b[^>]*>([\s\S]*?)<\/a>/gim,"$1")}wrapFragment(e){return`<!DOCTYPE html>\n<html>\n<head>\n <meta charset="utf-8">\n <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'none'; style-src 'unsafe-inline';">\n <style>\n body {\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, sans-serif;\n white-space: pre-wrap;\n word-wrap: break-word;\n }\n img { max-width: 100%; height: auto; }\n body {\n pointer-events: none;\n user-select: none;\n }\n </style>\n</head>\n<body>\n ${e}\n</body>\n</html>`}}class i extends r{constructor(){super(...arguments),this.name="CHATGPT",this.baseUrl="https://chatgpt.com"}extractContent(e){return this.extractContentCommon(e)}removeLinks(e){return e.replace(/<a\b([^>]*)>/gi,(e,t)=>{const r=t.replace(/\s+href\s*=\s*["'][^"']*["']/gi,"").replace(/\s+alt\s*=\s*["'][^"']*["']/gi,"").replace(/\s+rel\s*=\s*["'][^"']*["']/gi,"").replace(/\s+target\s*=\s*["'][^"']*["']/gi,"").trim();return`<span${r?" "+r:""}>`}).replace(/<\/a>/gi,"</span>")}removeHeader(e){let t=e;return t=t.replace(/<header[^>]*id="page-header"[^>]*>.*?<\/header>/gis,""),t}removeSidebar(e){let t=e;return t=t.replace(/<nav[^>]*>.*?<\/nav>/gis,""),t=t.replace(/<div[^>]*class="[^"]*sidebar[^"]*"[^>]*>.*?<\/div>/gis,""),t}removeFooter(e){let t=e;return t=t.replace(/<div[^>]*id="thread-bottom-container"[^>]*>.*?<\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*id="thread-bottom"[^>]*>.*?<\/div><\/div><\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*\[grid-area:leading\][^"]*"[^>]*>.*?<\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*\[grid-area:footer\][^"]*"[^>]*>.*?<\/div><\/div><\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*\[grid-area:trailing\][^"]*"[^>]*>.*?<\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*\[view-transition-name:var\(--vt-disclaimer\)\][^>]*>.*?<\/div><\/div>/gis,""),t}removeCookieBanner(e){return e.replace(/<div[^>]*role="dialog"[^>]*>[\s\S]*?openai\.com\/policies\/cookie-policy[\s\S]*?<\/div><\/div><\/div><\/div><\/div><\/div>/gi,"")}removeSources(e){return e.replace(/<div[^>]*data-testid="stage-thread-flyout"[^>]*>[\s\S]*?(?=<\/div><div><\/div><\/div><\/div>)/gi,"")}parse(e,t){var r;const{html:i,text:o}=this.extractContent(e);if(!i)throw new Error("No HTML content found in ChatGPT response");let n=i;const s=null!==(r=null==t?void 0:t.removeFooter)&&void 0!==r&&r;n=this.sanitizeHtml(n),n=this.removeCookieBanner(n),(null==t?void 0:t.removeHeader)&&(n=this.removeHeader(n)),(null==t?void 0:t.removeSidebar)&&(n=this.removeSidebar(n)),s&&(n=this.removeFooter(n)),(null==t?void 0:t.removeSources)&&(n=this.removeSources(n)),(null==t?void 0:t.removeLinks)&&(n=this.removeLinks(n));let l="";return(null==t?void 0:t.removeSidebar)&&(l+="\n [data-sidebar-item] { display: none !important; }\n [data-skip-to-content] { display: none !important; }\n .h-svh { height: auto !important; }\n "),s&&(l+='\n form[data-type="unified-composer"] { display: none !important; }\n #thread { min-height: auto !important; }\n '),n=this.injectStyles(n,{baseUrl:this.baseUrl,customCSS:l}),{provider:this.name,html:n,text:o,metadata:{isFullDocument:this.isFullDocument(n),cookieBannerRemoved:!0,headerRemoved:(null==t?void 0:t.removeHeader)||!1,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,footerRemoved:s,sourcesRemoved:(null==t?void 0:t.removeSources)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class o extends r{constructor(){super(...arguments),this.name="GEMINI",this.baseUrl="https://gemini.google.com"}extractContent(e){return this.extractContentCommon(e,!0)}removeHeader(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*boqOnegoogleliteOgbOneGoogleBar[^"]*"[^>]*>.*?<\/div><\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*side-nav-menu-button[^"]*"[^>]*>.*?<\/div>/gis,""),t=t.replace(/<top-bar-actions[^>]*>.*?<\/top-bar-actions>/gis,""),t=t.replace(/<div[^>]*class="[^"]*desktop-ogb-buffer[^"]*"[^>]*><\/div>/gis,""),t}removeFooter(e){return e.replace(/<input-container[^>]*>.*?<\/input-container>/gis,"")}removeSidebar(e){return e.replace(/<bard-sidenav[^>]*>.*?<\/bard-sidenav>/gis,"")}removeSources(e){let t=e;return t=t.replace(/<context-sidebar[^>]*>[\s\S]*?<\/context-sidebar>/gi,""),t=t.replace(/<sources-sidebar-button[^>]*>[\s\S]*?<\/sources-sidebar-button>/gi,""),t}parse(e,t){var r,i;const{html:o,text:n,sources:s}=this.extractContent(e);if(!o)throw new Error("No HTML content found in Gemini response");let l=o;const a=null!==(r=null==t?void 0:t.removeHeader)&&void 0!==r&&r,d=null!==(i=null==t?void 0:t.removeFooter)&&void 0!==i&&i;return l=this.sanitizeHtml(l),a&&(l=this.removeHeader(l)),d&&(l=this.removeFooter(l)),(null==t?void 0:t.removeSidebar)&&(l=this.removeSidebar(l)),(null==t?void 0:t.removeSources)&&(l=this.removeSources(l)),(null==t?void 0:t.removeLinks)&&(l=this.removeLinks(l)),l=this.injectStyles(l,{baseUrl:this.baseUrl,customCSS:""}),{provider:this.name,html:l,text:n,sources:s,metadata:{isFullDocument:this.isFullDocument(l),headerRemoved:a,footerRemoved:d,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,sourcesRemoved:(null==t?void 0:t.removeSources)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class n extends r{constructor(){super(...arguments),this.name="PERPLEXITY",this.baseUrl="https://www.perplexity.ai"}extractContent(e){return this.extractContentCommon(e)}removeHeader(e){return e.replace(/<div[^>]*class="[^"]*@container\/header[^"]*"[^>]*>.*?<div[^>]*class="[^"]*absolute bottom-0 inset-x-0 border-b[^"]*"[^>]*><\/div>/gis,"")}removeFooter(e){return e}removeSidebar(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*w-sideBarWidth[^"]*"[^>]*>[\s\S]*?<\/nav>[\s\S]*?<\/div>/gi,""),t}removeSources(e){return e}parse(e,t){var r,i;const{html:o,text:n}=this.extractContent(e);if(!o)throw new Error("No HTML content found in Perplexity response");let s=o;const l=null!==(r=null==t?void 0:t.removeHeader)&&void 0!==r&&r,a=null!==(i=null==t?void 0:t.removeFooter)&&void 0!==i&&i;s=this.sanitizeHtml(s),s=s.replace(/style="transition: none; overflow: hidden; height: 48px;"/gi,""),s=s.replace(/padding-right:\s*\d+px/gi,"padding-right: 0px"),l&&(s=this.removeHeader(s)),(null==t?void 0:t.removeSidebar)&&(s=this.removeSidebar(s)),a&&(s=this.removeFooter(s)),(null==t?void 0:t.removeSources)&&(s=this.removeSources(s)),(null==t?void 0:t.removeLinks)&&(s=this.removeLinks(s));let d='\n #cookie-consent,\n [role="dialog"]:has(#cookie-consent) {\n display: none !important;\n }\n [data-radix-focus-guard] {\n display: none !important;\n }\n ';return(null==t?void 0:t.removeSidebar)&&(d+='\n [class*="w-sideBarWidth"] { display: none !important; }\n #root, #root > div, #root > div > div {\n display: block !important;\n height: auto !important;\n max-height: none !important;\n width: 100% !important;\n padding: 0 !important;\n }\n main {\n display: block !important;\n height: auto !important;\n max-height: none !important;\n overflow: visible !important;\n }\n main > div {\n height: auto !important;\n overflow: visible !important;\n }\n [class*="scrollable-container"] {\n height: auto !important;\n overflow: visible !important;\n }\n [class*="max-w-threadContentWidth"] {\n max-width: 100% !important;\n }\n '),(null==t?void 0:t.removeSources)&&(d+='\n div[class*="fixed"][class*="inset-y-0"][class*="right-0"] {\n display: none !important;\n }\n '),a&&(d+='\n [class*="bottom-safeAreaInsetBottom"] {\n display: none !important;\n }\n '),s=this.injectStyles(s,{baseUrl:this.baseUrl,customCSS:d}),{provider:this.name,html:s,text:n,metadata:{isFullDocument:this.isFullDocument(s),linksRemoved:(null==t?void 0:t.removeLinks)||!1,headerRemoved:l,footerRemoved:a,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,cookieBannerRemoved:!0,sourcesRemoved:(null==t?void 0:t.removeSources)||!1}}}}class s extends r{constructor(){super(...arguments),this.name="COPILOT",this.baseUrl="https://copilot.microsoft.com"}extractContent(e){return this.extractContentCommon(e)}removeHeader(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*relative shrink-0 min-h-14[^"]*"[^>]*data-testid="backstage-chats"[^>]*>.*?<\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*flex items-center px-6 mx-auto w-full max-w-chat[^"]*"[^>]*>.*?<span[^>]*data-testid="date-divider"[^>]*>.*?<\/span>.*?<div[^>]*class="[^"]*border-t-\[1px\][^"]*"[^>]*>.*?<\/div>.*?<\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*absolute flex end-6 origin-top-right flex-col items-end[^"]*"[^>]*data-testid="settings-wrapper"[^>]*>.*?<\/div><\/div>/gis,""),t}removeFooter(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*absolute bottom-0 w-full[^"]*"[^>]*>.*?<\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*mt-\[var\(--composer-container-height\)\][^"]*"[^>]*><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*pointer-events-none absolute flex justify-center z-20 inset-x-0 bottom-\[calc\(var\(--composer-container-height\)\+1rem\)\][^"]*"[^>]*>.*?<button[^>]*data-testid="scroll-to-bottom-button"[^>]*>.*?<\/button><\/div>/gis,""),t}removeCookieBanner(e){let t=e;return t=t.replace(/<div[^>]*id="cookie-banner"[^>]*>.*?<\/div>.*?<\/div>.*?<\/div>.*?<\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*max-w-cookie-banner[^"]*"[^>]*>.*?<\/div>.*?<\/div>.*?<\/div>.*?<\/div>/gis,""),t}removeSources(e){return e.replace(/<div[^>]*class="[^"]*relative h-full overflow-hidden will-change-auto[^"]*"[^>]*style="[^"]*width:\s*\d+px[^"]*"[^>]*>[\s\S]*?(?=<div[^>]*class="[^"]*pointer-events-none (?:fixed|absolute)[^"]*")/gi,"")}removeSidebar(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*bg-sidebar-light[^"]*"[^>]*>[\s\S]*?(?=<main)/gi,""),t}parse(e,t){var r,i;const{html:o,text:n}=this.extractContent(e);if(!o)throw new Error("No HTML content found in Copilot response");let s=o;const l=null!==(r=null==t?void 0:t.removeHeader)&&void 0!==r&&r,a=null!==(i=null==t?void 0:t.removeFooter)&&void 0!==i&&i;s=this.sanitizeHtml(s),s=this.removeCookieBanner(s),l&&(s=this.removeHeader(s)),a&&(s=this.removeFooter(s)),(null==t?void 0:t.removeSidebar)&&(s=this.removeSidebar(s)),(null==t?void 0:t.removeSources)&&(s=this.removeSources(s)),(null==t?void 0:t.removeLinks)&&(s=this.removeLinks(s));let d="";return l&&(d+='\n [data-testid="sticky-header"] { display: none !important; }\n '),s=this.injectStyles(s,{baseUrl:this.baseUrl,customCSS:d}),{provider:this.name,html:s,text:n,metadata:{isFullDocument:this.isFullDocument(s),cookieBannerRemoved:!0,headerRemoved:l,footerRemoved:a,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,sourcesRemoved:(null==t?void 0:t.removeSources)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class l extends r{constructor(){super(...arguments),this.name="AIOVERVIEW",this.baseUrl="https://www.google.com"}extractContent(e){return this.extractContentCommon(e,!0)}removeHeader(e){return e}removeFooter(e){return e}removeSidebar(e){return e}parse(e,t){var r,i;const{html:o,sources:n}=this.extractContent(e);if(!o)throw new Error("No HTML content found in AI Overview response");let s=o;const l=null===(r=null==t?void 0:t.removeHeader)||void 0===r||r,a=null===(i=null==t?void 0:t.removeFooter)||void 0===i||i;s=this.sanitizeHtml(s),l&&(s=this.removeHeader(s)),a&&(s=this.removeFooter(s)),(null==t?void 0:t.removeSidebar)&&(s=this.removeSidebar(s)),(null==t?void 0:t.removeLinks)&&(s=this.removeLinks(s));let d="";return l&&(d+='\n /* Header hiding */\n header, #header, #searchform, .sfbg, #appbar,\n div[role="navigation"], #leftnav, #sidetogether,\n [role="banner"], .Fgvgjc, #hdtb, .hdtb-msb,\n .DZ13He, .wYq63b, .eT9Cje, .bNg8Rb, .S6VXfe, .Lu57id {\n display: none !important;\n }\n '),(null==t?void 0:t.removeSidebar)&&(d+="\n /* Sidebar hiding */\n #leftnav, #sidetogether {\n display: none !important;\n }\n "),a&&(d+='\n /* Footer hiding */\n footer, #footer, .fbar,\n .pdp-nav, [aria-label="Main menu"], .gb_Td, .gb_L {\n display: none !important;\n }\n '),s=this.injectStyles(s,{baseUrl:this.baseUrl,customCSS:d}),{provider:this.name,html:s,sources:n,metadata:{isFullDocument:this.isFullDocument(s),headerRemoved:l,footerRemoved:a,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class a extends r{constructor(){super(...arguments),this.name="AIMODE",this.baseUrl="https://www.google.com"}extractContent(e){return this.extractContentCommon(e)}removeHeader(e){let t=e;return t=t.replace(/<div[^>]*jsname="oEQ3x"[^>]*class="[^"]*DZ13He[^"]*"[^>]*>.*?<hr class="e9c7U">.*?<\/div><\/div><\/div><\/div><\/div>/gis,""),t}removeFooter(e){let t=e;return t=t.replace(/<div[^>]*data-xid="aim-mars-input-plate"[^>]*>[\s\S]*?<\/div><\/div><\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*jscontroller="P5gZDb"[^>]*>[\s\S]*?<\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*t0ITR hh3ttd[^"]*"[^>]*>[\s\S]*?<\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*y4VEUd vve6Ce[^"]*"[^>]*>[\s\S]*?<\/div><\/div>/gis,""),t}removeSidebar(e){let t=e;return t=t.replace(/<div[^>]*aria-label="AI Mode history"[^>]*class="[^"]*ho072b[^"]*"[^>]*>[\s\S]*?(?=<!--TgQPHd)/gi,""),t=t.replace(/<div[^>]*class="[^"]*ho072b[^"]*"[^>]*aria-label="AI Mode history"[^>]*>[\s\S]*?(?=<!--TgQPHd)/gi,""),t=t.replace(/<div[^>]*class="[^"]*OEwhSe[^"]*"[^>]*>[\s\S]*?<\/div><\/div>/gis,""),t=t.replace(/<button[^>]*aria-label="AI Mode history"[^>]*>[\s\S]*?<\/button>/gis,""),t}parse(e,t){var r,i;const{html:o,text:n}=this.extractContent(e);if(!o)throw new Error("No HTML content found in AI Mode response");let s=o;const l=null===(r=null==t?void 0:t.removeHeader)||void 0===r||r,a=null===(i=null==t?void 0:t.removeFooter)||void 0===i||i;s=this.sanitizeHtml(s),l&&(s=this.removeHeader(s)),a&&(s=this.removeFooter(s)),(null==t?void 0:t.removeSidebar)&&(s=this.removeSidebar(s)),(null==t?void 0:t.removeLinks)&&(s=this.removeLinks(s));let d="";return d+="\n .KxvlWc, #CXQnmb {\n display: none !important;\n }\n ",l&&(d+='\n /* Header hiding */\n header, #header, #searchform, .sfbg, #appbar,\n div[role="navigation"], #leftnav, #sidetogether,\n [role="banner"], .Fgvgjc, #hdtb, .hdtb-msb,\n .DZ13He, .wYq63b, .eT9Cje, .bNg8Rb, .S6VXfe, .Lu57id,\n .YHsVn, .UTNPFf {\n display: none !important;\n }\n '),a&&(d+='\n /* Footer hiding */\n footer, #footer, .fbar,\n .pdp-nav, [aria-label="Main menu"], .gb_Td, .gb_L {\n display: none !important;\n }\n /* Hide the "Ask anything" input bar */\n [data-xid="aim-mars-input-plate"],\n .UAbVe, .y4VEUd, .t0ITR.hh3ttd {\n display: none !important;\n }\n '),(null==t?void 0:t.removeSidebar)&&(d+="\n /* Hide AI Mode history panel */\n .ho072b, .OEwhSe, .qEn1od {\n display: none !important;\n }\n "),s=this.injectStyles(s,{baseUrl:this.baseUrl,customCSS:d}),{provider:this.name,html:s,text:n,metadata:{isFullDocument:this.isFullDocument(s),headerRemoved:l,footerRemoved:a,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class d extends r{constructor(){super(...arguments),this.name="GROK",this.baseUrl="https://grok.com"}extractContent(e){return this.extractContentCommon(e)}removeHeader(e){return e}removeFooter(e){return e}parse(e,t){const{html:r,text:i}=this.extractContent(e);if(!r)throw new Error("No HTML content found in Grok response");let o=r;o=this.sanitizeHtml(o);let n="";return n+='\n [data-cookie-banner],\n [data-cookie-banner="true"] {\n display: none !important;\n }\n ',n+='\n [data-sonner-toaster],\n [data-sonner-toast],\n [class*="sonner-toast"] {\n display: none !important;\n }\n ',(null==t?void 0:t.removeSources)&&(o=o.replace(/<div[^>]*class="[^"]*h-dvh[^"]*flex-shrink-0[^"]*max-w-[^"]*"[^>]*>[\s\S]*?<\/aside>[\s\S]*?(?=<section)/gi,""),n+='\n div[data-state] > div.flex.flex-row.gap-1.items-center.rounded-full.cursor-pointer {\n display: none !important;\n }\n [vaul-drawer][vaul-drawer-direction="right"],\n [vaul-overlay] {\n display: none !important;\n }\n '),(null==t?void 0:t.removeHeader)&&(n+='\n /* Header hiding - hide elements with Grok\'s header class pattern */\n div[class*="h-16"][class*="top-0"][class*="z-10"],\n div[class*="absolute"][class*="inset-x-0"][class*="top-0"] {\n display: none !important;\n }\n '),(null==t?void 0:t.removeFooter)&&(n+='\n /* Footer hiding - hide Grok\'s footer/input area */\n div[class*="absolute"][class*="inset-x-0"][class*="bottom-0"][class*="max-w-breakout"],\n div[class*="absolute"][class*="bottom-0"][class*="w-full"] {\n display: none !important;\n }\n '),(null==t?void 0:t.removeLinks)&&(o=this.removeLinks(o)),o=this.injectStyles(o,{baseUrl:this.baseUrl,customCSS:n}),{provider:this.name,html:o,text:i,metadata:{isFullDocument:this.isFullDocument(o),linksRemoved:(null==t?void 0:t.removeLinks)||!1,headerRemoved:(null==t?void 0:t.removeHeader)||!1,footerRemoved:(null==t?void 0:t.removeFooter)||!1,cookieBannerRemoved:!0,sourcesRemoved:(null==t?void 0:t.removeSources)||!1}}}}class v{constructor(){this.providers=new Map,this.providers.set("CHATGPT",new i),this.providers.set("GEMINI",new o),this.providers.set("PERPLEXITY",new n),this.providers.set("COPILOT",new s),this.providers.set("AIOVERVIEW",new l),this.providers.set("AIMODE",new a),this.providers.set("GROK",new d)}parse(e,r){const i=t.detect(e);if(!i)return this.parseGeneric(e);const o=this.providers.get(i.provider);if(!o)return null;try{const t=o.parse(e,r);return{...t,metadata:{...t.metadata,detectionConfidence:i.confidence}}}catch(e){return console.error(`Failed to parse response with ${i.provider}:`,e),null}}parseWithProvider(e,t,r){const i=this.providers.get(t);if(!i)throw new Error(`Unknown provider: ${t}`);try{return i.parse(e,r)}catch(e){return console.error(`Failed to parse response with ${t}:`,e),null}}detectProvider(e){const r=t.detect(e);return(null==r?void 0:r.provider)||null}detectAllProviders(e){return t.getAllProviders(e)}parseGeneric(t){const{html:r,text:i}=e(t);if(!r&&!i)return null;let o=r;return o&&(o=o.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gim,""),o=o.replace(/<noscript[\s\S]*?<\/noscript>/gi,"")),{provider:"CHATGPT",html:o||"",text:i||"",metadata:{isGeneric:!0}}}getSupportedProviders(){return Array.from(this.providers.keys())}registerProvider(e,t){this.providers.set(e,t)}}const c=new v,u=(e,t)=>c.parse(e,t),m=e=>c.detectProvider(e);export{a as AIModeProvider,l as AIOverviewProvider,v as AIResponseParser,r as BaseProvider,i as ChatGPTProvider,s as CopilotProvider,o as GeminiProvider,d as GrokProvider,n as PerplexityProvider,t as ProviderDetector,m as detectProvider,u as parseAiResponse,c as parser};
1
+ function e(e){let t="",o="",n=e;return e.result&&(n=e.result),"string"==typeof n?n.trim().startsWith("<")&&n.includes(">")?t=n:o=n:"object"==typeof n&&null!==n&&(n.html?t=n.html:n.content?n.content.trim().startsWith("<")?t=n.content:o=n.content:n.text&&(o=n.text)),{html:t,text:o}}class t{static detect(e){const t={CHATGPT:0,GEMINI:0,PERPLEXITY:0,COPILOT:0,AIOVERVIEW:0,AIMODE:0,GROK:0};for(const[o,n]of Object.entries(this.PROVIDER_PATTERNS))for(const r of n)try{r(e)&&t[o]++}catch(e){}let o=0,n=null;for(const[e,r]of Object.entries(t))r>o&&(o=r,n=e);return 0===o?null:{provider:n,confidence:o/Object.values(t).reduce((e,t)=>Math.max(e,t),1)}}static getAllProviders(e){const t=[];for(const[o,n]of Object.entries(this.PROVIDER_PATTERNS)){let r=0;for(const t of n)try{t(e)&&r++}catch(e){}r>0&&t.push({provider:o,confidence:r/n.length})}return t.sort((e,t)=>t.confidence-e.confidence)}static validate(e,t){const o=this.detect(e);return(null==o?void 0:o.provider)===t&&o.confidence>.5}}t.PROVIDER_PATTERNS={CHATGPT:[e=>{var t;const o=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return o.includes("bg-token-bg-primary")||o.includes("text-token-text-secondary")},e=>{var t;const o=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return o.includes("chatgpt.com")||o.includes("openai.com")}],GEMINI:[e=>{var t;const o=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return o.includes("bard-sidenav")||o.includes("mat-sidenav")},e=>{var t;const o=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return o.includes("<chat-app")||o.includes("gem-sys-color")}],PERPLEXITY:[e=>{var t;return((null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"").includes("perplexity.ai")},e=>{var t;const o=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return o.includes("prose")&&!o.includes("grok.com")&&!o.includes("chatgpt.com")}],COPILOT:[e=>{var t;const o=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return o.includes("copilot.microsoft.com")||o.includes('data-testid="sidebar-container"')}],AIOVERVIEW:[e=>{var t,o,n;return!!(null===(o=null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.aioverview)||void 0===o?void 0:o.text)||!!(null===(n=null==e?void 0:e.aioverview)||void 0===n?void 0:n.text)},e=>{var t;const o=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return o.includes('id="gsr"')&&!o.includes("aim-mars")&&!o.includes("ho072b")}],AIMODE:[e=>{var t;return((null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"").includes("aim-mars")},e=>{var t;return((null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"").includes("ho072b")}],GROK:[e=>{var t;const o=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return o.includes("grok.com")||o.includes("x.ai")},e=>{var t;const o=(null===(t=null==e?void 0:e.result)||void 0===t?void 0:t.html)||(null==e?void 0:e.html)||"";return o.includes("cdn.grok.com")||o.includes("vaul-drawer")}]};class o{extractContentCommon(t,o=!1){var n;const r=e(t);if(o){let e=[];const o=t.result||t;return"object"==typeof o&&null!==o&&((null===(n=o.aioverview)||void 0===n?void 0:n.sources)?e=o.aioverview.sources:o.sources&&(e=o.sources)),{...r,sources:e}}return r}injectStyles(e,t){let o=e;(null==t?void 0:t.baseUrl)&&!e.includes("<base ")&&(o=o.includes("<head>")?o.replace("<head>",`<head><base href="${t.baseUrl}">`):o.replace(/(<html[^>]*>)/i,`$1<head><base href="${t.baseUrl}"></head>`));const n=(null==t?void 0:t.customCSS)||"";return n&&o.includes("<head>")?o=o.replace("<head>",`<head><style>${n}</style>`):n&&(o=o.replace(/(<html[^>]*>)/i,`$1<head><style>${n}</style></head>`)),o}sanitizeHtml(e){let t=e.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gim,"");return t=t.replace(/<noscript[\s\S]*?<\/noscript>/gi,""),t}isFullDocument(e){return/^\s*(<html|<!DOCTYPE)/i.test(e)}removeLinks(e){return e.replace(/<a\b[^>]*>([\s\S]*?)<\/a>/gim,"$1")}wrapFragment(e){return`<!DOCTYPE html>\n<html>\n<head>\n <meta charset="utf-8">\n <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'none'; style-src 'unsafe-inline';">\n <style>\n body {\n margin: 0;\n padding: 16px;\n font-family: system-ui, -apple-system, sans-serif;\n white-space: pre-wrap;\n word-wrap: break-word;\n }\n img { max-width: 100%; height: auto; }\n body {\n pointer-events: none;\n user-select: none;\n }\n </style>\n</head>\n<body>\n ${e}\n</body>\n</html>`}}class n extends o{constructor(){super(...arguments),this.name="CHATGPT",this.baseUrl="https://chatgpt.com"}extractContent(e){return this.extractContentCommon(e)}removeLinks(e){return e.replace(/<a\b([^>]*)>/gi,(e,t)=>{const o=t.replace(/\s+href\s*=\s*["'][^"']*["']/gi,"").replace(/\s+alt\s*=\s*["'][^"']*["']/gi,"").replace(/\s+rel\s*=\s*["'][^"']*["']/gi,"").replace(/\s+target\s*=\s*["'][^"']*["']/gi,"").trim();return`<span${o?" "+o:""}>`}).replace(/<\/a>/gi,"</span>")}removeHeader(e){let t=e;return t=t.replace(/<header[^>]*id="page-header"[^>]*>.*?<\/header>/gis,""),t}removeSidebar(e){return e.replace(/<nav[^>]*>.*?<\/nav>/gis,"")}removeFooter(e){return e}removeCookieBanner(e){return e.replace(/<div[^>]*role="dialog"[^>]*>[\s\S]*?openai\.com\/policies\/cookie-policy[\s\S]*?<\/div><\/div><\/div><\/div><\/div><\/div>/gi,"")}removeSources(e){return e}parse(e,t){var o;const{html:n,text:r}=this.extractContent(e);if(!n)throw new Error("No HTML content found in ChatGPT response");let i=n;const s=null!==(o=null==t?void 0:t.removeFooter)&&void 0!==o&&o;i=this.sanitizeHtml(i),i=this.removeCookieBanner(i),(null==t?void 0:t.removeHeader)&&(i=this.removeHeader(i)),(null==t?void 0:t.removeSidebar)&&(i=this.removeSidebar(i)),s&&(i=this.removeFooter(i)),(null==t?void 0:t.removeSources)&&(i=this.removeSources(i)),(null==t?void 0:t.removeLinks)&&(i=this.removeLinks(i));let l="";return(null==t?void 0:t.removeSidebar)&&(l+="\n #stage-slideover-sidebar { display: none !important; }\n [data-sidebar-item] { display: none !important; }\n [data-skip-to-content] { display: none !important; }\n .h-svh { height: auto !important; }\n "),s&&(l+='\n #thread-bottom-container { display: none !important; }\n form[data-type="unified-composer"] { display: none !important; }\n #thread { min-height: auto !important; }\n '),(null==t?void 0:t.removeSources)&&(l+='\n /* Side flyout, the modal sheet that replaces it on narrow pages, and\n the sources dialog of the mobile page */\n [data-testid="stage-thread-flyout"],\n [data-sheet-travel-state],\n #assistant-sources-dialog {\n display: none !important;\n }\n '),i=this.injectStyles(i,{baseUrl:this.baseUrl,customCSS:l}),{provider:this.name,html:i,text:r,metadata:{isFullDocument:this.isFullDocument(i),cookieBannerRemoved:!0,headerRemoved:(null==t?void 0:t.removeHeader)||!1,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,footerRemoved:s,sourcesRemoved:(null==t?void 0:t.removeSources)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class r extends o{constructor(){super(...arguments),this.name="GEMINI",this.baseUrl="https://gemini.google.com"}extractContent(e){return this.extractContentCommon(e,!0)}removeHeader(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*boqOnegoogleliteOgbOneGoogleBar[^"]*"[^>]*>.*?<\/div><\/div><\/div><\/div>/gis,""),t=t.replace(/<top-bar-actions[^>]*>.*?<\/top-bar-actions>/gis,""),t=t.replace(/<div[^>]*class="[^"]*desktop-ogb-buffer[^"]*"[^>]*><\/div>/gis,""),t}removeFooter(e){return e.replace(/<input-container[^>]*>.*?<\/input-container>/gis,"")}removeSidebar(e){return e.replace(/<bard-sidenav[^>]*>.*?<\/bard-sidenav>/gis,"")}removeSources(e){let t=e;return t=t.replace(/<context-sidebar[^>]*>[\s\S]*?<\/context-sidebar>/gi,""),t=t.replace(/<sources-sidebar-button[^>]*>[\s\S]*?<\/sources-sidebar-button>/gi,""),t}parse(e,t){var o,n;const{html:r,text:i,sources:s}=this.extractContent(e);if(!r)throw new Error("No HTML content found in Gemini response");let l=r;const a=null!==(o=null==t?void 0:t.removeHeader)&&void 0!==o&&o,d=null!==(n=null==t?void 0:t.removeFooter)&&void 0!==n&&n;l=this.sanitizeHtml(l),a&&(l=this.removeHeader(l)),d&&(l=this.removeFooter(l)),(null==t?void 0:t.removeSidebar)&&(l=this.removeSidebar(l)),(null==t?void 0:t.removeSources)&&(l=this.removeSources(l)),(null==t?void 0:t.removeLinks)&&(l=this.removeLinks(l));let v="\n sign-in-nudge { display: none !important; }\n ";return a&&(v+="\n .side-nav-menu-button { display: none !important; }\n "),l=this.injectStyles(l,{baseUrl:this.baseUrl,customCSS:v}),{provider:this.name,html:l,text:i,sources:s,metadata:{isFullDocument:this.isFullDocument(l),headerRemoved:a,footerRemoved:d,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,sourcesRemoved:(null==t?void 0:t.removeSources)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class i extends o{constructor(){super(...arguments),this.name="PERPLEXITY",this.baseUrl="https://www.perplexity.ai"}extractContent(e){return this.extractContentCommon(e)}removeHeader(e){return e.replace(/<div[^>]*class="[^"]*@container\/header[^"]*"[^>]*>.*?<div[^>]*class="[^"]*absolute bottom-0 inset-x-0 border-b[^"]*"[^>]*><\/div>/gis,"")}removeFooter(e){return e}removeSidebar(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*w-sideBarWidth[^"]*"[^>]*>[\s\S]*?<\/nav>[\s\S]*?<\/div>/gi,""),t}removeSources(e){return e}parse(e,t){var o,n;const{html:r,text:i}=this.extractContent(e);if(!r)throw new Error("No HTML content found in Perplexity response");let s=r;const l=null!==(o=null==t?void 0:t.removeHeader)&&void 0!==o&&o,a=null!==(n=null==t?void 0:t.removeFooter)&&void 0!==n&&n;s=this.sanitizeHtml(s),s=s.replace(/style="transition: none; overflow: hidden; height: 48px;"/gi,""),s=s.replace(/padding-right:\s*\d+px/gi,"padding-right: 0px"),l&&(s=this.removeHeader(s)),(null==t?void 0:t.removeSidebar)&&(s=this.removeSidebar(s)),a&&(s=this.removeFooter(s)),(null==t?void 0:t.removeSources)&&(s=this.removeSources(s)),(null==t?void 0:t.removeLinks)&&(s=this.removeLinks(s));let d='\n #cookie-consent,\n [role="dialog"]:has(#cookie-consent),\n div[role="dialog"][class*="fixed"][class*="bottom-2"] {\n display: none !important;\n }\n /* Login prompts: the full-page modal and the corner card. The #root\n prefix keeps the rule above the removeSidebar layout overrides. */\n [data-type="portal"]:has([data-testid="login-modal"]),\n #root div[class*="fixed"]:has([data-testid="login-modal"]),\n div[class*="fixed"]:has([data-testid="login-modal"]) {\n display: none !important;\n }\n [data-radix-focus-guard] {\n display: none !important;\n }\n ';return(null==t?void 0:t.removeSidebar)&&(d+='\n [class*="w-sideBarWidth"] { display: none !important; }\n #root, #root > div, #root > div > div {\n display: block !important;\n height: auto !important;\n max-height: none !important;\n width: 100% !important;\n padding: 0 !important;\n }\n main {\n display: block !important;\n height: auto !important;\n max-height: none !important;\n overflow: visible !important;\n }\n main > div {\n height: auto !important;\n overflow: visible !important;\n }\n [class*="scrollable-container"] {\n height: auto !important;\n overflow: visible !important;\n }\n [class*="max-w-threadContentWidth"] {\n max-width: 100% !important;\n }\n '),(null==t?void 0:t.removeSources)&&(d+='\n div[class*="fixed"][class*="inset-y-0"][class*="right-0"],\n [data-radix-popper-content-wrapper] {\n display: none !important;\n }\n '),a&&(d+='\n [class*="bottom-safeAreaInsetBottom"] {\n display: none !important;\n }\n '),s=this.injectStyles(s,{baseUrl:this.baseUrl,customCSS:d}),{provider:this.name,html:s,text:i,metadata:{isFullDocument:this.isFullDocument(s),linksRemoved:(null==t?void 0:t.removeLinks)||!1,headerRemoved:l,footerRemoved:a,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,cookieBannerRemoved:!0,sourcesRemoved:(null==t?void 0:t.removeSources)||!1}}}}class s extends o{constructor(){super(...arguments),this.name="COPILOT",this.baseUrl="https://copilot.microsoft.com"}extractContent(e){return this.extractContentCommon(e)}removeHeader(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*absolute flex end-6 origin-top-right flex-col items-end[^"]*"[^>]*data-testid="settings-wrapper"[^>]*>.*?<\/div><\/div>/gis,""),t}removeFooter(e){let t=e;return t=t.replace(/<div[^>]*class="[^"]*absolute bottom-0 w-full[^"]*"[^>]*>.*?<\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*mt-\[var\(--composer-container-height\)\][^"]*"[^>]*><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*pointer-events-none absolute flex justify-center z-20 inset-x-0 bottom-\[calc\(var\(--composer-container-height\)\+1rem\)\][^"]*"[^>]*>.*?<button[^>]*data-testid="scroll-to-bottom-button"[^>]*>.*?<\/button><\/div>/gis,""),t}removeCookieBanner(e){let t=e;return t=t.replace(/<div[^>]*id="cookie-banner"[^>]*>.*?<\/div>.*?<\/div>.*?<\/div>.*?<\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*max-w-cookie-banner[^"]*"[^>]*>.*?<\/div>.*?<\/div>.*?<\/div>.*?<\/div>/gis,""),t}removeSources(e){return e.replace(/<div[^>]*class="[^"]*relative h-full overflow-hidden will-change-auto[^"]*"[^>]*style="[^"]*width:\s*\d+px[^"]*"[^>]*>[\s\S]*?(?=<div[^>]*class="[^"]*pointer-events-none (?:fixed|absolute)[^"]*")/gi,"")}removeSidebar(e){return e}parse(e,t){var o,n;const{html:r,text:i}=this.extractContent(e);if(!r)throw new Error("No HTML content found in Copilot response");let s=r;const l=null!==(o=null==t?void 0:t.removeHeader)&&void 0!==o&&o,a=null!==(n=null==t?void 0:t.removeFooter)&&void 0!==n&&n;s=this.sanitizeHtml(s),s=this.removeCookieBanner(s),l&&(s=this.removeHeader(s)),a&&(s=this.removeFooter(s)),(null==t?void 0:t.removeSidebar)&&(s=this.removeSidebar(s)),(null==t?void 0:t.removeSources)&&(s=this.removeSources(s)),(null==t?void 0:t.removeLinks)&&(s=this.removeLinks(s));let d="";return l&&(d+='\n [data-testid="sticky-header"],\n [data-testid="backstage-chats"],\n div:has(> div > [data-testid="date-divider"]) {\n display: none !important;\n }\n '),(null==t?void 0:t.removeSidebar)&&(d+="\n div:has(> #sidebar-container) { display: none !important; }\n "),s=this.injectStyles(s,{baseUrl:this.baseUrl,customCSS:d}),{provider:this.name,html:s,text:i,metadata:{isFullDocument:this.isFullDocument(s),cookieBannerRemoved:!0,headerRemoved:l,footerRemoved:a,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,sourcesRemoved:(null==t?void 0:t.removeSources)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class l extends o{constructor(){super(...arguments),this.name="AIOVERVIEW",this.baseUrl="https://www.google.com"}extractContent(e){return this.extractContentCommon(e,!0)}removeHeader(e){return e}removeFooter(e){return e}removeSidebar(e){return e}parse(e,t){var o,n;const{html:r,sources:i}=this.extractContent(e);if(!r)throw new Error("No HTML content found in AI Overview response");let s=r;const l=null===(o=null==t?void 0:t.removeHeader)||void 0===o||o,a=null===(n=null==t?void 0:t.removeFooter)||void 0===n||n;s=this.sanitizeHtml(s),l&&(s=this.removeHeader(s)),a&&(s=this.removeFooter(s)),(null==t?void 0:t.removeSidebar)&&(s=this.removeSidebar(s)),(null==t?void 0:t.removeLinks)&&(s=this.removeLinks(s));let d="";return l&&(d+='\n /* Header hiding */\n header, #header, #searchform, .sfbg, #appbar,\n div[role="navigation"], #leftnav, #sidetogether,\n [role="banner"], .Fgvgjc, #hdtb, .hdtb-msb,\n .DZ13He, .wYq63b, .eT9Cje, .bNg8Rb, .S6VXfe, .Lu57id {\n display: none !important;\n }\n '),(null==t?void 0:t.removeSidebar)&&(d+="\n /* Sidebar hiding */\n #leftnav, #sidetogether {\n display: none !important;\n }\n "),a&&(d+='\n /* Footer hiding */\n footer, #footer, #sfooter, .fbar,\n .pdp-nav, [aria-label="Main menu"], .gb_Td, .gb_L {\n display: none !important;\n }\n '),s=this.injectStyles(s,{baseUrl:this.baseUrl,customCSS:d}),{provider:this.name,html:s,sources:i,metadata:{isFullDocument:this.isFullDocument(s),headerRemoved:l,footerRemoved:a,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class a extends o{constructor(){super(...arguments),this.name="AIMODE",this.baseUrl="https://www.google.com"}extractContent(e){return this.extractContentCommon(e)}removeHeader(e){let t=e;return t=t.replace(/<div[^>]*jsname="oEQ3x"[^>]*class="[^"]*DZ13He[^"]*"[^>]*>.*?<hr class="e9c7U">.*?<\/div><\/div><\/div><\/div><\/div>/gis,""),t}removeFooter(e){let t=e;return t=t.replace(/<div[^>]*data-xid="aim-mars-input-plate"[^>]*>[\s\S]*?<\/div><\/div><\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*jscontroller="P5gZDb"[^>]*>[\s\S]*?<\/div><\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*t0ITR hh3ttd[^"]*"[^>]*>[\s\S]*?<\/div><\/div>/gis,""),t=t.replace(/<div[^>]*class="[^"]*y4VEUd vve6Ce[^"]*"[^>]*>[\s\S]*?<\/div><\/div>/gis,""),t}removeSidebar(e){let t=e;return t=t.replace(/<div[^>]*aria-label="AI Mode history"[^>]*class="[^"]*ho072b[^"]*"[^>]*>[\s\S]*?(?=<!--TgQPHd)/gi,""),t=t.replace(/<div[^>]*class="[^"]*ho072b[^"]*"[^>]*aria-label="AI Mode history"[^>]*>[\s\S]*?(?=<!--TgQPHd)/gi,""),t=t.replace(/<div[^>]*class="[^"]*OEwhSe[^"]*"[^>]*>[\s\S]*?<\/div><\/div>/gis,""),t=t.replace(/<button[^>]*aria-label="AI Mode history"[^>]*>[\s\S]*?<\/button>/gis,""),t}parse(e,t){var o,n;const{html:r,text:i}=this.extractContent(e);if(!r)throw new Error("No HTML content found in AI Mode response");let s=r;const l=null===(o=null==t?void 0:t.removeHeader)||void 0===o||o,a=null===(n=null==t?void 0:t.removeFooter)||void 0===n||n;s=this.sanitizeHtml(s),l&&(s=this.removeHeader(s)),a&&(s=this.removeFooter(s)),(null==t?void 0:t.removeSidebar)&&(s=this.removeSidebar(s)),(null==t?void 0:t.removeLinks)&&(s=this.removeLinks(s));let d="";return d+="\n .KxvlWc, #CXQnmb {\n display: none !important;\n }\n ",l&&(d+='\n /* Header hiding */\n header, #header, #searchform, .sfbg, #appbar,\n div[role="navigation"], #leftnav, #sidetogether,\n [role="banner"], .Fgvgjc, #hdtb, .hdtb-msb,\n .DZ13He, .wYq63b, .eT9Cje, .bNg8Rb, .S6VXfe, .Lu57id,\n .YHsVn, .UTNPFf {\n display: none !important;\n }\n '),a&&(d+='\n /* Footer hiding */\n footer, #footer, .fbar,\n .pdp-nav, [aria-label="Main menu"], .gb_Td, .gb_L {\n display: none !important;\n }\n /* Hide the "Ask anything" input bar */\n [data-xid="aim-mars-input-plate"],\n .UAbVe, .y4VEUd, .t0ITR.hh3ttd {\n display: none !important;\n }\n '),(null==t?void 0:t.removeSidebar)&&(d+="\n /* Hide AI Mode history panel */\n .ho072b, .OEwhSe, .qEn1od {\n display: none !important;\n }\n "),s=this.injectStyles(s,{baseUrl:this.baseUrl,customCSS:d}),{provider:this.name,html:s,text:i,metadata:{isFullDocument:this.isFullDocument(s),headerRemoved:l,footerRemoved:a,sidebarRemoved:(null==t?void 0:t.removeSidebar)||!1,linksRemoved:(null==t?void 0:t.removeLinks)||!1}}}}class d extends o{constructor(){super(...arguments),this.name="GROK",this.baseUrl="https://grok.com"}extractContent(e){return this.extractContentCommon(e)}removeHeader(e){return e}removeFooter(e){return e}parse(e,t){const{html:o,text:n}=this.extractContent(e);if(!o)throw new Error("No HTML content found in Grok response");let r=o;r=this.sanitizeHtml(r);let i="";return i+='\n [data-cookie-banner],\n [data-cookie-banner="true"] {\n display: none !important;\n }\n ',i+='\n [data-sonner-toaster],\n [data-sonner-toast],\n [class*="sonner-toast"] {\n display: none !important;\n }\n ',(null==t?void 0:t.removeSources)&&(r=r.replace(/<div[^>]*class="[^"]*h-dvh[^"]*flex-shrink-0[^"]*max-w-[^"]*"[^>]*>[\s\S]*?<\/aside>[\s\S]*?(?=<section)/gi,""),i+='\n div[data-state] > div.flex.flex-row.gap-1.items-center.rounded-full.cursor-pointer {\n display: none !important;\n }\n [vaul-drawer][vaul-drawer-direction="right"],\n [vaul-overlay] {\n display: none !important;\n }\n '),(null==t?void 0:t.removeHeader)&&(i+='\n /* Header hiding - hide elements with Grok\'s header class pattern */\n div[class*="h-16"][class*="top-0"][class*="z-10"],\n div[class*="absolute"][class*="inset-x-0"][class*="top-0"] {\n display: none !important;\n }\n '),(null==t?void 0:t.removeFooter)&&(i+='\n /* Footer hiding - hide Grok\'s footer/input area */\n div[class*="absolute"][class*="inset-x-0"][class*="bottom-0"][class*="max-w-breakout"],\n div[class*="absolute"][class*="bottom-0"][class*="w-full"] {\n display: none !important;\n }\n '),(null==t?void 0:t.removeLinks)&&(r=this.removeLinks(r)),r=this.injectStyles(r,{baseUrl:this.baseUrl,customCSS:i}),{provider:this.name,html:r,text:n,metadata:{isFullDocument:this.isFullDocument(r),linksRemoved:(null==t?void 0:t.removeLinks)||!1,headerRemoved:(null==t?void 0:t.removeHeader)||!1,footerRemoved:(null==t?void 0:t.removeFooter)||!1,cookieBannerRemoved:!0,sourcesRemoved:(null==t?void 0:t.removeSources)||!1}}}}class v{constructor(){this.providers=new Map,this.providers.set("CHATGPT",new n),this.providers.set("GEMINI",new r),this.providers.set("PERPLEXITY",new i),this.providers.set("COPILOT",new s),this.providers.set("AIOVERVIEW",new l),this.providers.set("AIMODE",new a),this.providers.set("GROK",new d)}parse(e,o){const n=t.detect(e);if(!n)return this.parseGeneric(e);const r=this.providers.get(n.provider);if(!r)return null;try{const t=r.parse(e,o);return{...t,metadata:{...t.metadata,detectionConfidence:n.confidence}}}catch(e){return console.error(`Failed to parse response with ${n.provider}:`,e),null}}parseWithProvider(e,t,o){const n=this.providers.get(t);if(!n)throw new Error(`Unknown provider: ${t}`);try{return n.parse(e,o)}catch(e){return console.error(`Failed to parse response with ${t}:`,e),null}}detectProvider(e){const o=t.detect(e);return(null==o?void 0:o.provider)||null}detectAllProviders(e){return t.getAllProviders(e)}parseGeneric(t){const{html:o,text:n}=e(t);if(!o&&!n)return null;let r=o;return r&&(r=r.replace(/<script\b[^>]*>[\s\S]*?<\/script>/gim,""),r=r.replace(/<noscript[\s\S]*?<\/noscript>/gi,"")),{provider:"CHATGPT",html:r||"",text:n||"",metadata:{isGeneric:!0}}}getSupportedProviders(){return Array.from(this.providers.keys())}registerProvider(e,t){this.providers.set(e,t)}}const c=new v,m=(e,t)=>c.parse(e,t),u=e=>c.detectProvider(e);export{a as AIModeProvider,l as AIOverviewProvider,v as AIResponseParser,o as BaseProvider,n as ChatGPTProvider,s as CopilotProvider,r as GeminiProvider,d as GrokProvider,i as PerplexityProvider,t as ProviderDetector,u as detectProvider,m as parseAiResponse,c as parser};
2
2
  //# sourceMappingURL=index.esm.js.map