Skip to content

Refactor duplicated site scripts into shared JS/gf-utils.js helpers - #3

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1784999722-shared-utils
Open

Refactor duplicated site scripts into shared JS/gf-utils.js helpers#3
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1784999722-shared-utils

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

The documentation site repeated the same few patterns dozens of times (13 copy-pasted partN() loaders in app.js, 40 identical _keyCustom blocks in code/part-eight.js, 4 identical ajax callbacks in code/part-two.js, ...). This adds JS/gf-utils.js — a small layer on top of GF-1.js, loaded by index.html right after it — and rewrites those call sites in terms of it. Net −335 lines, no behaviour change.

New helpers: _bindClick(idsOrMap, fu), _bindKey(codeMap), _printKeyTo(id, labelMap), _responseTo(id), _alertUrl(url), _nextIndex(i, len), _printAll(idContentMap).

app.js: the 13 partN() functions, their 14 _onClick bindings and the 14-branch if/else chain behind INSERT collapse into one table + one loader:

const documentationPart = [{ file: "part-one", trigger: ["part_one","part_one_one"] }, /* ... */];

function loadPart(i) {                     // i indexes documentationPage[1..13]
  const part = documentationPart[i - 1];
  _loadDoc("./code/"+part.file+".html", function(res){ /* same body as before */ });
}

documentationPart.forEach(function(part,index){ _bindClick(part.trigger, function(){ loadPart(index+1); }); });

INSERT keeps the old semantics (home → part1, partN → partN+1, part13 → part1) via documentationPage.indexOf(now_page), and still does nothing when the current page is Get-Start/All-Function.

One intentional behaviour fix: the PREVIOUS key in code/part-eight.js used to _writeLog("PREVIOUS") and log the wrong key code instead of printing to display_key — the table-driven version makes it behave like every other key.

Verified in Chrome against a local static server: parts 4, 8, 9 and 11 render, nav clicks and INSERT navigation work, key labels print, and the color cycling in part 11 still rotates.

Link to Devin session: https://app.devin.ai/sessions/fc017cd138aa4772a02a07db257dbf5d
Requested by: @lamhotsimamora

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@lamhotsimamora lamhotsimamora self-assigned this Jul 25, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant