@@ -2,21 +2,21 @@ import { CONFIG } from '../common/config'
22import { logger } from '../common/logger'
33import { EnhancerRegistry , TextareaRegistry } from '../datamodel/registries'
44
5- const handlerRegistry = new EnhancerRegistry ( )
6- const textareaRegistry = new TextareaRegistry ( )
5+ const enhancers = new EnhancerRegistry ( )
6+ const enhancedTextareas = new TextareaRegistry ( )
77
88export default defineContentScript ( {
99 main ( ) {
1010 const textAreasOnPageLoad = document . querySelectorAll < HTMLTextAreaElement > ( `textarea` )
1111 for ( const textarea of textAreasOnPageLoad ) {
12- initializeMaybeIsPageload ( textarea )
12+ enhanceMaybe ( textarea )
1313 }
1414 const observer = new MutationObserver ( handleMutations )
1515 observer . observe ( document . body , {
1616 childList : true ,
1717 subtree : true ,
1818 } )
19- logger . debug ( 'Extension loaded with' , handlerRegistry . getAllHandlers ( ) . length , 'handlers' )
19+ logger . debug ( 'Extension loaded with' , enhancers . getAllHandlers ( ) . length , 'handlers' )
2020 } ,
2121 matches : [ '<all_urls>' ] ,
2222 runAt : 'document_end' ,
@@ -29,13 +29,13 @@ function handleMutations(mutations: MutationRecord[]): void {
2929 if ( node . nodeType === Node . ELEMENT_NODE ) {
3030 const element = node as Element
3131 if ( element . tagName === 'TEXTAREA' ) {
32- initializeMaybeIsPageload ( element as HTMLTextAreaElement )
32+ enhanceMaybe ( element as HTMLTextAreaElement )
3333 } else {
3434 // Also check for textareas within added subtrees
3535 const textareas = element . querySelectorAll ?.( 'textarea' )
3636 if ( textareas ) {
3737 for ( const textarea of textareas ) {
38- initializeMaybeIsPageload ( textarea )
38+ enhanceMaybe ( textarea )
3939 }
4040 }
4141 }
@@ -47,13 +47,13 @@ function handleMutations(mutations: MutationRecord[]): void {
4747 if ( node . nodeType === Node . ELEMENT_NODE ) {
4848 const element = node as Element
4949 if ( element . tagName === 'TEXTAREA' ) {
50- textareaRegistry . unregisterDueToModification ( element as HTMLTextAreaElement )
50+ enhancedTextareas . unregisterDueToModification ( element as HTMLTextAreaElement )
5151 } else {
5252 // Also check for textareas within removed subtrees
5353 const textareas = element . querySelectorAll ?.( 'textarea' )
5454 if ( textareas ) {
5555 for ( const textarea of textareas ) {
56- textareaRegistry . unregisterDueToModification ( textarea )
56+ enhancedTextareas . unregisterDueToModification ( textarea )
5757 }
5858 }
5959 }
@@ -62,9 +62,9 @@ function handleMutations(mutations: MutationRecord[]): void {
6262 }
6363}
6464
65- function initializeMaybeIsPageload ( textarea : HTMLTextAreaElement ) {
65+ function enhanceMaybe ( textarea : HTMLTextAreaElement ) {
6666 // Check if this textarea is already registered
67- if ( textareaRegistry . get ( textarea ) ) {
67+ if ( enhancedTextareas . get ( textarea ) ) {
6868 logger . debug ( 'textarea already registered {}' , textarea )
6969 return
7070 }
@@ -73,10 +73,14 @@ function initializeMaybeIsPageload(textarea: HTMLTextAreaElement) {
7373 injectStyles ( )
7474
7575 // Use registry to identify and handle this specific textarea
76- const textareaInfo = handlerRegistry . identifyTextarea ( textarea )
77- if ( textareaInfo ) {
78- logger . debug ( 'Identified textarea:' , textareaInfo . context . type , textareaInfo . context . unique_key )
79- textareaRegistry . register ( textareaInfo )
76+ const enhancedTextarea = enhancers . identifyTextarea ( textarea )
77+ if ( enhancedTextarea ) {
78+ logger . debug (
79+ 'Identified textarea:' ,
80+ enhancedTextarea . context . type ,
81+ enhancedTextarea . context . unique_key ,
82+ )
83+ enhancedTextareas . register ( enhancedTextarea )
8084 } else {
8185 logger . debug ( 'No handler found for textarea' )
8286 }
0 commit comments