refactor(Harmony Enhancements.user.js): optimize DOM caching and prevent redundant parsing (#8)
This commit addresses several inefficiencies and a bug in the script's
initialization and data-loading process.
DOM Caching Optimization:
-
initDOMCache has been broken into smaller, page-specific functions
(e.g., cacheReleaseLookupPageDOM, cacheSettingsPageDOM).
- The
main() function now acts as a router, calling only the
necessary caching function for the current page.
- A new
Map (releaseInfoRowsByHeader) is created once on
release pages to cache table rows by their header text.
-
UI_UTILS.findReleaseInfoRow is refactored to use this Map,
changing its lookup from O(n) to O(1) and speeding up all
dependent modules (like toggleReleaseInfo).
Redundant Parsing Fix:
- Previously, modules would run on empty/error
/release pages
and each re-call getReleaseDataFromJSON, leading to
multiple warnings and wasted cycles.
-
getReleaseDataFromJSON now uses a "tri-state" cache
(initial: undefined, failed: null, success: {object}).
- This ensures the
__FRSH_STATE__ JSON is parsed exactly
once. All subsequent calls instantly receive the cached result
(either the release object or null).
This fixes the bug of repeated "Could not find release data" warnings in
the console and prevents modules from running on pages with no release.
fix(Harmony Enhancements.user.js): Normalize ETI even without provider conflict (#9)
The previous logic for normalizeETI on multi-provider releases
(> 1 provider) would only trigger a normalization if Harmony's UI
indicated a discrepancy between provider titles (i.e., a ul.alt-values
list was present).
This caused a bug where titles containing known "tech terms"
(like "sped up" or "slowed") were not normalized if all providers
agreed on the "bad" hyphenated ETI.
This commit refactors the logic to check two conditions:
A title will now be normalized if:
- The hyphenated ETI contains a term from the
techTerms list.
(This fixes the bug)
- OR it is a multi-provider release and a UI discrepancy is present.
(This retains the original safeguard against false positives
for non-tech-term ETI).
refactor(Harmony Enhancements.user.js): Extract label link generation to a UI utility
Created a new helper function, UI_UTILS.updateLabelLink, to provide a single, reusable method for updating the main release label <span>. This function handles clearing existing content and rebuilding it with either plain text (if no MBID) or a full MusicBrainz icon and link.
This change achieves two objectives:
DRY: Refactored mapLabelMbids to use this new helper, which significantly simplifies its code and removes duplicated DOM manipulation logic.
Consistency/Fix: Refactored setNoLabel to also use updateLabelLink. This fixes an issue where setNoLabel would only update the label text but failed to add the correct link to the [no label] entity.
Both label-modifying modules now behave consistently and share the same UI logic.
feat(Harmony Enhancements.user.js): Disable spellcheck on textareas
Disables the browser's native spellchecker for all <textarea> elements on the settings page. This improves usability as the text fields are used for technical terms, regular expressions, and label mappings, where spellchecking is unhelpful and distracting.