7373button .remove : hover {
7474 background : # d62d20 ;
7575}
76+
77+ button .quote {
78+ background : # 34c759 ;
79+ }
80+
81+ button .quote : hover {
82+ background : # 28a745 ;
83+ }
84+
85+ button .hidden {
86+ display : none;
87+ }
7688</ style >
7789</ head >
7890< body >
@@ -85,6 +97,8 @@ <h1>Text indentation tool</h1>
8597 < button id ="remove2 " class ="remove "> Remove 2 spaces</ button >
8698 < button id ="remove4 " class ="remove "> Remove 4 spaces</ button >
8799 < button id ="removeIndent " class ="remove "> Remove all indentation</ button >
100+ < button id ="quote " class ="quote "> Quote</ button >
101+ < button id ="unquote " class ="remove hidden "> Unquote</ button >
88102 </ div >
89103</ div >
90104
@@ -95,26 +109,51 @@ <h1>Text indentation tool</h1>
95109const indent4Btn = document . getElementById ( 'indent4' ) ;
96110const remove2Btn = document . getElementById ( 'remove2' ) ;
97111const remove4Btn = document . getElementById ( 'remove4' ) ;
112+ const quoteBtn = document . getElementById ( 'quote' ) ;
113+ const unquoteBtn = document . getElementById ( 'unquote' ) ;
114+
115+ function updateQuoteButtons ( ) {
116+ const text = textInput . value ;
117+ if ( ! text . trim ( ) ) {
118+ unquoteBtn . classList . add ( 'hidden' ) ;
119+ return ;
120+ }
121+
122+ const lines = text . split ( '\n' ) ;
123+ const nonEmptyLines = lines . filter ( line => line . trim ( ) . length > 0 ) ;
124+ const allQuoted = nonEmptyLines . length > 0 && nonEmptyLines . every ( line => line . startsWith ( '> ' ) ) ;
125+
126+ if ( allQuoted ) {
127+ unquoteBtn . classList . remove ( 'hidden' ) ;
128+ } else {
129+ unquoteBtn . classList . add ( 'hidden' ) ;
130+ }
131+ }
132+
133+ textInput . addEventListener ( 'input' , updateQuoteButtons ) ;
98134
99135removeIndentBtn . addEventListener ( 'click' , ( ) => {
100136 const text = textInput . value ;
101137 const lines = text . split ( '\n' ) ;
102138 const processed = lines . map ( line => line . replace ( / ^ \s + / , '' ) ) . join ( '\n' ) ;
103139 textInput . value = processed ;
140+ updateQuoteButtons ( ) ;
104141} ) ;
105142
106143indent2Btn . addEventListener ( 'click' , ( ) => {
107144 const text = textInput . value ;
108145 const lines = text . split ( '\n' ) ;
109146 const processed = lines . map ( line => ' ' + line ) . join ( '\n' ) ;
110147 textInput . value = processed ;
148+ updateQuoteButtons ( ) ;
111149} ) ;
112150
113151indent4Btn . addEventListener ( 'click' , ( ) => {
114152 const text = textInput . value ;
115153 const lines = text . split ( '\n' ) ;
116154 const processed = lines . map ( line => ' ' + line ) . join ( '\n' ) ;
117155 textInput . value = processed ;
156+ updateQuoteButtons ( ) ;
118157} ) ;
119158
120159remove2Btn . addEventListener ( 'click' , ( ) => {
@@ -127,6 +166,7 @@ <h1>Text indentation tool</h1>
127166 return line ;
128167 } ) . join ( '\n' ) ;
129168 textInput . value = processed ;
169+ updateQuoteButtons ( ) ;
130170} ) ;
131171
132172remove4Btn . addEventListener ( 'click' , ( ) => {
@@ -139,7 +179,32 @@ <h1>Text indentation tool</h1>
139179 return line ;
140180 } ) . join ( '\n' ) ;
141181 textInput . value = processed ;
182+ updateQuoteButtons ( ) ;
142183} ) ;
184+
185+ quoteBtn . addEventListener ( 'click' , ( ) => {
186+ const text = textInput . value ;
187+ const lines = text . split ( '\n' ) ;
188+ const processed = lines . map ( line => '> ' + line ) . join ( '\n' ) ;
189+ textInput . value = processed ;
190+ updateQuoteButtons ( ) ;
191+ } ) ;
192+
193+ unquoteBtn . addEventListener ( 'click' , ( ) => {
194+ const text = textInput . value ;
195+ const lines = text . split ( '\n' ) ;
196+ const processed = lines . map ( line => {
197+ if ( line . startsWith ( '> ' ) ) {
198+ return line . slice ( 2 ) ;
199+ }
200+ return line ;
201+ } ) . join ( '\n' ) ;
202+ textInput . value = processed ;
203+ updateQuoteButtons ( ) ;
204+ } ) ;
205+
206+ // Initial check
207+ updateQuoteButtons ( ) ;
143208</ script >
144209</ body >
145210</ html >
0 commit comments