@profullstack/waitlist 0.8.0 → 0.10.0

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
@@ -83,10 +83,14 @@ Attributes: `dn` (the list; defaults to the page's host), `api` (default
83
83
  Any server with these two routes works (moshcoding.com runs them: double opt-in email,
84
84
  a list per domain in the owner's dashboard, `waitlist.signup` domain webhooks):
85
85
 
86
- - `POST /api/waitlist` `{ email, dn, ref? }` -> `{ ok, pending, already }` or `{ error }`
86
+ - `POST /api/waitlist` `{ email, dn, ref?, site?, bump? }` -> `{ ok, pending, already, referral? }` or `{ error }`;
87
+ `referral` is `{ code, link, position, total, referrals, bump }`
87
88
  - `GET /api/waitlist/stats?dn=&days=` -> `{ total, verified, days: [{ day, n }] }` (counts only)
89
+ - `GET /api/waitlist/referrals/leaderboard?dn=&limit=` -> `{ dn, updatedAt, entries: [{ rank, name, handle, referrals }] }`
90
+ (names are chosen handles or masked emails)
88
91
 
89
- Both send `Access-Control-Allow-Origin: *`.
92
+ All send `Access-Control-Allow-Origin: *`. A launch page is static, so the leaderboard
93
+ endpoint lives on the API host, not on the page's own host.
90
94
 
91
95
  MIT
92
96
 
@@ -116,7 +120,7 @@ The page reports one exposure a day; a signup is the conversion. Both go through
116
120
  waitlist API, which holds the CrawlProof token. Stop the experiment with a winner in
117
121
  CrawlProof and every page switches to it. Turn it off per site with `"ab": false`.
118
122
 
119
- ## Plugins (0.4; buyaday 0.6; book + promo 0.7)
123
+ ## Plugins (0.4; buyaday 0.6; book + promo 0.7; affiliate 0.9)
120
124
 
121
125
  Every page showcases all plugins by default. Pick per site in `sites.json`:
122
126
  `"plugins": ["form", "board"]` keeps only those, `"plugins": { "faq": false }` drops some.
@@ -135,6 +139,30 @@ Every page showcases all plugins by default. Pick per site in `sites.json`:
135
139
  | `buyaday` | `<pf-buy-a-day>` from [@profullstack/marketing-widgets](https://github.com/profullstack/marketing-widgets): the next free doors on [holi.days](https://holi.days.pit.world/calendars) calendars (ones matching the site's keywords first), baked in and refreshed live, every sale credited to this site with `?ref=<host>`. Nothing shows when the feed is down. `buyadayKeywords` / `buyadayLimit` in `sites.json` override the keywords and count (default 3) |
136
140
  | `book` | The Profullstack pitch (four solution lines) and `<book-a-call>`, our booking widget: open times from the OutreachGraph public calendar in the reader's own time zone, booked inline as a PairUX call. A plain link to the booking page without script. `"booking": {"handle": "chovy"}` picks the calendar |
137
141
  | `promo` | "More from the network": sister properties from the live `@profullstack/cross-promo` catalog, tagged `utm_medium=waitlist`. `"promoAudience": "developers"` (or a list) overrides the audience picked from the hierarchy |
142
+ | (search, resources) | Every search item and resource carries pit.world's result tools from `https://pit.world/widgets.js`: vote, Summarize, Listen and Share. They work without an account; on a pit.world host, "Sign in with CoinPay" (OAuth 2.1 + PKCE through pit.world) raises the limits. From a terminal the same account is `pit login` |
143
+ | `affiliate` | Referrals (0.9). Every signup gets a personal link `https://<site>/?ref=<code>`, shown right after joining by `<pf-referral-share>` ("You are #X of Y, N people referred.", copy button, plain X/Bluesky/LinkedIn/email links) and in the confirmation email with a signed status page. A visitor who arrives with `?ref=` keeps a 30-day first-party, first-touch cookie `wl_ref`; their signup credits the referrer once they confirm. Each confirmed referral moves the referrer up `bumpPlaces`. A "Move up the list" section bakes `<pf-referral-leaderboard>` (handles or masked emails only). With `buyaday` on, a door sold to a referred visitor credits the referrer too (holi.days `ref=<code>.<site>`). See below |
144
+
145
+ ### Referrals (`affiliate`)
146
+
147
+ ```json
148
+ { "name": "comp.lang", "affiliate": { "enabled": true, "bumpPlaces": 3, "leaderboard": true, "leaderboardLimit": 10 } }
149
+ ```
150
+
151
+ All keys are optional (shown with their defaults); `"affiliate": { "enabled": false }` or
152
+ `"plugins": { "affiliate": false }` turns it off. The rules live on the API (moshcoding.com):
153
+ no self-referral (same normalized email: case, `+tags`, Gmail dots), one credit per referred
154
+ person per list, only confirmed signups count, at most 3 credited signups per hashed IP per
155
+ list per day (IPs are HMAC'd, never stored). Nothing here pays or promises money.
156
+
157
+ Snippet for any page on the same API:
158
+
159
+ ```html
160
+ <waitlist-form dn="comp.lang" bump="3"></waitlist-form>
161
+ <pf-referral-share bump="3"></pf-referral-share>
162
+ <pf-referral-leaderboard dn="comp.lang"></pf-referral-leaderboard>
163
+ <script type="module" src="https://cdn.jsdelivr.net/npm/@profullstack/waitlist/src/index.js"></script>
164
+ <script type="module" src="https://cdn.jsdelivr.net/npm/@profullstack/marketing-widgets/src/widgets.js"></script>
165
+ ```
138
166
 
139
167
  `keywords` (also the `<meta name="keywords">`) default to the name's labels plus the tagline's
140
168
  meaningful words; set `keywords` or `resourcesQuery` per site to steer the resources.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profullstack/waitlist",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Email waitlist for any launch page: a <waitlist-form> web component, a live signup chart, and a static-site builder on @profullstack/css + @profullstack/charts.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -51,7 +51,7 @@
51
51
  "@profullstack/footer": "^0.7.3",
52
52
  "@resvg/resvg-js": "^2.6.2",
53
53
  "@profullstack/comments": "^0.2.0",
54
- "@profullstack/marketing-widgets": "^0.1.0",
54
+ "@profullstack/marketing-widgets": "^0.2.0",
55
55
  "@profullstack/cross-promo": "^0.2.1"
56
56
  },
57
57
  "devDependencies": {
package/src/build.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * for one name, ready for `c0mpute hosting publish <dir> --name <site>`.
4
4
  */
5
5
  import { mkdir, writeFile, copyFile, readFile, readdir } from 'node:fs/promises';
6
- import { pluginSet, keywordsFor, runPlugins, baseSlot } from './plugins.js';
6
+ import { pluginSet, keywordsFor, runPlugins, baseSlot, affiliateConfig } from './plugins.js';
7
7
  import {
8
8
  TABS, SORTS, tabPath, searchPageHtml, searchPageMeta, searchJson, searchLlms, manifestJson,
9
9
  openSearchXml, serviceWorker, maskableIconSvg,
@@ -114,6 +114,7 @@ export function normalize(spec) {
114
114
  marquee: spec.marquee || `Welcome to ${name}! You are visitor #000${(name.length * 7919) % 9000 + 1000}. Sign the waitlist below!`,
115
115
  crawlproof: spec.crawlproof === undefined ? (moshpit ? MOSHPIT_STATS_SITE : null) : spec.crawlproof,
116
116
  plugins: pluginSet(spec.plugins),
117
+ affiliate: affiliateConfig(spec.affiliate),
117
118
  ab: spec.ab === false ? null : { ...DEFAULT_AB, ...(spec.ab || {}) },
118
119
  lang: spec.lang || 'en',
119
120
  locale: spec.locale || 'en_US',
@@ -137,6 +138,7 @@ export function normalize(spec) {
137
138
  s.summary = spec.summary || d.summary;
138
139
  s.imageAlt = spec.imageAlt || d.imageAlt;
139
140
  if (!s.plugins.has('ab')) s.ab = null;
141
+ if (!s.affiliate.enabled) s.plugins.delete('affiliate');
140
142
  if (!s.keywords.length) s.keywords = keywordsFor(s);
141
143
  s.resourcesQuery = spec.resourcesQuery || '';
142
144
  s.searchQuery = spec.searchQuery || '';
package/src/index.js CHANGED
@@ -31,6 +31,29 @@ export function refFrom(href) {
31
31
  }
32
32
  }
33
33
 
34
+ /** The first-party cookie that remembers a referral code (first touch, 30 days). */
35
+ export const REF_COOKIE = 'wl_ref';
36
+
37
+ /** A referral code from a cookie string, or null. */
38
+ export function refFromCookie(cookie) {
39
+ const m = String(cookie ?? '').match(/(?:^|;\s*)wl_ref=([A-Za-z0-9]{6,16})(?:;|$)/);
40
+ return m ? m[1].toLowerCase() : null;
41
+ }
42
+
43
+ /**
44
+ * The referral code in force for this visit: a first-touch cookie wins; else
45
+ * ?ref= on this URL, which is then remembered for 30 days. Null without either.
46
+ */
47
+ export function captureRef(doc = globalThis.document, href = globalThis.location?.href) {
48
+ const kept = refFromCookie(doc?.cookie);
49
+ if (kept) return kept;
50
+ const ref = href ? refFrom(href) : null;
51
+ if (ref && doc && /^[A-Za-z0-9]{6,16}$/.test(ref)) {
52
+ doc.cookie = `${REF_COOKIE}=${ref.toLowerCase()}; Max-Age=${30 * 86400}; Path=/; SameSite=Lax${String(href).startsWith('https:') ? '; Secure' : ''}`;
53
+ }
54
+ return ref;
55
+ }
56
+
34
57
  /** The message to show for an API answer. */
35
58
  export function messageFor(res, email) {
36
59
  if (res && res.ok) {
@@ -72,14 +95,23 @@ export async function reportExposure({ api = DEFAULT_API, dn, fetchImpl = global
72
95
  }
73
96
  }
74
97
 
75
- export async function join({ email, dn, ref = null, api = DEFAULT_API, fetchImpl = globalThis.fetch, ab = abContext() }) {
98
+ /**
99
+ * POST one signup. `site` is this page's origin (so the referral link points at the
100
+ * host people reach, e.g. the pit.world relay) and `bump` the places one confirmed
101
+ * referral is worth on this site. The answer carries `referral` when the API has it.
102
+ */
103
+ export async function join({ email, dn, ref = null, api = DEFAULT_API, fetchImpl = globalThis.fetch, ab = abContext(), site = null, bump = null }) {
76
104
  const clean = cleanEmail(email);
77
105
  if (!clean) return { ok: false, status: 400, error: "That doesn't look like an email." };
106
+ const payload = { email: clean, dn, ref };
107
+ if (site) payload.site = site;
108
+ if (bump !== null && bump !== undefined && bump !== '') payload.bump = Number(bump);
109
+ if (ab) payload.ab = ab;
78
110
  try {
79
111
  const res = await fetchImpl(new URL('/api/waitlist', api).href, {
80
112
  method: 'POST',
81
113
  headers: { 'content-type': 'application/json' },
82
- body: JSON.stringify(ab ? { email: clean, dn, ref, ab } : { email: clean, dn, ref }),
114
+ body: JSON.stringify(payload),
83
115
  });
84
116
  const body = await res.json().catch(() => ({}));
85
117
  return { ...body, ok: Boolean(res.ok && body.ok), status: res.status };
@@ -110,6 +142,7 @@ export class WaitlistForm extends HTMLElementBase {
110
142
  if (this.dataset.ready) return;
111
143
  this.dataset.ready = '1';
112
144
  reportExposure({ api: this.getAttribute('api') || DEFAULT_API, dn: this.getAttribute('dn') || location.hostname });
145
+ captureRef();
113
146
  const id = `wl-${Math.random().toString(36).slice(2, 8)}`;
114
147
  this.innerHTML = `
115
148
  <form class="stack waitlist-form" novalidate>
@@ -140,8 +173,10 @@ export class WaitlistForm extends HTMLElementBase {
140
173
  const res = await join({
141
174
  email,
142
175
  dn: this.getAttribute('dn') || location.hostname,
143
- ref: refFrom(location.href),
176
+ ref: captureRef(),
144
177
  api: this.getAttribute('api') || DEFAULT_API,
178
+ site: location.origin,
179
+ bump: this.getAttribute('bump'),
145
180
  });
146
181
  say(messageFor(res, email));
147
182
  button.disabled = false;
package/src/plugins.js CHANGED
@@ -12,6 +12,8 @@
12
12
  * calendar, PairUX call). `"booking": {"handle": "chovy"}` picks the calendar.
13
13
  * promo "More from the network": sister properties from @profullstack/cross-promo.
14
14
  * `"promoAudience": "developers"` (or a list) picks who the reader is.
15
+ * affiliate referral links, place bumps and a leaderboard (`"affiliate": {...}`, see
16
+ * affiliateConfig); door sales credit the referrer when buyaday is on.
15
17
  */
16
18
  import { mkdir, readFile, writeFile, copyFile } from 'node:fs/promises';
17
19
  import { createRequire } from 'node:module';
@@ -22,7 +24,7 @@ import { fetchSearch, searchCardHtml } from './search.js';
22
24
 
23
25
  const require = createRequire(import.meta.url);
24
26
 
25
- export const PLUGINS = ['form', 'stats', 'ab', 'faq', 'search', 'resources', 'board', 'share', 'feed', 'buyaday', 'book', 'promo'];
27
+ export const PLUGINS = ['form', 'stats', 'ab', 'faq', 'search', 'resources', 'board', 'share', 'feed', 'buyaday', 'book', 'promo', 'affiliate'];
26
28
 
27
29
  /** Resolve a site's `plugins` setting to a Set (default: all of them). */
28
30
  export function pluginSet(setting) {
@@ -32,6 +34,53 @@ export function pluginSet(setting) {
32
34
  return on;
33
35
  }
34
36
 
37
+ /**
38
+ * The `affiliate` plugin's settings from sites.json:
39
+ *
40
+ * "affiliate": { "enabled": true, "bumpPlaces": 3, "leaderboard": true, "leaderboardLimit": 10 }
41
+ *
42
+ * bumpPlaces is how many places one confirmed referral moves someone up (0..50).
43
+ */
44
+ export function affiliateConfig(raw) {
45
+ const a = raw && typeof raw === 'object' ? raw : {};
46
+ const int = (v, d, lo, hi) => (Number.isFinite(Number(v)) && v !== null && v !== '' ? Math.min(Math.max(Math.floor(Number(v)), lo), hi) : d);
47
+ return {
48
+ enabled: raw === false ? false : a.enabled !== false,
49
+ bumpPlaces: int(a.bumpPlaces, 3, 0, 50),
50
+ leaderboard: a.leaderboard !== false,
51
+ leaderboardLimit: int(a.leaderboardLimit, 10, 1, 100),
52
+ };
53
+ }
54
+
55
+ /**
56
+ * Copy the @profullstack/marketing-widgets browser files FLAT into assets/ (as
57
+ * mw-widgets.js + mw-core.js: versionAssets reads assets/ and would EISDIR on a
58
+ * subfolder, and assets/core.js is already the comments package's). Once per build.
59
+ */
60
+ async function copyMarketingWidgets(mw, out, slot) {
61
+ if (slot._mw) return;
62
+ slot._mw = true;
63
+ const core = await readFile(mw.assetPath.core, 'utf8');
64
+ const widgets = (await readFile(mw.assetPath.widgets, 'utf8')).replace(/from '\.\/core\.js'/, "from './mw-core.js'");
65
+ await writeFile(join(out, 'assets', 'mw-core.js'), core);
66
+ await writeFile(join(out, 'assets', 'mw-widgets.js'), widgets);
67
+ slot.scripts.push('<script type="module" src="assets/mw-widgets.js"></script>');
68
+ }
69
+
70
+ /** The affiliate section: how referrals work, then the top referrers (baked, refreshed live). */
71
+ export async function affiliateHtml(s, { fetchImpl } = {}) {
72
+ const a = s.affiliate;
73
+ const mw = await import('@profullstack/marketing-widgets');
74
+ const how = a.bumpPlaces > 0
75
+ ? `Everyone who joins gets a personal link. Each friend who joins through yours and confirms their email moves you up ${a.bumpPlaces} ${a.bumpPlaces === 1 ? 'place' : 'places'}.`
76
+ : 'Everyone who joins gets a personal link. Friends who join through yours and confirm their email put you on the board.';
77
+ const board = a.leaderboard ? await mw.referralLeaderboardHtml({ dn: s.dn, api: s.api, limit: a.leaderboardLimit, fetchImpl }) : '';
78
+ return `<section class="stack waitlist-affiliate" aria-labelledby="referrals"><h2 id="referrals">Move up the list</h2>
79
+ <p>${esc(how)}</p>
80
+ ${board}
81
+ </section>`;
82
+ }
83
+
35
84
  const STOP = new Set('a an and are as at be by for from has have in into is it its of on or that the this to was we with you your our not yet will one all any get it\'s now new site'.split(' '));
36
85
 
37
86
  /** Keywords for a site: its own list, else the name's labels and the tagline's meaningful words. */
@@ -82,7 +131,7 @@ export function resourcesHtml(s, res, { comments = false, share = false } = {})
82
131
  if (!res?.results?.length) return '';
83
132
  return `<section class="stack" aria-labelledby="resources"><h2 id="resources">Resources</h2>
84
133
  <p class="muted">Useful reading on ${esc(s.title)} while you wait, from <a href="https://pit.world/search?q=${encodeURIComponent(res.query)}">pit.world search</a>.</p>
85
- <ul role="list" class="grid" data-columns="2">${res.results.map((r) => `<li class="card stack" data-space="sm"><a href="${esc(r.url)}" rel="noopener"><strong>${esc(r.title)}</strong></a><small class="muted">${esc(r.host)}</small>${r.summary ? `<p>${esc(r.summary)}</p>` : ''}${thread(r)}</li>`).join('')}</ul>
134
+ <ul role="list" class="grid" data-columns="2">${res.results.map((r) => `<li class="card stack" data-space="sm" data-pit-result data-url="${esc(r.url)}" data-title="${esc(r.title)}" data-host="${esc(r.host)}" data-q="${esc(res.query)}" data-tab="web"><a href="${esc(r.url)}" rel="noopener"><strong>${esc(r.title)}</strong></a><small class="muted">${esc(r.host)}</small>${r.summary ? `<p>${esc(r.summary)}</p>` : ''}${thread(r)}</li>`).join('')}</ul>
86
135
  </section>`;
87
136
  }
88
137
 
@@ -102,10 +151,13 @@ export function baseSlot(s) {
102
151
  const on = s.plugins || pluginSet();
103
152
  const slot = { head: [], hero: [], cards: [], sections: [], scripts: [] };
104
153
  if (on.has('form')) {
105
- slot.hero.push(`<waitlist-form dn="${esc(s.dn)}" api="${esc(s.api)}" button="${esc(s.button)}">
154
+ const aff = on.has('affiliate') && s.affiliate;
155
+ slot.hero.push(`<waitlist-form dn="${esc(s.dn)}" api="${esc(s.api)}" button="${esc(s.button)}"${aff ? ` bump="${aff.bumpPlaces}"` : ''}>
106
156
  <form class="stack" method="post" action="${esc(s.api)}/api/waitlist"><label for="wl-email">Email</label>
107
157
  <div class="field-group"><input id="wl-email" name="email" type="email" autocomplete="email" required><button type="submit">${esc(s.button)}</button></div></form>
108
158
  </waitlist-form>`);
159
+ // Shown after a signup: place on the list, personal link, copy + share links.
160
+ if (aff) slot.hero.push(`<pf-referral-share bump="${aff.bumpPlaces}"></pf-referral-share>`);
109
161
  }
110
162
  if (on.has('stats')) {
111
163
  slot.cards.push(`<section class="card stack" aria-labelledby="count"><h2 id="count">Who's waiting</h2>
@@ -132,6 +184,8 @@ export async function runPlugins(s, out, { fetchImpl, cacheDir, maxAgeMs, search
132
184
  : await fetchResources(s, { fetchImpl, cacheDir, maxAgeMs });
133
185
  slot.sections.push(resourcesHtml(s, res, { comments: on.has('board'), share: on.has('share') }));
134
186
  if (res.results.length) await writeFile(join(out, 'resources.json'), JSON.stringify(res, null, 2) + '\n');
187
+ // pit.world's own tools under each resource: vote, Summarize, Listen (https://pit.world/widgets.js).
188
+ if (res.results.length) slot.scripts.push('<script type="module" src="https://pit.world/widgets.js"></script>');
135
189
  }
136
190
  if (on.has('board')) {
137
191
  const dir = dirname(require.resolve('@profullstack/comments'));
@@ -145,17 +199,22 @@ export async function runPlugins(s, out, { fetchImpl, cacheDir, maxAgeMs, search
145
199
  // @profullstack/marketing-widgets: sell holi.days doors, credited to this site.
146
200
  // Offers are baked in (no script needed, crawlers read them); the copied script
147
201
  // refreshes them live so taken doors drop off. An empty feed renders nothing.
202
+ // With affiliate on, a door sold to a referred visitor credits the referrer too
203
+ // (holi.days ref = <code>.<site>, from ?ref or the wl_ref cookie).
148
204
  const mw = await import('@profullstack/marketing-widgets');
149
- const html = await mw.buyADayHtml({ ref: s.host, keywords: s.buyadayKeywords || keywordsFor(s), limit: s.buyadayLimit || 3, fetchImpl });
205
+ const html = await mw.buyADayHtml({ ref: s.host, keywords: s.buyadayKeywords || keywordsFor(s), limit: s.buyadayLimit || 3, fetchImpl, referrerCookie: on.has('affiliate') });
150
206
  if (html.includes('pf-mw-offer')) {
151
- const core = await readFile(mw.assetPath.core, 'utf8');
152
- const widgets = (await readFile(mw.assetPath.widgets, 'utf8')).replace(/from '\.\/core\.js'/, "from './mw-core.js'");
153
- await writeFile(join(out, 'assets', 'mw-core.js'), core);
154
- await writeFile(join(out, 'assets', 'mw-widgets.js'), widgets);
207
+ await copyMarketingWidgets(mw, out, slot);
155
208
  slot.sections.push(`<section class="stack" aria-label="Buy a day">${html}</section>`);
156
- slot.scripts.push('<script type="module" src="assets/mw-widgets.js"></script>');
157
209
  }
158
210
  }
211
+ if (on.has('affiliate')) {
212
+ // Referral links, place bumps and a leaderboard (@profullstack/marketing-widgets
213
+ // on moshcoding's /api/waitlist/referrals/*). The share panel sits under the form.
214
+ const mw = await import('@profullstack/marketing-widgets');
215
+ await copyMarketingWidgets(mw, out, slot);
216
+ slot.sections.push(await affiliateHtml(s, { fetchImpl }));
217
+ }
159
218
  if (on.has('book')) {
160
219
  await copyFile(join(dirname(new URL(import.meta.url).pathname), 'book.js'), join(out, 'assets', 'book.js'));
161
220
  slot.sections.push(bookHtml(s));
package/src/search.js CHANGED
@@ -91,6 +91,8 @@ export function normalizeHit(x) {
91
91
  channel: str(x.channel, 80),
92
92
  author: str(x.author, 160),
93
93
  extra: str(x.extra, 80),
94
+ // pit.world's signed Share link for this hit (its own page there).
95
+ share: typeof x.share === 'string' && x.share.startsWith('https://pit.world/share?') ? x.share : undefined,
94
96
  };
95
97
  for (const k of Object.keys(hit)) if (hit[k] === undefined) delete hit[k];
96
98
  return hit;
@@ -219,14 +221,26 @@ function fmtDate(h) {
219
221
  return /^\d{4}$/.test(h.date) ? h.date : new Date(t).toISOString().slice(0, 10);
220
222
  }
221
223
 
222
- function hitHtml(h, tab, v) {
224
+ /** The script that draws pit.world's tools (vote, Summarize, Listen, Share) under every marked result. */
225
+ export const TOOLS_SCRIPT = '<script type="module" src="https://pit.world/widgets.js"></script>';
226
+
227
+ /**
228
+ * Marks a result for pit.world's tools (https://pit.world/widgets.js). They work without an
229
+ * account; signing in with CoinPay (OAuth 2.1) on a pit.world host raises the limits.
230
+ */
231
+ export function toolAttrs(h, { q = '', tab = 'web', tools = '' } = {}) {
232
+ return ` data-pit-result data-url="${esc(h.url)}" data-title="${esc(h.title)}" data-host="${esc(h.host)}" data-q="${esc(q)}" data-tab="${esc(tab)}"${h.share ? ` data-share="${esc(h.share)}"` : ''}${tools ? ` data-tools="${esc(tools)}"` : ''}`;
233
+ }
234
+
235
+ function hitHtml(h, tab, v, q = '') {
223
236
  const meta = [h.host, h.author, h.channel, fmtDate(h), h.duration, h.extra].filter(Boolean).map(esc).join(' · ');
224
- const voted = v ? ` <span class="badge" title="pit.world votes">▲ ${v.up - v.down}</span>` : '';
237
+ // Without script the count stands alone; with it, the vote buttons carry the live count.
238
+ const voted = v ? `<noscript> <span class="badge" title="pit.world votes">▲ ${v.up - v.down}</span></noscript>` : '';
225
239
  if (tab === 'images') {
226
- return `<li class="card wl-hit wl-hit-image"><a href="${esc(h.url)}" rel="noopener">${h.thumbnail ? `<img src="${esc(h.thumbnail)}" alt="${esc(h.title)}" loading="lazy" decoding="async" referrerpolicy="no-referrer">` : ''}<span>${esc(h.title)}</span></a><small class="muted">${esc(h.host)}</small></li>`;
240
+ return `<li class="card wl-hit wl-hit-image"${toolAttrs(h, { q, tab, tools: 'vote share' })}><a href="${esc(h.url)}" rel="noopener">${h.thumbnail ? `<img src="${esc(h.thumbnail)}" alt="${esc(h.title)}" loading="lazy" decoding="async" referrerpolicy="no-referrer">` : ''}<span>${esc(h.title)}</span></a><small class="muted">${esc(h.host)}</small></li>`;
227
241
  }
228
242
  const thumb = h.thumbnail ? `<img class="wl-thumb" src="${esc(h.thumbnail)}" alt="" loading="lazy" decoding="async" referrerpolicy="no-referrer" width="96" height="96">` : '';
229
- return `<li class="card wl-hit">${thumb}<div class="stack" data-space="xs"><a href="${esc(h.url)}" rel="noopener"><strong>${esc(h.title)}</strong></a>${voted}<small class="muted">${meta}</small>${h.summary ? `<p>${esc(h.summary)}</p>` : ''}</div></li>`;
243
+ return `<li class="card wl-hit"${toolAttrs(h, { q, tab })}>${thumb}<div class="stack" data-space="xs" data-pit-tools><a href="${esc(h.url)}" rel="noopener"><strong>${esc(h.title)}</strong></a>${voted}<small class="muted">${meta}</small>${h.summary ? `<p>${esc(h.summary)}</p>` : ''}</div></li>`;
230
244
  }
231
245
 
232
246
  /** The SEO fields of one search page. */
@@ -306,9 +320,11 @@ export function searchPageHtml(s, search, tabId, sort, { chrome }) {
306
320
  <nav class="wl-tabs" aria-label="Search tabs"><ul role="list">${tabs}</ul></nav>
307
321
  <nav class="wl-sorts" aria-label="Sort"><ul role="list">${sorts}</ul></nav>
308
322
  <section aria-labelledby="results" class="stack"><h2 id="results" class="visually-hidden">${esc(tabMeta.label)} results</h2>
309
- <ol role="list" class="wl-results${tabId === 'images' ? ' wl-results-images' : ''}">${hits.map((h) => hitHtml(h, tabId, search.votes.get(h.url))).join('')}</ol>
323
+ <ol role="list" class="wl-results${tabId === 'images' ? ' wl-results-images' : ''}">${hits.map((h) => hitHtml(h, tabId, search.votes.get(h.url), data.query)).join('')}</ol>
324
+ <p data-pit-account></p>
310
325
  <p class="muted">Results from <a href="https://pit.world/search?q=${encodeURIComponent(data.query)}${tabId === 'web' ? '' : `&amp;t=${tabId}`}">pit.world search</a>${data.provider ? ` (${esc(data.provider)})` : ''}, updated ${esc(data.fetchedAt.slice(0, 10))}.</p>
311
- </section>`;
326
+ </section>
327
+ ${TOOLS_SCRIPT}`;
312
328
  return { html: rebase(chrome({ head, body, spec: ps }), up), path: tabPath(tabId, sort), meta: m };
313
329
  }
314
330