index.html 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>JSON Viewer</title>
  7. <style>
  8. #jsonInput {
  9. width: 45%;
  10. height: 300px;
  11. margin-bottom: 10px;
  12. }
  13. #jsonOutput {
  14. width: 45%;
  15. height: 300px;
  16. margin-bottom: 10px;
  17. }
  18. #updateButton {
  19. display: block;
  20. margin-top: 10px;
  21. }
  22. </style>
  23. <script defer src="pretty-json-custom-element.js"></script>
  24. </head>
  25. <body>
  26. <h1>JSON Viewer</h1>
  27. <p><a href="https://github.com/wekan/wekan/issues/4877#issuecomment-2105688702">Source</a></p>
  28. <textarea id="jsonInput" placeholder="Enter Trello-JSON here: (Ctrl+V)&#10;&#10;In Trello go to ... menu and select 'Print, Export and Share'&#10;Select 'Export as JSON'&#10;Copy the whole text (Ctrl+A, Ctrl+C)"></textarea><br>
  29. <button id="updateButton">Convert from Trello to Wekan</button><br>
  30. <textarea id="jsonOutput" placeholder="Copy JSON for Wekan from here: (Ctrl+A, Ctrl+C)&#10;&#10;In Wekan go to 'all Boards', 'Add Board', 'Import', 'From Trello'" readonly></textarea>
  31. <script>
  32. document.getElementById("updateButton").addEventListener("click", function() {
  33. try {
  34. var jsonInput = document.getElementById("jsonInput").value;
  35. // replace colors with replaceAll
  36. jsonInput = jsonInput.replaceAll("green_dark", "green");
  37. jsonInput = jsonInput.replaceAll("red_dark", "red");
  38. // alter the json file structure
  39. var parsedJson = JSON.parse(jsonInput);
  40. // Iterate through the actions array
  41. parsedJson.actions.forEach(function(action) {
  42. // Check if the type is "addAttachmentToCard"
  43. if (action.type === "addAttachmentToCard") {
  44. // Store the value of data.attachment
  45. action.data.text = "**" + action.memberCreator.fullName + "**";
  46. action.data.text += "\nAdded: " + action.data.attachment.name + " " + action.data.attachment.url;
  47. action.data.textData = {};
  48. action.data.textData.emoji = {};
  49. delete action.data.attachment;
  50. action.type = "commentCard";
  51. } else if (action.type === "deleteAttachmentFromCard") {
  52. // Store the value of data.attachment
  53. action.data.text = "**" + action.memberCreator.fullName + "**";
  54. action.data.text += "\nRemoved: " + action.data.attachment.name;
  55. action.data.textData = {};
  56. action.data.textData.emoji = {};
  57. delete action.data.attachment;
  58. action.type = "commentCard";
  59. } else if (action.type === "commentCard") {
  60. action.data.text = "**" + action.memberCreator.fullName + "**\n" + action.data.text;
  61. }
  62. });
  63. // Iterate through the actions array
  64. parsedJson.cards.forEach(function(card) {
  65. for (var i=0; i<card.badges.attachments; i++) {
  66. card.desc += "\nAttachment: " + card.attachments[i].name + " " + card.attachments[i].url;
  67. }
  68. });
  69. var formattedJson = JSON.stringify(parsedJson, null, 4);
  70. document.getElementById("jsonOutput").value = formattedJson;
  71. } catch (error) {
  72. document.getElementById("jsonOutput").value = "Invalid JSON format!";
  73. }
  74. });
  75. </script>
  76. </body>
  77. </html>