Download extension/src/content.ts from Gaurav711/HyperFlow: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/Gaurav711/HyperFlow/resolve/main/extension/src/content.ts
- Command line
-
hf download hf://spaces/Gaurav711/HyperFlow/extension/src/content.ts
-
curl -L -o content.ts https://huggingface.co/spaces/Gaurav711/HyperFlow/resolve/main/extension/src/content.ts
1.05 kB
| // Runs on supported store pages. Reads only the page the user opened and sends parsed, validated | |
| // data to the extension worker; it never makes network requests. | |
| import { PARSERS, storeForUrl } from './parsers'; | |
| async function sha256(text: string): Promise<string> { | |
| const bytes = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(text))); | |
| return [...bytes].map((b) => b.toString(16).padStart(2, '0')).join(''); | |
| } | |
| async function capture(): Promise<void> { | |
| const store = storeForUrl(new URL(location.href)); | |
| if (!store) return; | |
| const parser = PARSERS[store]; | |
| const now = new Date(); | |
| const locationKey = await sha256(store + '|' + (parser.deliveryArea(document) ?? 'unknown')); | |
| const prices = parser.parseSeen(document, locationKey, now); | |
| if (prices.length) await chrome.runtime.sendMessage({ type: 'seen', prices }); | |
| if (/\/(cart|checkout)/.test(location.pathname)) { | |
| await chrome.runtime.sendMessage({ type: 'cart', cart: parser.parseCart(document, now), locationKey }); | |
| } | |
| } | |
| void capture(); | |