1.1.11
Features:
- Added automatic text rephrasing via GPT models to improve clarity and fluidity.
- Added direct buttons on the banner to enable/disable rephrasing and translation.
- Integrated a language selector in the banner to easily change the target language.
- Supported the Escape key to cancel the ongoing recording.
Improvements:
- Automatically hide the banner 4 seconds after the recording is cancelled.
- Bidirectional synchronization between the options and the control banner.
- Visual redesign of the banner with modern buttons and smooth animations.
- Visual optimization of the language selector (removal of double arrows).
- Added padding to the body to prevent the banner from covering content.
Internationalization:
- Added translated messages for the new features.
- Created an event system for dynamic translation management.
Framework:
- Updated constants to include rephrasing errors.
- Added a keyboard handler for detecting the Escape key.
- Improved the text processing flow to include the rephrasing step.
Fix: Preservation of Focus and Cursor during Banner Interactions
This update fixes a significant user experience issue where focus and cursor position were lost during interactions with the banner controls (rephrasing, translation buttons, language selector).
Improvements made:
- Added a system to memorize and restore focus and text selection.
- Captured focus on mousedown before interacting with controls.
- Intelligent restoration of cursor position after the interaction.
- Improved handling of delays (300ms) to ensure DOM stabilization.
- Specific management of the language selector, including cases where the user clicks elsewhere after it is opened.
- Double restoration of focus when cancelling recording with the Escape key.
- Robust checks to avoid errors on invalid elements.
These improvements ensure a smooth text editing experience without interruption, even when interacting with the extension's controls.
-
Consolidation of Duplicated Functions:
- The
showBannerfunction has been consolidated inui.jsand is now used bycontent.js. - The language lists have been centralized in a new module
languages.js.
- The
-
Extraction of CSS:
- The inline CSS in
content.jshas been moved tocontent.css. - Manual CSS injection in
content.jshas been replaced by using an external CSS file.
- The inline CSS in
-
Improvement in Module Loading:
- The file
languages.jshas been added to the list of files to inject inbackground.js. - The
i18n.jsmodule is now explicitly loaded inbackground.js.
- The file
Benefits of these changes:
-
Better Separation of Concerns:
- Display logic is now in
ui.js. - Language data is centralized in
languages.js. - Styles are managed in
content.css.
- Display logic is now in
-
Easier Maintenance:
- It is now simpler to modify styles because they are in a dedicated CSS file.
- Changes to user interface functions can be made in one place.
-
Improved Performance:
- CSS is now injected by Chrome in an optimized manner.
- Code duplication has been reduced.
-
Consolidation of Duplicated Functions:
- The
showBannerfunction has been consolidated inui.jsand is now used bycontent.js. - The language lists have been centralized in a new module
languages.js.
- The
-
Extraction of CSS:
- The inline CSS in
content.jshas been moved tocontent.css. - Manual CSS injection in
content.jshas been replaced by using an external CSS file.
- The inline CSS in
-
Modularization of the
initBannerFunction:- The long
initBannerfunction has been decomposed into several smaller, specialized functions:createBannerButton: Creates a control button with an icon and text.createLanguageSelector: Creates the language selector.initializeLanguageSelector: Initializes the selector with the available languages.setupBannerEventListeners: Sets up event handlers for the buttons.- Additional utility functions for handling languages.
- The long
-
Code Cleanup:
- Removed obsolete comments.
- Removed unnecessary skipcq markers.
-
Improved Readability:
- Better organization of functions.
- Clearer documentation.
These improvements have led to:
- Reduced code duplication.
- Improved modularity and readability.
- Easier future maintenance.
- Reduced code size.
Additional Optimizations Implemented:
-
Enhancement of the
handleActiveElementInsertionFunction:- Reduced conditional checks.
- Utilized destructuring to extract properties from elements.
- Implemented a better insertion strategy for contentEditable elements with fallback.
-
Optimization of the
insertTextIntoInputFunction:- Simplified validation conditions.
- Reduced code duplication for different insertion strategies.
- Used destructuring to extract element values.
- Calculated the new value only once regardless of the execution path.
-
Optimization of
updateBannerColorOptions:- Early exit if the banner is unavailable.
- Used a direct loop instead of
Object.keys().forEach(). - Simplified change verification.
-
Major Optimization of
handleStorageChanges:- Cached DOM selectors to avoid repeated queries.
- Employed a lazy-loading model for DOM elements.
- Grouped DOM manipulations within
requestAnimationFrame. - Optimized CSS animations.
- Implemented more robust error handling.
Benefits:
-
Better Performance:
- Fewer repetitive DOM operations.
- More efficient use of modern browser APIs.
- Reduced style recalculations and reflows.
-
More Robust Code:
- Improved error and edge-case checks.
- Reduced risk of diverging duplicated code.
- Enhanced error handling.
-
Easier Maintainability:
- More modular organization.
- Clearer separation of concerns.
- More readable code with explicit comments.
-
Resource Savings:
- Minimized object creation.
- Better memory utilization.
- Fewer garbage collection triggers.