@@ -105,17 +105,20 @@ OutputWaiter.prototype.setOutputInfo = function(length, lines, duration) {
105105OutputWaiter . prototype . adjustWidth = function ( ) {
106106 const output = document . getElementById ( "output" ) ;
107107 const saveToFile = document . getElementById ( "save-to-file" ) ;
108+ const copyOutput = document . getElementById ( "copy-output" ) ;
108109 const switchIO = document . getElementById ( "switch" ) ;
109110 const undoSwitch = document . getElementById ( "undo-switch" ) ;
110111 const maximiseOutput = document . getElementById ( "maximise-output" ) ;
111112
112113 if ( output . clientWidth < 680 ) {
113114 saveToFile . childNodes [ 1 ] . nodeValue = "" ;
115+ copyOutput . childNodes [ 1 ] . nodeValue = "" ;
114116 switchIO . childNodes [ 1 ] . nodeValue = "" ;
115117 undoSwitch . childNodes [ 1 ] . nodeValue = "" ;
116118 maximiseOutput . childNodes [ 1 ] . nodeValue = "" ;
117119 } else {
118120 saveToFile . childNodes [ 1 ] . nodeValue = " Save to file" ;
121+ copyOutput . childNodes [ 1 ] . nodeValue = " Copy output" ;
119122 switchIO . childNodes [ 1 ] . nodeValue = " Move output to input" ;
120123 undoSwitch . childNodes [ 1 ] . nodeValue = " Undo" ;
121124 maximiseOutput . childNodes [ 1 ] . nodeValue =
@@ -147,6 +150,44 @@ OutputWaiter.prototype.saveClick = function() {
147150} ;
148151
149152
153+ /**
154+ * Handler for copy click events.
155+ * Copies the output to the clipboard.
156+ */
157+ OutputWaiter . prototype . copyClick = function ( ) {
158+ // Create invisible textarea to populate with the raw dishStr (not the printable version that
159+ // contains dots instead of the actual bytes)
160+ const textarea = document . createElement ( "textarea" ) ;
161+ textarea . style . position = "fixed" ;
162+ textarea . style . top = 0 ;
163+ textarea . style . left = 0 ;
164+ textarea . style . width = 0 ;
165+ textarea . style . height = 0 ;
166+ textarea . style . border = "none" ;
167+
168+ textarea . value = this . app . dishStr ;
169+ document . body . appendChild ( textarea ) ;
170+
171+ // Select and copy the contents of this textarea
172+ let success = false ;
173+ try {
174+ textarea . select ( ) ;
175+ success = document . execCommand ( "copy" ) ;
176+ } catch ( err ) {
177+ success = false ;
178+ }
179+
180+ if ( success ) {
181+ this . app . alert ( "Copied raw output successfully." , "success" , 2000 ) ;
182+ } else {
183+ this . app . alert ( "Sorry, the output could not be copied." , "danger" , 2000 ) ;
184+ }
185+
186+ // Clean up
187+ document . body . removeChild ( textarea ) ;
188+ } ;
189+
190+
150191/**
151192 * Handler for switch click events.
152193 * Moves the current output into the input textarea.
0 commit comments