brain: plug into the page's hooks instead of overriding its functions
hooks.djPrompt, hooks.stationOpened, hooks.jobMade and hooks.reacted carry what the djPrompt / openStation / makeJob / react reassignments did; same behaviour. countPlay reads its one row with db.get instead of db.all(). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K6897PWcUEwHiqZMcVnNF6
This commit is contained in:
1 parent
eb110e827b
commit
dddf8f0add
1 file changed
+6
-14
@@ -124,19 +124,17 @@ function tasteText() {
|
||||
(likes ? ` Words it warms to: ${likes}.` : "") + (dislikes ? ` Words it cools on: ${dislikes}.` : "") +
|
||||
` Aim near the likely region and lean on the warm words unless the listener's own words say otherwise; keep some variety.`;
|
||||
}
|
||||
const _djPromptBase = djPrompt; // assignment, not a declaration: a declaration would hoist over this
|
||||
djPrompt = function () {
|
||||
const base = _djPromptBase();
|
||||
/* the page's hooks (index.html › hooks): the taste text rides into the DJ's prompt, and a station opening retrains */
|
||||
hooks.djPrompt = (base) => {
|
||||
const tt = tasteText();
|
||||
return tt ? base.replace("\nWrite the NEXT track.", `\n${tt}\n\nWrite the NEXT track.`) : base;
|
||||
};
|
||||
const _openStation = openStation;
|
||||
openStation = async function (seed, s) { await _openStation(seed, s); rebuildBrains().catch(() => {}); };
|
||||
hooks.stationOpened = () => { rebuildBrains().catch(() => {}); };
|
||||
|
||||
/* ---------- plays: every start counts, and so does every pass of the loop ---------- */
|
||||
async function countPlay(spec) {
|
||||
if (!spec || !spec.id) return;
|
||||
const row = (await db.all()).find((t) => t.id === spec.id); if (!row) return;
|
||||
const row = await db.get(spec.id); if (!row) return;
|
||||
row.plays = (row.plays || 0) + 1; row.spec.plays = row.plays; spec.plays = row.plays;
|
||||
await db.put(row);
|
||||
if (row.plays === 2 || row.plays === 4 || row.plays % 8 === 0) rebuildBrains().catch(() => {});
|
||||
@@ -150,11 +148,7 @@ state.audio.addEventListener("timeupdate", () => { // a loop wra
|
||||
});
|
||||
|
||||
/* ---------- the NEXT line carries the net's guess for the track in the oven ---------- */
|
||||
const _makeJob = makeJob;
|
||||
makeJob = function (spec) {
|
||||
const net = brainNow(); if (net) spec.guess = net.predict(spec);
|
||||
return _makeJob(spec);
|
||||
};
|
||||
hooks.jobMade = (spec) => { const net = brainNow(); if (net) spec.guess = net.predict(spec); };
|
||||
const guessText = (spec) => spec && spec.guess != null ? ` · ${Math.round(spec.guess * 100)}% YOU` : "";
|
||||
(function () {
|
||||
const next = $("#next");
|
||||
@@ -283,9 +277,7 @@ async function openTaste() {
|
||||
openTaste.redraw = show;
|
||||
}
|
||||
/* a reaction while TASTE is open: retrain, and let the neurons flare */
|
||||
const _react = react;
|
||||
react = async function (emoji, text) {
|
||||
await _react(emoji, text);
|
||||
hooks.reacted = () => {
|
||||
rebuildBrains().then(() => {
|
||||
if ($("#taste").classList.contains("hidden") || !openTaste.redraw) return;
|
||||
let t0 = performance.now();
|
||||
|
||||
Reference in new issue
Block a user