@@ -2,19 +2,28 @@ import OverType from "../overtype/overtype";
22
33export default defineContentScript ( {
44 main ( ) {
5- const ghCommentBox = document . getElementById ( "new_comment_field" ) ! ;
6- ghCommentBox . classList . add ( "overtype-input" ) ;
7- const previewDiv = document . createElement ( "div" ) ;
8- previewDiv . classList . add ( "overtype-preview" ) ;
9- ghCommentBox . insertAdjacentElement ( "afterend" , previewDiv ) ;
10- const ghCommentWrapper = ghCommentBox . parentElement ! . closest ( "div" ) ! ;
11- ghCommentWrapper . classList . add ( "overtype-wrapper" ) ;
12- const ghCommentContainer = ghCommentWrapper . parentElement ! . closest ( "div" ) ! ;
13- ghCommentContainer . classList . add ( "overtype-container" ) ;
14- new OverType ( ghCommentContainer . parentElement ! . closest ( "div" ) ! , {
15- placeholder : "Add your comment here..." ,
16- } ) ;
5+ const ghCommentBox = document . getElementById ( "new_comment_field" ) as
6+ | HTMLTextAreaElement
7+ | undefined ;
8+ if ( ghCommentBox ) {
9+ const overtypeContainer = modifyGithubDOM ( ghCommentBox ) ;
10+ new OverType ( overtypeContainer , {
11+ placeholder : "Add your comment here..." ,
12+ } ) ;
13+ }
1714 } ,
1815 matches : [ "<all_urls>" ] ,
1916 runAt : "document_end" ,
2017} ) ;
18+
19+ function modifyGithubDOM ( ghCommentBox : HTMLTextAreaElement ) {
20+ ghCommentBox . classList . add ( "overtype-input" ) ;
21+ const previewDiv = document . createElement ( "div" ) ;
22+ previewDiv . classList . add ( "overtype-preview" ) ;
23+ ghCommentBox . insertAdjacentElement ( "afterend" , previewDiv ) ;
24+ const ghCommentWrapper = ghCommentBox . parentElement ! . closest ( "div" ) ! ;
25+ ghCommentWrapper . classList . add ( "overtype-wrapper" ) ;
26+ const ghCommentContainer = ghCommentWrapper . parentElement ! . closest ( "div" ) ! ;
27+ ghCommentContainer . classList . add ( "overtype-container" ) ;
28+ return ghCommentContainer . parentElement ! . closest ( "div" ) ! ;
29+ }
0 commit comments