tspb commited on
Commit
134f09f
·
verified ·
1 Parent(s): 4bfb33c

Update index.html

Browse files

add copy and save button

Files changed (1) hide show
  1. index.html +33 -3
index.html CHANGED
@@ -239,8 +239,10 @@
239
  <button id="convertButton">Convert</button>
240
 
241
  <div class="output">
242
- <h2>Converted Risu JSON:</h2>
243
- <pre id="stOutput"></pre>
 
 
244
  </div>
245
  </div>
246
 
@@ -263,6 +265,34 @@
263
  </div>
264
 
265
  <script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  // ST to Risu Converter Logic
267
  document.getElementById('convertButton').addEventListener('click', function convert() {
268
  try {
@@ -599,4 +629,4 @@ async function recoverPresetFromFile(file) {
599
  });
600
  </script>
601
  </body>
602
- </html>
 
239
  <button id="convertButton">Convert</button>
240
 
241
  <div class="output">
242
+ <h2>Converted Risu JSON:</h2>
243
+ <button id="copyButton">Copy</button>
244
+ <button id="saveButton">Save as JSON</button>
245
+ <pre id="stOutput"></pre>
246
  </div>
247
  </div>
248
 
 
265
  </div>
266
 
267
  <script>
268
+
269
+ // Copy button functionality
270
+ document.getElementById("copyButton").addEventListener("click", function() {
271
+ const outputText = document.getElementById("stOutput").textContent;
272
+ navigator.clipboard.writeText(outputText).then(function() {
273
+ alert("Copied to clipboard!");
274
+ }).catch(function(err) {
275
+ alert("Failed to copy text: " + err);
276
+ });
277
+ });
278
+
279
+ // Save as JSON button functionality
280
+ document.getElementById("saveButton").addEventListener("click", function() {
281
+ const outputText = document.getElementById("stOutput").textContent;
282
+
283
+ // Ensure the output is valid JSON
284
+ try {
285
+ const jsonObject = JSON.parse(outputText); // Validate JSON format
286
+ const blob = new Blob([JSON.stringify(jsonObject, null, 2)], { type: 'application/json' });
287
+ const link = document.createElement('a');
288
+ link.href = URL.createObjectURL(blob);
289
+ link.download = 'converted_risu.json'; // File name
290
+ link.click();
291
+ } catch (error) {
292
+ alert("The output is not valid JSON.");
293
+ }
294
+ });
295
+
296
  // ST to Risu Converter Logic
297
  document.getElementById('convertButton').addEventListener('click', function convert() {
298
  try {
 
629
  });
630
  </script>
631
  </body>
632
+ </html>