@@ -73,12 +73,31 @@ async function populateCodeJson(data) {
7373 return codeJson ;
7474}
7575
76- // Creates code.json and triggers file download
77- async function downloadFile ( data ) {
76+ // Creates code.json object
77+ async function createCodeJson ( data ) {
7878 delete data . submit ;
7979 const codeJson = await populateCodeJson ( data ) ;
8080
8181 const jsonString = JSON . stringify ( codeJson , null , 2 ) ;
82+ document . getElementById ( "json-result" ) . value = jsonString ;
83+ }
84+
85+ // Copies code.json to clipboard
86+ async function copyToClipboard ( event ) {
87+ event . preventDefault ( ) ;
88+
89+ var textArea = document . getElementById ( "json-result" ) ;
90+ textArea . select ( ) ;
91+ document . execCommand ( "copy" )
92+ }
93+
94+ // Triggers local file download
95+ async function downloadFile ( event ) {
96+ event . preventDefault ( ) ;
97+
98+ const codeJson = document . getElementById ( "json-result" ) . value
99+ const jsonObject = JSON . parse ( codeJson ) ;
100+ const jsonString = JSON . stringify ( jsonObject , null , 2 ) ;
82101 const blob = new Blob ( [ jsonString ] , { type : "application/json" } ) ;
83102
84103 // Create anchor element and create download link
@@ -90,4 +109,6 @@ async function downloadFile(data) {
90109 link . click ( ) ;
91110}
92111
112+ window . createCodeJson = createCodeJson ;
113+ window . copyToClipboard = copyToClipboard ;
93114window . downloadFile = downloadFile ;
0 commit comments