Skip to content

perf: fix 9 JS inefficiencies across /docs chapter, search, and bookmarks pages; add Devnagri Urdu (Maududi) translation#33

Draft
Copilot wants to merge 5 commits into
cairofrom
copilot/identify-code-improvements
Draft

perf: fix 9 JS inefficiencies across /docs chapter, search, and bookmarks pages; add Devnagri Urdu (Maududi) translation#33
Copilot wants to merge 5 commits into
cairofrom
copilot/identify-code-improvements

Conversation

Copilot AI commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

Several hot-path JS routines in the generated /docs pages had algorithmic and DOM inefficiencies causing measurable jank on filter toggles, scroll, and search operations across all 114 chapter files.

Chapter pages (001.html114.html)

  • applyAllRows() — replaced O(n×m) nested Set+classList loop with Array.prototype.some.call(tr.classList, c => enabledTypes.has(c)), flipping the iteration to walk the small classList (2–3 items) and hit the Set in O(1)
  • applyFs() — collapsed two querySelectorAll passes into one; also fixes a silent bug where td:not(.label) in the second pass overwrote .arabic-text cells with the wrong font size at non-default scale steps
  • Scroll handler — gated the display toggle behind requestAnimationFrame + ticking flag to cap DOM writes at one per frame
  • Permalink clicks — replaced up to 286 per-element addEventListener calls with a single delegated listener on document
  • copyVerse — replaced tr.querySelector('.label') with direct tr.cells[0]

search.html

  • highlight() — moved new RegExp(…) construction out of the per-result-per-field call into buildHighlightRegexes(), called once per search; previously created 200+ RegExp objects per page render
  • doSearch() — pre-computes fieldArrays before the 6,236-row loop, eliminating repeated fieldCache[f[0]]||[] lookups per row
  • renderPage() — same pre-cache pattern applied before the results render loop

bookmarks.html

  • Delete button — replaced onclick="deleteBm(i)" (fragile stale-index binding) with data-key="s:a" and a single delegated listener; deletion now resolves by stable surah:ayah identity

Devnagri Urdu (Maududi) translation

Added the Devanagari-script Urdu translation by Abul Ala Maududi to the website:

  • src/gentxtforquran.py — added a Devnagri-Urdu-HTML parser that strips HTML tags from data/quran_devnagri_urdu_maududi.html, normalizes split verse markers (e.g. [ \nS:A][S:A]), and extracts all [S:A] verse lines to produce output/quran_devnagri_urdu_maududi.txt (6,210 of 6,236 verses; 26 are absent in the upstream source HTML)
  • src/gendocshtml.py — loads the new output file, adds a styled devnagri-urdu row (light blue-grey background, Devanagari font, indigo text) with dark mode support, adds it to the Content Filter checkbox list, writes docs/sd/devnagri-urdu.json for search, and registers it in search.html's FIELD_MAP

Approach

All JS and translation templates live in src/gendocshtml.py. Changes were made there and the full /docs directory regenerated — 114 chapter files + search.html + bookmarks.html + config.html + config.js + docs/sd/devnagri-urdu.json.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

…scroll rAF, permalink delegation, search regex/array caching, bookmarks event delegation

Co-authored-by: druvx13 <131332414+druvx13@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify and suggest improvements to slow or inefficient code perf: fix 9 JS inefficiencies across /docs chapter, search, and bookmarks pages Mar 12, 2026
@druvx13

druvx13 commented Mar 12, 2026

Copy link
Copy Markdown
Owner

Nice work; @copilot , i have added “quran_devnagri_urdu_maududi.html” in /data directory creates it's output in /output directory like in the format as others are and also include it in /docs website.

Co-authored-by: druvx13 <131332414+druvx13@users.noreply.github.com>

Copilot AI commented Mar 12, 2026

Copy link
Copy Markdown
Contributor Author

Nice work; @copilot , i have added “quran_devnagri_urdu_maududi.html” in /data directory creates it's output in /output directory like in the format as others are and also include it in /docs webs...

Done in commit 069f726. Here's what was added:

  • src/gentxtforquran.py: Added a Devnagri-Urdu-HTML parser that strips HTML tags, fixes split verse markers (e.g. [ \nS:A][S:A]), and extracts all [S:A] verse lines → output/quran_devnagri_urdu_maududi.txt (6,210 verses; 26 are absent in the source HTML).
  • src/gendocshtml.py: Added the translation to all chapter pages (light blue-grey row, Devanagari font), the Content Filter checkbox, docs/sd/devnagri-urdu.json for search, and the FIELD_MAP in search.html.
  • All 114 chapter HTMLs, search.html, config.html, config.js, and docs/sd/devnagri-urdu.json were regenerated.

The new "Devnagri Urdu (Maududi)" row now appears in each verse alongside the other translations and is searchable from search.html.

Copilot AI changed the title perf: fix 9 JS inefficiencies across /docs chapter, search, and bookmarks pages perf: fix 9 JS inefficiencies across /docs chapter, search, and bookmarks pages; add Devnagri Urdu (Maududi) translation Mar 12, 2026
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.

2 participants