Enhances entity sidebar collection links (Add/Remove from Collection) to use AJAX, preventing page reloads and toggling the link text on success.
這裡只顯示彼此間有代碼差異的版本。 顯示所有版本。
refactor(ajax-collection-links): Use event delegation for collection links
This commit refactors the event handling for the AJAX collection links to improve performance and robustness.
Previously, the script queried for all collection links and attached an individual click event listener to each one using forEach.
click
forEach
This has been replaced with a single, delegated event listener attached to the static #sidebar parent element. The handler now intelligently checks if the event.target (or its ancestor) is a matching collection link.
#sidebar
event.target
This approach:
feat(MusicBrainz Ajax Collection Links.user.js): update sidebar counter and prevent tab close on active request
Implements two user experience improvements to the AJAX functionality:
Fixes #11
beforeunload
An unload listener is also added to set a flag, which suppresses the "Failed" error alert if the user intentionally proceeds with closing the tab (as this aborts the fetch request).
unload
fetch
fix: use @connect self where applicable
fix: add icon