A desktop browser with x402 built in: when a page asks for payment, it pays in stablecoins and shows the content.

9 downloads

dbbasic-browser/apps/browser/scripts/build-chrome.mjs
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-browser.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-browser.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-browser.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 toolbar: Back and Forward are greyed out when there's nowhere to go cc08c7a 1 week, 2 days ago History
build-chrome.mjs · 2.9 KB · 53 lines
1#!/usr/bin/env node
2/**
3 * Build dist/chrome.html: src/chrome.html with the loading animations and the toolbar icons inlined.
4 *
5 * The chrome page's CSP forbids loading external files, and both must be real inline <svg> (so `currentColor` and the
6 * --throb-* / --icon-accent variables follow the UI theme). So at build time:
7 * - the SVGs in assets/throbbers/svg/ are embedded as a JS object at the `THROBBERS` marker;
8 * - the SVGs in assets/icons/svg/ are embedded as a JS object at the `ICONS` marker (for icons the page swaps, like
9 * the star), and each `<!--icon:NAME-->` in the markup is replaced by that icon.
10 */
11import { mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
12import { dirname, join } from "node:path";
13import { fileURLToPath } from "node:url";
14
15const root = join(dirname(fileURLToPath(import.meta.url)), "..");
16
17/** name → SVG markup for every plain `name.svg` in a folder (the fixed-colour -dark/-light variants are for <img> use). */
18function readSvgs(dir, tidy) {
19 const out = {};
20 for (const f of readdirSync(dir).sort()) {
21 if (!/^[a-z0-9-]+\.svg$/.test(f) || /-(dark|light)\.svg$/.test(f)) continue;
22 out[f.replace(/\.svg$/, "")] = tidy(readFileSync(join(dir, f), "utf8"));
23 }
24 if (Object.keys(out).length === 0) throw new Error(`no SVGs found in ${dir}`);
25 return out;
26}
27// <title> would add a native tooltip; the aria-label stays for assistive tech.
28const throbbers = readSvgs(join(root, "assets", "throbbers", "svg"), (s) => s.replace(/<title>.*?<\/title>/s, "").trim());
29// An icon sits next to its button's words (or the button has its own aria-label), so it is decoration: hidden from
30// assistive tech, no tooltip of its own.
31const icons = readSvgs(join(root, "assets", "icons", "svg"), (s) =>
32 s.replace(/<title>.*?<\/title>/s, "").replace(/\s*role="img"\s*aria-label="[^"]*"/, ' class="ico" aria-hidden="true" focusable="false"').trim());
33
34// Escape "</" so nothing inside the JSON can ever close the surrounding <script>.
35const asJs = (o) => JSON.stringify(o).replace(/<\//g, "<\\/");
36const inline = (html, marker, o) => {
37 if (!html.includes(marker)) throw new Error(`marker ${marker} not found in src/chrome.html`);
38 return html.replace(marker, () => asJs(o));
39};
40
41let html = readFileSync(join(root, "src", "chrome.html"), "utf8");
42html = inline(html, "/*__THROBBERS__*/ {}", throbbers);
43html = inline(html, "/*__ICONS__*/ {}", icons);
44let placed = 0;
45html = html.replace(/<!--icon:([a-z0-9-]+)-->/g, (_, name) => {
46 if (!icons[name]) throw new Error(`<!--icon:${name}--> in src/chrome.html, but there is no assets/icons/svg/${name}.svg`);
47 placed++;
48 return icons[name];
49});
50
51mkdirSync(join(root, "dist"), { recursive: true });
52writeFileSync(join(root, "dist", "chrome.html"), html);
53console.log(`chrome.html: inlined ${Object.keys(throbbers).length} throbbers and ${Object.keys(icons).length} icons (${placed} placed in the toolbar)`);