$ show tosdr/browser-extensions
This repository contains the ToS;DR browser extension (Manifest V3) for Chrome, Firefox, and Edge. It downloads a local database of website service ratings from the ToS;DR API, then detects which service a visited domain corresponds to by progressively reducing the hostname. When a match is found, it updates the toolbar icon with the service's grade (A–E) and enables the popup to show detailed summaries of terms-of-service points. The popup also fetches live service details from the API if needed. The codebase is written entirely in TypeScript with strict type checking, uses Vite for building, and includes CI/CD workflows for linting, type-checking, and creating release artifacts. The architecture is a standard single-page browser extension with a background script (or background page for Firefox), popup UI, and settings page. No test suite is present, but the code is well-organized and modular.
The LLM identified 3 files worth highlighting for reuse:
Provides a pure function `findServiceMatch(hostname, db)` that takes a hostname and a database array of services, strips the www prefix, progressively reduces subdomains up to a configurable limit, and returns the first matching service. The helper functions `stripWwwPrefix`, `reduceDomain`, and `lookupDomain` are isolated and could be reused in any project that needs to match a domain against a list of known domains.
A thin, clean abstraction over `chrome.storage.local.get` and `set`, converting callback-based APIs to Promise-based functions. It is fully self-contained (only depends on the global `chrome` object) and can be extracted as a reusable utility for any Chrome extension that needs simplified local storage access.
Contains functions to normalize language codes (handling region suffixes), detect the browser's preferred language from `navigator.languages`/`navigator.language`, and resolve a candidate value to a supported language. It is a self-contained utility with no internal imports beyond constants, and could be reused in any web application that needs language detection and normalization.