atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
e76ab808e7ad49d0b6fccd17728da137daacdb8c
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git

Blame: src/ui.html

99524cf9f17catagen2026-10-10 10:53 UTC1
<!DOCTYPE html>
99524cf9f17catagen2026-10-10 10:53 UTC2
<html>
99524cf9f17catagen2026-10-10 10:53 UTC3
<head>
99524cf9f17catagen2026-10-10 10:53 UTC4
<meta charset="utf-8">
99524cf9f17catagen2026-10-10 10:53 UTC5
<title>jelqd</title>
185851447cebatagen2026-10-10 12:58 UTC6
<style>
185851447cebatagen2026-10-10 12:58 UTC7
.frame { border: 2px inset; background: #fff; height: 85vh; overflow: scroll; padding: 4px; }
185851447cebatagen2026-10-10 12:58 UTC8
#log { white-space: pre-wrap; margin: 0; }
185851447cebatagen2026-10-10 12:58 UTC9
pre, li, p, td, label { overflow-wrap: anywhere; }
185851447cebatagen2026-10-10 12:58 UTC10
</style>
99524cf9f17catagen2026-10-10 10:53 UTC11
</head>
99524cf9f17catagen2026-10-10 10:53 UTC12
<body>
99524cf9f17catagen2026-10-10 10:53 UTC13
185851447cebatagen2026-10-10 12:58 UTC14
<h1>jelqd</h1>
ef7d6dee5976atagen2026-10-10 13:23 UTC15
<p>A roguelike played over HTTP. Pick a resource, pick a method, send it. The log on the right is everything the server has said to you.
ef7d6dee5976atagen2026-10-10 13:23 UTC16
Language <select id="locale"><option>en-GB</option><option>en-US</option><option>en-AU</option></select></p>
185851447cebatagen2026-10-10 12:58 UTC17
185851447cebatagen2026-10-10 12:58 UTC18
<table width="100%" cellspacing="6">
185851447cebatagen2026-10-10 12:58 UTC19
<tr>
185851447cebatagen2026-10-10 12:58 UTC20
<td width="45%" valign="top">
185851447cebatagen2026-10-10 12:58 UTC21
<div class="frame">
185851447cebatagen2026-10-10 12:58 UTC22
431c1bc8ded1atagen2026-10-10 13:20 UTC23
<div id="alerts"></div>
431c1bc8ded1atagen2026-10-10 13:20 UTC24
185851447cebatagen2026-10-10 12:58 UTC25
<form id="form">
185851447cebatagen2026-10-10 12:58 UTC26
<h3>Method</h3>
185851447cebatagen2026-10-10 12:58 UTC27
<div id="methods"></div>
185851447cebatagen2026-10-10 12:58 UTC28
185851447cebatagen2026-10-10 12:58 UTC29
<h3>Request</h3>
185851447cebatagen2026-10-10 12:58 UTC30
<table id="fields" cellpadding="2"></table>
185851447cebatagen2026-10-10 12:58 UTC31
185851447cebatagen2026-10-10 12:58 UTC32
<p><input type="submit" id="send" value="Send" style="font-size: 1.3em"></p>
185851447cebatagen2026-10-10 12:58 UTC33
185851447cebatagen2026-10-10 12:58 UTC34
<h3>Stats</h3>
185851447cebatagen2026-10-10 12:58 UTC35
<table id="stats" border="1" cellspacing="0" cellpadding="3"></table>
185851447cebatagen2026-10-10 12:58 UTC36
185851447cebatagen2026-10-10 12:58 UTC37
<h3>Resource</h3>
185851447cebatagen2026-10-10 12:58 UTC38
<div id="targets"></div>
185851447cebatagen2026-10-10 12:58 UTC39
</form>
185851447cebatagen2026-10-10 12:58 UTC40
185851447cebatagen2026-10-10 12:58 UTC41
<p><small>Every request goes through <code>/ui/send</code>, which replays it inside the server, so the page can show redirects and send methods and headers that browsers refuse.</small></p>
185851447cebatagen2026-10-10 12:58 UTC42
</div>
185851447cebatagen2026-10-10 12:58 UTC43
</td>
185851447cebatagen2026-10-10 12:58 UTC44
<td valign="top">
185851447cebatagen2026-10-10 12:58 UTC45
<div class="frame" id="frame"><pre id="log"></pre></div>
185851447cebatagen2026-10-10 12:58 UTC46
</td>
185851447cebatagen2026-10-10 12:58 UTC47
</tr>
185851447cebatagen2026-10-10 12:58 UTC48
</table>
99524cf9f17catagen2026-10-10 10:53 UTC49
99524cf9f17catagen2026-10-10 10:53 UTC50
<script>
185851447cebatagen2026-10-10 12:58 UTC51
const REL = "https://jelq.dev/rels/";
185851447cebatagen2026-10-10 12:58 UTC52
const METHODS = ["JELQ", "GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "TRACE"];
58e1fb3943e6atagen2026-10-10 13:30 UTC53
const LUBES = ["", "application/baby-oil", "application/coconut-oil", "application/lotion", "application/vaseline", "text/plain; charset=spit", "image/jpeg"];
9683736a2c5eatagen2026-10-10 13:15 UTC54
const DEATHS = ["vascular-event", "caught", "banned", "degloved", "zip", "run-ended"];
185851447cebatagen2026-10-10 12:58 UTC55
const STATS = [
185851447cebatagen2026-10-10 12:58 UTC56
  ["x-floor", "Floor"],
185851447cebatagen2026-10-10 12:58 UTC57
  ["x-self-reported-length", "Self-reported length"],
185851447cebatagen2026-10-10 12:58 UTC58
  ["x-girth", "Girth"],
185851447cebatagen2026-10-10 12:58 UTC59
  ["x-foreskin", "Foreskin"],
185851447cebatagen2026-10-10 12:58 UTC60
  ["x-eq", "EQ (aim for 50 to 70)"],
185851447cebatagen2026-10-10 12:58 UTC61
  ["x-stamina", "Stamina"],
185851447cebatagen2026-10-10 12:58 UTC62
  ["x-suspicion", "Suspicion"],
185851447cebatagen2026-10-10 12:58 UTC63
  ["x-shame", "Shame"],
185851447cebatagen2026-10-10 12:58 UTC64
  ["x-cash", "Cash"],
185851447cebatagen2026-10-10 12:58 UTC65
];
185851447cebatagen2026-10-10 12:58 UTC66
const QUIET = new Set(["link", "set-cookie", "server", "x-powered-by", "cache-control", "content-length", "content-type", "date"].concat(STATS.map(s => s[0])));
99524cf9f17catagen2026-10-10 10:53 UTC67
185851447cebatagen2026-10-10 12:58 UTC68
const FIELDS = {
185851447cebatagen2026-10-10 12:58 UTC69
  seed: { label: "seed (unranked)", kind: "text" },
58e1fb3943e6atagen2026-10-10 13:30 UTC70
  technique: { label: "technique", kind: "select" },
58e1fb3943e6atagen2026-10-10 13:30 UTC71
  also: { label: "combo with", kind: "select" },
185851447cebatagen2026-10-10 12:58 UTC72
  intensity: { label: "intensity, 1 to 10", kind: "number", value: "5" },
58e1fb3943e6atagen2026-10-10 13:30 UTC73
  lube: { label: "Content-Type", header: "Content-Type", kind: "select" },
185851447cebatagen2026-10-10 12:58 UTC74
  patch: { label: "body", kind: "textarea", value: '[{"op": "test", "path": "/length", "value": 6}]' },
185851447cebatagen2026-10-10 12:58 UTC75
  range: { label: "Range", header: "Range", kind: "text", placeholder: "inches=0-2" },
185851447cebatagen2026-10-10 12:58 UTC76
  ifMatch: { label: "If-Match", header: "If-Match", kind: "text" },
185851447cebatagen2026-10-10 12:58 UTC77
  ifNoneMatch: { label: "If-None-Match", header: "If-None-Match", kind: "text" },
185851447cebatagen2026-10-10 12:58 UTC78
  ifModifiedSince: { label: "If-Modified-Since", header: "If-Modified-Since", kind: "text", placeholder: "an HTTP-date" },
185851447cebatagen2026-10-10 12:58 UTC79
  proxy: { label: "Proxy-Authorization", header: "Proxy-Authorization", kind: "text", placeholder: "Ruler 5.4" },
185851447cebatagen2026-10-10 12:58 UTC80
  upgrade: { label: "Upgrade", header: "Upgrade", kind: "select", options: ["", "underhand", "overhand"] },
185851447cebatagen2026-10-10 12:58 UTC81
  authorization: { label: "Authorization", header: "Authorization", kind: "text", placeholder: 'Excuse "homework"' },
185851447cebatagen2026-10-10 12:58 UTC82
  extra: { label: "other headers, one per line", kind: "textarea", placeholder: "Expect: gains" },
185851447cebatagen2026-10-10 12:58 UTC83
};
185851447cebatagen2026-10-10 12:58 UTC84
const BY_TARGET = {
185851447cebatagen2026-10-10 12:58 UTC85
  "runs POST": ["seed"],
185851447cebatagen2026-10-10 12:58 UTC86
  "run PATCH": ["patch"],
185851447cebatagen2026-10-10 12:58 UTC87
  "length GET": ["range"],
185851447cebatagen2026-10-10 12:58 UTC88
  "length HEAD": ["range"],
185851447cebatagen2026-10-10 12:58 UTC89
  "foreskin DELETE": ["ifMatch"],
185851447cebatagen2026-10-10 12:58 UTC90
  "elder GET": ["proxy", "ifModifiedSince"],
185851447cebatagen2026-10-10 12:58 UTC91
  "grip GET": ["upgrade"],
4b690ff501b8atagen2026-10-10 13:27 UTC92
  "diagnosis GET": ["authorization", "ifNoneMatch"],
185851447cebatagen2026-10-10 12:58 UTC93
};
185851447cebatagen2026-10-10 12:58 UTC94
const GLOBALS = [
185851447cebatagen2026-10-10 12:58 UTC95
  { key: "runs", name: "start a new run", path: "/runs", methods: ["POST"] },
185851447cebatagen2026-10-10 12:58 UTC96
  { key: "global", name: "leaderboard", path: "/leaderboard", methods: ["GET", "HEAD", "OPTIONS"] },
185851447cebatagen2026-10-10 12:58 UTC97
  { key: "global", name: "graveyard", path: "/graveyard", methods: ["GET", "HEAD", "OPTIONS"] },
185851447cebatagen2026-10-10 12:58 UTC98
  { key: "global", name: "the 2009 forum thread", path: "/forum/threads/2009", methods: ["GET", "HEAD", "OPTIONS"] },
185851447cebatagen2026-10-10 12:58 UTC99
];
185851447cebatagen2026-10-10 12:58 UTC100
185851447cebatagen2026-10-10 12:58 UTC101
let run = null;
185851447cebatagen2026-10-10 12:58 UTC102
let linked = [];
58e1fb3943e6atagen2026-10-10 13:30 UTC103
let techniques = [];
185851447cebatagen2026-10-10 12:58 UTC104
let offered = [];
4b690ff501b8atagen2026-10-10 13:27 UTC105
let challenged = false;
185851447cebatagen2026-10-10 12:58 UTC106
let target = "/runs";
185851447cebatagen2026-10-10 12:58 UTC107
let method = "POST";
185851447cebatagen2026-10-10 12:58 UTC108
const values = {};
185851447cebatagen2026-10-10 12:58 UTC109
185851447cebatagen2026-10-10 12:58 UTC110
const $ = id => document.getElementById(id);
185851447cebatagen2026-10-10 12:58 UTC111
185851447cebatagen2026-10-10 12:58 UTC112
function short(path) {
185851447cebatagen2026-10-10 12:58 UTC113
  return path.replace(/[0-9a-f]{32}/, id => id.slice(0, 6) + "…");
99524cf9f17catagen2026-10-10 10:53 UTC114
}
99524cf9f17catagen2026-10-10 10:53 UTC115
185851447cebatagen2026-10-10 12:58 UTC116
function el(tag, props, ...children) {
185851447cebatagen2026-10-10 12:58 UTC117
  const node = Object.assign(document.createElement(tag), props || {});
185851447cebatagen2026-10-10 12:58 UTC118
  for (const child of children) node.append(child);
185851447cebatagen2026-10-10 12:58 UTC119
  return node;
99524cf9f17catagen2026-10-10 10:53 UTC120
}
99524cf9f17catagen2026-10-10 10:53 UTC121
58e1fb3943e6atagen2026-10-10 13:30 UTC122
function titled(text) {
58e1fb3943e6atagen2026-10-10 13:30 UTC123
  return text.charAt(0).toUpperCase() + text.slice(1);
58e1fb3943e6atagen2026-10-10 13:30 UTC124
}
58e1fb3943e6atagen2026-10-10 13:30 UTC125
58e1fb3943e6atagen2026-10-10 13:30 UTC126
function technique(name) {
58e1fb3943e6atagen2026-10-10 13:30 UTC127
  return techniques.find(t => t.name === name);
58e1fb3943e6atagen2026-10-10 13:30 UTC128
}
58e1fb3943e6atagen2026-10-10 13:30 UTC129
58e1fb3943e6atagen2026-10-10 13:30 UTC130
function clashes(a, b) {
58e1fb3943e6atagen2026-10-10 13:30 UTC131
  const rules = [a.lubricant, b.lubricant];
58e1fb3943e6atagen2026-10-10 13:30 UTC132
  return rules.includes("required") && rules.includes("forbidden");
58e1fb3943e6atagen2026-10-10 13:30 UTC133
}
58e1fb3943e6atagen2026-10-10 13:30 UTC134
58e1fb3943e6atagen2026-10-10 13:30 UTC135
// The options a field can take right now, or null for free text.
58e1fb3943e6atagen2026-10-10 13:30 UTC136
function options(name) {
58e1fb3943e6atagen2026-10-10 13:30 UTC137
  if (name === "technique") return techniques.map(t => t.name);
58e1fb3943e6atagen2026-10-10 13:30 UTC138
  if (name === "also") {
58e1fb3943e6atagen2026-10-10 13:30 UTC139
    const first = technique(fieldValue("technique"));
58e1fb3943e6atagen2026-10-10 13:30 UTC140
    if (!first || !first.lubricant) return [""];
58e1fb3943e6atagen2026-10-10 13:30 UTC141
    const partners = techniques.filter(t => t.lubricant && t.name !== first.name && !clashes(first, t));
58e1fb3943e6atagen2026-10-10 13:30 UTC142
    return [""].concat(partners.map(t => t.name));
58e1fb3943e6atagen2026-10-10 13:30 UTC143
  }
58e1fb3943e6atagen2026-10-10 13:30 UTC144
  if (name === "lube") return lubeRule() === "required" ? LUBES.filter(Boolean) : LUBES;
58e1fb3943e6atagen2026-10-10 13:30 UTC145
  return FIELDS[name].options || null;
58e1fb3943e6atagen2026-10-10 13:30 UTC146
}
58e1fb3943e6atagen2026-10-10 13:30 UTC147
58e1fb3943e6atagen2026-10-10 13:30 UTC148
function raw(name) {
58e1fb3943e6atagen2026-10-10 13:30 UTC149
  return values[name] ?? FIELDS[name].value ?? "";
58e1fb3943e6atagen2026-10-10 13:30 UTC150
}
58e1fb3943e6atagen2026-10-10 13:30 UTC151
58e1fb3943e6atagen2026-10-10 13:30 UTC152
function fieldValue(name) {
58e1fb3943e6atagen2026-10-10 13:30 UTC153
  const allowed = options(name);
58e1fb3943e6atagen2026-10-10 13:30 UTC154
  const value = raw(name);
58e1fb3943e6atagen2026-10-10 13:30 UTC155
  if (allowed && !allowed.includes(value)) return allowed[0] ?? "";
58e1fb3943e6atagen2026-10-10 13:30 UTC156
  return value;
58e1fb3943e6atagen2026-10-10 13:30 UTC157
}
58e1fb3943e6atagen2026-10-10 13:30 UTC158
58e1fb3943e6atagen2026-10-10 13:30 UTC159
function lubeRule() {
58e1fb3943e6atagen2026-10-10 13:30 UTC160
  const picked = [technique(fieldValue("technique")), technique(fieldValue("also"))].filter(Boolean);
58e1fb3943e6atagen2026-10-10 13:30 UTC161
  if (!picked.length || !picked[0].lubricant) return "none";
58e1fb3943e6atagen2026-10-10 13:30 UTC162
  for (const rule of ["forbidden", "required"]) {
58e1fb3943e6atagen2026-10-10 13:30 UTC163
    if (picked.some(t => t.lubricant === rule)) return rule;
58e1fb3943e6atagen2026-10-10 13:30 UTC164
  }
58e1fb3943e6atagen2026-10-10 13:30 UTC165
  return "optional";
58e1fb3943e6atagen2026-10-10 13:30 UTC166
}
58e1fb3943e6atagen2026-10-10 13:30 UTC167
58e1fb3943e6atagen2026-10-10 13:30 UTC168
function allowedMethods(t) {
58e1fb3943e6atagen2026-10-10 13:30 UTC169
  return t.key === "run" && !techniques.length ? t.methods.filter(m => m !== "JELQ") : t.methods;
58e1fb3943e6atagen2026-10-10 13:30 UTC170
}
58e1fb3943e6atagen2026-10-10 13:30 UTC171
185851447cebatagen2026-10-10 12:58 UTC172
function targets() {
185851447cebatagen2026-10-10 12:58 UTC173
  return (run ? linked : []).concat(offered, GLOBALS);
185851447cebatagen2026-10-10 12:58 UTC174
}
185851447cebatagen2026-10-10 12:58 UTC175
185851447cebatagen2026-10-10 12:58 UTC176
function current() {
185851447cebatagen2026-10-10 12:58 UTC177
  return targets().find(t => t.path === target) || GLOBALS[0];
185851447cebatagen2026-10-10 12:58 UTC178
}
185851447cebatagen2026-10-10 12:58 UTC179
185851447cebatagen2026-10-10 12:58 UTC180
function chooseTarget(t) {
58e1fb3943e6atagen2026-10-10 13:30 UTC181
  const allowed = allowedMethods(t);
185851447cebatagen2026-10-10 12:58 UTC182
  target = t.path;
58e1fb3943e6atagen2026-10-10 13:30 UTC183
  method = allowed.includes("JELQ") ? "JELQ" : allowed.find(m => m !== "HEAD" && m !== "OPTIONS") || allowed[0];
185851447cebatagen2026-10-10 12:58 UTC184
  render();
185851447cebatagen2026-10-10 12:58 UTC185
}
185851447cebatagen2026-10-10 12:58 UTC186
185851447cebatagen2026-10-10 12:58 UTC187
function renderStats(headers) {
185851447cebatagen2026-10-10 12:58 UTC188
  const table = $("stats");
185851447cebatagen2026-10-10 12:58 UTC189
  table.replaceChildren();
185851447cebatagen2026-10-10 12:58 UTC190
  for (let i = 0; i < STATS.length; i += 2) {
185851447cebatagen2026-10-10 12:58 UTC191
    const row = el("tr");
185851447cebatagen2026-10-10 12:58 UTC192
    for (const [name, label] of STATS.slice(i, i + 2)) {
185851447cebatagen2026-10-10 12:58 UTC193
      const value = headers ? headers[name] : undefined;
185851447cebatagen2026-10-10 12:58 UTC194
      row.append(el("th", { align: "left", textContent: label }), el("td", { textContent: value === undefined ? "—" : value }));
185851447cebatagen2026-10-10 12:58 UTC195
    }
185851447cebatagen2026-10-10 12:58 UTC196
    table.append(row);
99524cf9f17catagen2026-10-10 10:53 UTC197
  }
185851447cebatagen2026-10-10 12:58 UTC198
}
185851447cebatagen2026-10-10 12:58 UTC199
431c1bc8ded1atagen2026-10-10 13:20 UTC200
function renderAlerts(list) {
431c1bc8ded1atagen2026-10-10 13:20 UTC201
  const box = $("alerts");
431c1bc8ded1atagen2026-10-10 13:20 UTC202
  box.replaceChildren();
431c1bc8ded1atagen2026-10-10 13:20 UTC203
  const alerts = [];
431c1bc8ded1atagen2026-10-10 13:20 UTC204
  for (const [name, value] of list || []) {
ef7d6dee5976atagen2026-10-10 13:23 UTC205
    if (name === "via") alerts.push(titled(value.split(" ").pop()) + " is at the door.");
ef7d6dee5976atagen2026-10-10 13:23 UTC206
    if (name === "x-observed-by") alerts.push((value === "cat" ? "The cat" : titled(value)) + " is watching.");
431c1bc8ded1atagen2026-10-10 13:20 UTC207
    if (name === "warning") {
431c1bc8ded1atagen2026-10-10 13:20 UTC208
      const text = (value.match(/"([^"]*)"/) || [, value])[1];
ef7d6dee5976atagen2026-10-10 13:23 UTC209
      alerts.push(titled(text) + ".");
431c1bc8ded1atagen2026-10-10 13:20 UTC210
    }
431c1bc8ded1atagen2026-10-10 13:20 UTC211
  }
e76ab808e7adatagen2026-10-10 13:46 UTC212
  const stamina = (list || []).find(([name]) => name === "x-stamina");
e76ab808e7adatagen2026-10-10 13:46 UTC213
  if (stamina && stamina[1].startsWith("0/")) alerts.push("Exhausted. Wait out the refractory period, then GET the run.");
431c1bc8ded1atagen2026-10-10 13:20 UTC214
  for (const alert of alerts) box.append(el("h2", { textContent: alert }));
431c1bc8ded1atagen2026-10-10 13:20 UTC215
}
431c1bc8ded1atagen2026-10-10 13:20 UTC216
185851447cebatagen2026-10-10 12:58 UTC217
function renderTargets() {
185851447cebatagen2026-10-10 12:58 UTC218
  const box = $("targets");
185851447cebatagen2026-10-10 12:58 UTC219
  box.replaceChildren();
185851447cebatagen2026-10-10 12:58 UTC220
  for (const t of targets()) {
185851447cebatagen2026-10-10 12:58 UTC221
    const radio = el("input", { type: "radio", name: "target", checked: t.path === target, onchange: () => chooseTarget(t) });
185851447cebatagen2026-10-10 12:58 UTC222
    box.append(el("label", {}, radio, " " + t.name + " ", el("small", { textContent: short(t.path) })), el("br"));
185851447cebatagen2026-10-10 12:58 UTC223
  }
185851447cebatagen2026-10-10 12:58 UTC224
}
185851447cebatagen2026-10-10 12:58 UTC225
185851447cebatagen2026-10-10 12:58 UTC226
function renderMethods() {
185851447cebatagen2026-10-10 12:58 UTC227
  const box = $("methods");
185851447cebatagen2026-10-10 12:58 UTC228
  box.replaceChildren();
58e1fb3943e6atagen2026-10-10 13:30 UTC229
  const allowed = allowedMethods(current());
58e1fb3943e6atagen2026-10-10 13:30 UTC230
  for (const m of METHODS.filter(m => allowed.includes(m))) {
58e1fb3943e6atagen2026-10-10 13:30 UTC231
    const radio = el("input", { type: "radio", name: "method", checked: m === method, onchange: () => { method = m; render(); } });
185851447cebatagen2026-10-10 12:58 UTC232
    const label = el("label", {}, radio, " ");
185851447cebatagen2026-10-10 12:58 UTC233
    label.append(m === "JELQ" ? el("big", {}, el("b", { textContent: "JELQ" })) : m);
185851447cebatagen2026-10-10 12:58 UTC234
    box.append(label, " ");
185851447cebatagen2026-10-10 12:58 UTC235
  }
185851447cebatagen2026-10-10 12:58 UTC236
}
185851447cebatagen2026-10-10 12:58 UTC237
185851447cebatagen2026-10-10 12:58 UTC238
function fieldNames() {
4b690ff501b8atagen2026-10-10 13:27 UTC239
  const t = current();
58e1fb3943e6atagen2026-10-10 13:30 UTC240
  const key = t.key + " " + method;
58e1fb3943e6atagen2026-10-10 13:30 UTC241
  let names = BY_TARGET[key] || [];
58e1fb3943e6atagen2026-10-10 13:30 UTC242
  if (key === "run JELQ") {
58e1fb3943e6atagen2026-10-10 13:30 UTC243
    const chosen = technique(fieldValue("technique"));
58e1fb3943e6atagen2026-10-10 13:30 UTC244
    names = ["technique"];
58e1fb3943e6atagen2026-10-10 13:30 UTC245
    if (options("also").length > 1) names.push("also");
58e1fb3943e6atagen2026-10-10 13:30 UTC246
    if (chosen && chosen.lubricant) names.push("intensity");
58e1fb3943e6atagen2026-10-10 13:30 UTC247
    if (["required", "optional"].includes(lubeRule())) names.push("lube");
58e1fb3943e6atagen2026-10-10 13:30 UTC248
  }
4b690ff501b8atagen2026-10-10 13:27 UTC249
  const scoped = run && !["runs", "global"].includes(t.key);
4b690ff501b8atagen2026-10-10 13:27 UTC250
  const asked = challenged && scoped && !names.includes("authorization");
4b690ff501b8atagen2026-10-10 13:27 UTC251
  return (asked ? ["authorization"] : []).concat(names);
185851447cebatagen2026-10-10 12:58 UTC252
}
185851447cebatagen2026-10-10 12:58 UTC253
185851447cebatagen2026-10-10 12:58 UTC254
function renderFields() {
185851447cebatagen2026-10-10 12:58 UTC255
  const table = $("fields");
185851447cebatagen2026-10-10 12:58 UTC256
  table.replaceChildren();
185851447cebatagen2026-10-10 12:58 UTC257
  for (const name of fieldNames()) {
185851447cebatagen2026-10-10 12:58 UTC258
    const f = FIELDS[name];
185851447cebatagen2026-10-10 12:58 UTC259
    const value = fieldValue(name);
58e1fb3943e6atagen2026-10-10 13:30 UTC260
    const choices = options(name);
185851447cebatagen2026-10-10 12:58 UTC261
    let input;
58e1fb3943e6atagen2026-10-10 13:30 UTC262
    if (choices) {
58e1fb3943e6atagen2026-10-10 13:30 UTC263
      input = el("select", {}, ...choices.map(o => el("option", { value: o, textContent: o || "(none)", selected: o === value })));
185851447cebatagen2026-10-10 12:58 UTC264
    } else if (f.kind === "textarea") {
185851447cebatagen2026-10-10 12:58 UTC265
      input = el("textarea", { rows: 3, cols: 40, value, placeholder: f.placeholder || "" });
185851447cebatagen2026-10-10 12:58 UTC266
    } else {
185851447cebatagen2026-10-10 12:58 UTC267
      input = el("input", { type: f.kind, value, placeholder: f.placeholder || "", size: 30 });
185851447cebatagen2026-10-10 12:58 UTC268
    }
58e1fb3943e6atagen2026-10-10 13:30 UTC269
    input.oninput = () => { values[name] = input.value; };
58e1fb3943e6atagen2026-10-10 13:30 UTC270
    input.onchange = () => { values[name] = input.value; if (choices) renderFields(); };
185851447cebatagen2026-10-10 12:58 UTC271
    table.append(el("tr", {}, el("td", { align: "right", valign: "top", textContent: f.label }), el("td", {}, input)));
185851447cebatagen2026-10-10 12:58 UTC272
  }
58e1fb3943e6atagen2026-10-10 13:30 UTC273
  const extra = el("textarea", { rows: 3, cols: 40, value: raw("extra"), placeholder: FIELDS.extra.placeholder });
4b690ff501b8atagen2026-10-10 13:27 UTC274
  extra.oninput = () => { values.extra = extra.value; };
4b690ff501b8atagen2026-10-10 13:27 UTC275
  const more = el("details", { open: Boolean(values.extra) }, el("summary", { textContent: "more headers" }), extra);
4b690ff501b8atagen2026-10-10 13:27 UTC276
  table.append(el("tr", {}, el("td"), el("td", {}, more)));
185851447cebatagen2026-10-10 12:58 UTC277
  $("send").value = method + " " + short(current().path);
185851447cebatagen2026-10-10 12:58 UTC278
}
185851447cebatagen2026-10-10 12:58 UTC279
185851447cebatagen2026-10-10 12:58 UTC280
function render() {
58e1fb3943e6atagen2026-10-10 13:30 UTC281
  if (!allowedMethods(current()).includes(method)) return chooseTarget(current());
185851447cebatagen2026-10-10 12:58 UTC282
  renderTargets();
185851447cebatagen2026-10-10 12:58 UTC283
  renderMethods();
185851447cebatagen2026-10-10 12:58 UTC284
  renderFields();
185851447cebatagen2026-10-10 12:58 UTC285
}
185851447cebatagen2026-10-10 12:58 UTC286
185851447cebatagen2026-10-10 12:58 UTC287
function parseLinks(header) {
58e1fb3943e6atagen2026-10-10 13:30 UTC288
  const resources = [];
58e1fb3943e6atagen2026-10-10 13:30 UTC289
  const moves = [];
185851447cebatagen2026-10-10 12:58 UTC290
  for (const match of header.matchAll(/<([^>]*)>((?:\s*;\s*[a-z-]+="[^"]*")*)/g)) {
185851447cebatagen2026-10-10 12:58 UTC291
    const params = Object.fromEntries([...match[2].matchAll(/([a-z-]+)="([^"]*)"/g)].map(p => [p[1], p[2]]));
185851447cebatagen2026-10-10 12:58 UTC292
    const name = (params.rel || "").replace(REL, "");
58e1fb3943e6atagen2026-10-10 13:30 UTC293
    if (name === "technique") {
58e1fb3943e6atagen2026-10-10 13:30 UTC294
      moves.push({ name: params.title, lubricant: params.lubricant || null });
58e1fb3943e6atagen2026-10-10 13:30 UTC295
      continue;
58e1fb3943e6atagen2026-10-10 13:30 UTC296
    }
185851447cebatagen2026-10-10 12:58 UTC297
    const methods = (params.allow || "GET").split(",").map(s => s.trim());
58e1fb3943e6atagen2026-10-10 13:30 UTC298
    resources.push({ key: name, name: name === "run" ? "the run" : name, path: match[1], methods });
185851447cebatagen2026-10-10 12:58 UTC299
  }
58e1fb3943e6atagen2026-10-10 13:30 UTC300
  return [resources, moves];
99524cf9f17catagen2026-10-10 10:53 UTC301
}
99524cf9f17catagen2026-10-10 10:53 UTC302
99524cf9f17catagen2026-10-10 10:53 UTC303
function hrefs(value, found) {
99524cf9f17catagen2026-10-10 10:53 UTC304
  if (value && typeof value === "object") {
185851447cebatagen2026-10-10 12:58 UTC305
    if (typeof value.href === "string") {
185851447cebatagen2026-10-10 12:58 UTC306
      const name = value.title || value.item || value.name || value.href.split("/").pop();
185851447cebatagen2026-10-10 12:58 UTC307
      found.push({ key: "offered", name, path: value.href, methods: [value.method || "GET"] });
185851447cebatagen2026-10-10 12:58 UTC308
    }
99524cf9f17catagen2026-10-10 10:53 UTC309
    for (const key in value) hrefs(value[key], found);
99524cf9f17catagen2026-10-10 10:53 UTC310
  }
99524cf9f17catagen2026-10-10 10:53 UTC311
  return found;
99524cf9f17catagen2026-10-10 10:53 UTC312
}
99524cf9f17catagen2026-10-10 10:53 UTC313
185851447cebatagen2026-10-10 12:58 UTC314
function log(text) {
585e6b7ce086atagen2026-10-10 13:43 UTC315
  $("log").prepend(text + "\n\n");
585e6b7ce086atagen2026-10-10 13:43 UTC316
  $("frame").scrollTop = 0;
99524cf9f17catagen2026-10-10 10:53 UTC317
}
99524cf9f17catagen2026-10-10 10:53 UTC318
185851447cebatagen2026-10-10 12:58 UTC319
function describe(r) {
185851447cebatagen2026-10-10 12:58 UTC320
  const lines = ["< " + r.status + " " + r.reason];
185851447cebatagen2026-10-10 12:58 UTC321
  for (const [name, value] of r.headers) {
185851447cebatagen2026-10-10 12:58 UTC322
    if (!QUIET.has(name)) lines.push("< " + name + ": " + short(value));
185851447cebatagen2026-10-10 12:58 UTC323
  }
185851447cebatagen2026-10-10 12:58 UTC324
  let body = null;
185851447cebatagen2026-10-10 12:58 UTC325
  try { body = JSON.parse(r.body); } catch (e) {}
185851447cebatagen2026-10-10 12:58 UTC326
  if (body && typeof body === "object") {
185851447cebatagen2026-10-10 12:58 UTC327
    const rest = Object.assign({}, body);
185851447cebatagen2026-10-10 12:58 UTC328
    if (rest.detail) lines.push("  " + rest.detail);
185851447cebatagen2026-10-10 12:58 UTC329
    for (const key of ["type", "title", "status", "detail"]) delete rest[key];
185851447cebatagen2026-10-10 12:58 UTC330
    if (Object.keys(rest).length) lines.push(short(JSON.stringify(rest, null, 2)).replace(/^/gm, "  "));
185851447cebatagen2026-10-10 12:58 UTC331
  } else if (r.body) {
e76ab808e7adatagen2026-10-10 13:46 UTC332
    const range = (r.headers.find(h => h[0] === "content-range") || [])[1] || "";
e76ab808e7adatagen2026-10-10 13:46 UTC333
    const partial = r.status === 206 && range.match(/^bytes (\d+)-(\d+)\/(\d+)$/);
185851447cebatagen2026-10-10 12:58 UTC334
    lines.push("  " + r.body);
e76ab808e7adatagen2026-10-10 13:46 UTC335
    if (partial) lines.push("  [bytes " + partial[1] + "-" + partial[2] + " of " + partial[3] + ". A 206 carries only part of the representation, as RFC 9110 requires.]");
185851447cebatagen2026-10-10 12:58 UTC336
  }
185851447cebatagen2026-10-10 12:58 UTC337
  return lines.join("\n");
99524cf9f17catagen2026-10-10 10:53 UTC338
}
99524cf9f17catagen2026-10-10 10:53 UTC339
185851447cebatagen2026-10-10 12:58 UTC340
function absorb(r, sentMethod, sentPath) {
185851447cebatagen2026-10-10 12:58 UTC341
  const headers = Object.fromEntries(r.headers.map(([n, v]) => [n.toLowerCase(), v]));
185851447cebatagen2026-10-10 12:58 UTC342
  let body = null;
185851447cebatagen2026-10-10 12:58 UTC343
  try { body = JSON.parse(r.body); } catch (e) {}
185851447cebatagen2026-10-10 12:58 UTC344
  const problem = body && typeof body.type === "string" ? body.type.split("/").pop() : null;
58e1fb3943e6atagen2026-10-10 13:30 UTC345
  const started = r.status === 201 && (sentPath === "/runs" || sentPath.startsWith("/runs?"));
185851447cebatagen2026-10-10 12:58 UTC346
58e1fb3943e6atagen2026-10-10 13:30 UTC347
  if (started) {
58e1fb3943e6atagen2026-10-10 13:30 UTC348
    run = headers.location;
58e1fb3943e6atagen2026-10-10 13:30 UTC349
    log("--- a new run has started at " + short(run) + " ---");
185851447cebatagen2026-10-10 12:58 UTC350
  }
431c1bc8ded1atagen2026-10-10 13:20 UTC351
  if ("x-eq" in headers) {
431c1bc8ded1atagen2026-10-10 13:20 UTC352
    renderStats(headers);
431c1bc8ded1atagen2026-10-10 13:20 UTC353
    renderAlerts(r.headers);
4b690ff501b8atagen2026-10-10 13:27 UTC354
    challenged = r.status === 401 || "via" in headers;
431c1bc8ded1atagen2026-10-10 13:20 UTC355
  }
58e1fb3943e6atagen2026-10-10 13:30 UTC356
  if (headers.link) [linked, techniques] = parseLinks(headers.link);
185851447cebatagen2026-10-10 12:58 UTC357
  offered = body ? hrefs(body, []) : [];
58e1fb3943e6atagen2026-10-10 13:30 UTC358
  if (headers.location && !started) {
185851447cebatagen2026-10-10 12:58 UTC359
    offered.unshift({ key: "offered", name: "Location", path: headers.location, methods: ["GET"] });
185851447cebatagen2026-10-10 12:58 UTC360
  }
185851447cebatagen2026-10-10 12:58 UTC361
  const abandoned = sentMethod === "DELETE" && sentPath === run && r.status === 204;
185851447cebatagen2026-10-10 12:58 UTC362
  if (run && (abandoned || DEATHS.includes(problem))) {
185851447cebatagen2026-10-10 12:58 UTC363
    log("--- the run has ended ---");
431c1bc8ded1atagen2026-10-10 13:20 UTC364
    renderAlerts(null);
4b690ff501b8atagen2026-10-10 13:27 UTC365
    challenged = false;
185851447cebatagen2026-10-10 12:58 UTC366
    run = null;
185851447cebatagen2026-10-10 12:58 UTC367
    linked = [];
58e1fb3943e6atagen2026-10-10 13:30 UTC368
    techniques = [];
185851447cebatagen2026-10-10 12:58 UTC369
  }
185851447cebatagen2026-10-10 12:58 UTC370
  if (started || !targets().some(t => t.path === target)) {
185851447cebatagen2026-10-10 12:58 UTC371
    const home = linked.find(t => t.key === "run");
58e1fb3943e6atagen2026-10-10 13:30 UTC372
    chooseTarget(home || GLOBALS[0]);
185851447cebatagen2026-10-10 12:58 UTC373
  } else {
185851447cebatagen2026-10-10 12:58 UTC374
    render();
99524cf9f17catagen2026-10-10 10:53 UTC375
  }
99524cf9f17catagen2026-10-10 10:53 UTC376
}
99524cf9f17catagen2026-10-10 10:53 UTC377
185851447cebatagen2026-10-10 12:58 UTC378
async function go(event) {
185851447cebatagen2026-10-10 12:58 UTC379
  event.preventDefault();
185851447cebatagen2026-10-10 12:58 UTC380
  const t = current();
185851447cebatagen2026-10-10 12:58 UTC381
  const key = t.key + " " + method;
185851447cebatagen2026-10-10 12:58 UTC382
  const value = name => fieldValue(name).trim();
185851447cebatagen2026-10-10 12:58 UTC383
  const headers = [];
185851447cebatagen2026-10-10 12:58 UTC384
  let path = t.path;
185851447cebatagen2026-10-10 12:58 UTC385
  let body = "";
185851447cebatagen2026-10-10 12:58 UTC386
  for (const name of fieldNames()) {
185851447cebatagen2026-10-10 12:58 UTC387
    const f = FIELDS[name];
185851447cebatagen2026-10-10 12:58 UTC388
    if (f.header && value(name)) headers.push([f.header, value(name)]);
185851447cebatagen2026-10-10 12:58 UTC389
  }
185851447cebatagen2026-10-10 12:58 UTC390
  if (fieldNames().includes("upgrade") && value("upgrade")) headers.push(["Connection", "upgrade"]);
58e1fb3943e6atagen2026-10-10 13:30 UTC391
  for (const line of raw("extra").split("\n")) {
185851447cebatagen2026-10-10 12:58 UTC392
    const at = line.indexOf(":");
185851447cebatagen2026-10-10 12:58 UTC393
    if (at > 0) headers.push([line.slice(0, at).trim(), line.slice(at + 1).trim()]);
185851447cebatagen2026-10-10 12:58 UTC394
  }
185851447cebatagen2026-10-10 12:58 UTC395
  if (key === "run JELQ") {
58e1fb3943e6atagen2026-10-10 13:30 UTC396
    const names = fieldNames();
58e1fb3943e6atagen2026-10-10 13:30 UTC397
    const chosen = [value("technique")].concat(names.includes("also") && value("also") ? [value("also")] : []);
58e1fb3943e6atagen2026-10-10 13:30 UTC398
    path += "?technique=" + encodeURIComponent(chosen.join(","));
58e1fb3943e6atagen2026-10-10 13:30 UTC399
    if (names.includes("intensity")) path += "&intensity=" + encodeURIComponent(value("intensity"));
185851447cebatagen2026-10-10 12:58 UTC400
  }
185851447cebatagen2026-10-10 12:58 UTC401
  if (key === "runs POST" && value("seed")) path += "?seed=" + encodeURIComponent(value("seed"));
185851447cebatagen2026-10-10 12:58 UTC402
  if (method === "PATCH") {
185851447cebatagen2026-10-10 12:58 UTC403
    headers.push(["Content-Type", "application/json-patch+json"]);
185851447cebatagen2026-10-10 12:58 UTC404
    body = value("patch");
185851447cebatagen2026-10-10 12:58 UTC405
  }
99524cf9f17catagen2026-10-10 10:53 UTC406
585e6b7ce086atagen2026-10-10 13:43 UTC407
  const sent = ["> " + method + " " + short(path)].concat(headers.map(([name, v]) => "> " + name + ": " + v)).join("\n");
ef7d6dee5976atagen2026-10-10 13:23 UTC408
  headers.push(["Accept-Language", $("locale").value]);
7288fc269bb6atagen2026-10-10 13:36 UTC409
  let r;
7288fc269bb6atagen2026-10-10 13:36 UTC410
  try {
7288fc269bb6atagen2026-10-10 13:36 UTC411
    const response = await fetch("/ui/send", {
7288fc269bb6atagen2026-10-10 13:36 UTC412
      method: "POST",
7288fc269bb6atagen2026-10-10 13:36 UTC413
      headers: { "Content-Type": "application/json" },
7288fc269bb6atagen2026-10-10 13:36 UTC414
      body: JSON.stringify({ method, path, headers, body }),
7288fc269bb6atagen2026-10-10 13:36 UTC415
    });
7288fc269bb6atagen2026-10-10 13:36 UTC416
    r = await response.json();
7288fc269bb6atagen2026-10-10 13:36 UTC417
  } catch (error) {
585e6b7ce086atagen2026-10-10 13:43 UTC418
    log(sent + "\n! The server did not answer. Is jelqd still running? (" + error.message + ")");
7288fc269bb6atagen2026-10-10 13:36 UTC419
    return;
7288fc269bb6atagen2026-10-10 13:36 UTC420
  }
7288fc269bb6atagen2026-10-10 13:36 UTC421
  if (!Array.isArray(r.headers)) {
585e6b7ce086atagen2026-10-10 13:43 UTC422
    log(sent + "\n! The page could not read that reply:\n  " + JSON.stringify(r));
7288fc269bb6atagen2026-10-10 13:36 UTC423
    return;
7288fc269bb6atagen2026-10-10 13:36 UTC424
  }
585e6b7ce086atagen2026-10-10 13:43 UTC425
  log(sent + "\n" + describe(r));
185851447cebatagen2026-10-10 12:58 UTC426
  absorb(r, method, path);
99524cf9f17catagen2026-10-10 10:53 UTC427
}
185851447cebatagen2026-10-10 12:58 UTC428
185851447cebatagen2026-10-10 12:58 UTC429
$("form").onsubmit = go;
ef7d6dee5976atagen2026-10-10 13:23 UTC430
$("locale").value = localStorage.getItem("locale") || "en-GB";
ef7d6dee5976atagen2026-10-10 13:23 UTC431
$("locale").onchange = () => localStorage.setItem("locale", $("locale").value);
185851447cebatagen2026-10-10 12:58 UTC432
renderStats(null);
185851447cebatagen2026-10-10 12:58 UTC433
render();
585e6b7ce086atagen2026-10-10 13:43 UTC434
log("Welcome. Choose \"start a new run\" and send POST to begin. The newest turn is always at the top.");
99524cf9f17catagen2026-10-10 10:53 UTC435
</script>
99524cf9f17catagen2026-10-10 10:53 UTC436
</body>
99524cf9f17catagen2026-10-10 10:53 UTC437
</html>