import { html } from "./static"; function escapeHtml(value: string): string { return value.replace(/[&<>"']/g, (char) => `${char.charCodeAt(0)};`); } /** Copies the claim token from the URL fragment into the form, then drops it from the address bar. */ const CLAIM_SCRIPT = `var m=/(?:^#|&)token=([^&]*)/.exec(location.hash);if(m){document.getElementById("token").value=decodeURIComponent(m[1]);history.replaceState(null,"",location.pathname)}`; export function claimPage(viewerName: string, legacyToken: string, nonce: string): Response { return html( 200, `
Claiming moves this scratch site to @${escapeHtml(viewerName)}, removes its expiry and gives it a new address.
`, { "content-security-policy": `default-src 'none'; style-src 'unsafe-inline'; script-src 'nonce-${nonce}'; form-action 'self'; frame-ancestors 'none'`, "referrer-policy": "no-referrer", }, ); }