@@ -9,5 +9,40 @@ export function modifyDOM(overtypeInput: HTMLTextAreaElement): HTMLElement {
99 overtypeInput . placeholder = 'Add your comment here...'
1010 const overtypeContainer = overtypeWrapper . parentElement ! . closest ( 'div' ) !
1111 overtypeContainer . classList . add ( 'overtype-container' )
12+
13+ // Watch for class changes and restore if removed
14+ const observer = new MutationObserver ( ( mutations ) => {
15+ mutations . forEach ( ( mutation ) => {
16+ if ( mutation . type === 'attributes' && mutation . attributeName === 'class' ) {
17+ if ( ! overtypeContainer . classList . contains ( 'overtype-container' ) ) {
18+ overtypeContainer . classList . add ( 'overtype-container' )
19+ }
20+ }
21+ } )
22+ } )
23+
24+ observer . observe ( overtypeContainer , {
25+ attributeFilter : [ 'class' ] ,
26+ attributes : true ,
27+ } )
28+
29+ // Find the button that contains the text "Preview"
30+ const writePreviewTabs = Array . from (
31+ ( overtypeContainer . firstElementChild as HTMLElement ) . querySelectorAll ( 'button' ) ,
32+ )
33+ const writeTab = writePreviewTabs . find ( ( button ) => button . textContent . includes ( 'Write' ) )
34+ const previewTab = writePreviewTabs . find ( ( button ) => button . textContent . includes ( 'Preview' ) )
35+
36+ if ( writeTab && previewTab ) {
37+ // Hide the textarea when the user is on the "Preview" tab
38+ writeTab . addEventListener ( 'click' , ( ) => {
39+ overtypeWrapper . style . display = 'inline-block'
40+ } )
41+
42+ previewTab . addEventListener ( 'click' , ( ) => {
43+ overtypeWrapper . style . display = 'none'
44+ } )
45+ }
46+
1247 return overtypeContainer . parentElement ! . closest ( 'div' ) !
1348}
0 commit comments