11import { CONFIG } from './content/config'
22import { logger } from './content/logger'
33import { injectStyles } from './content/styles'
4+ import OverType from 'overtype'
45
56export default defineContentScript ( {
67 main ( ) {
78 const textAreasOnPageLoad = document . querySelectorAll < HTMLTextAreaElement > ( `textarea` )
89 for ( const textarea of textAreasOnPageLoad ) {
9- initializeMaybe ( textarea )
10+ initializeTextArea ( textarea )
1011 }
1112 const observer = new MutationObserver ( handleMutations )
1213 observer . observe ( document . body , {
@@ -25,19 +26,16 @@ function handleMutations(mutations: MutationRecord[]): void {
2526 if ( node . nodeType === Node . ELEMENT_NODE ) {
2627 const element = node as Element
2728 if ( element . tagName === 'textarea' ) {
28- initializeMaybe ( element as HTMLTextAreaElement )
29+ initializeTextArea ( element as HTMLTextAreaElement )
2930 }
3031 }
3132 }
3233 }
3334}
3435
35- function initializeMaybe ( textarea : HTMLTextAreaElement ) {
36- if ( ! textarea . classList . contains ( CONFIG . ADDED_OVERTYPE_CLASS ) ) {
37- logger . debug ( 'activating textarea {}' , textarea )
38- injectStyles ( )
39- textarea . classList . add ( CONFIG . ADDED_OVERTYPE_CLASS )
40- } else {
41- logger . debug ( 'already activated textarea {}' , textarea )
42- }
36+ function initializeTextArea ( textarea : HTMLTextAreaElement ) {
37+ logger . debug ( 'activating textarea {}' , textarea )
38+ const overtype = new OverType ( textarea ) [ 0 ]
39+ logger . debug ( 'overtype initialized {}' , overtype )
40+ overtype . setValue ( "Testing 1, 2, 3" )
4341}
0 commit comments