XML to JSON Converter

Upload an XML file and convert it to JSON format, then display the result on the page

2023-04-05 기준 버전입니다. 최신 버전을 확인하세요.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         XML to JSON Converter
// @namespace    none
// @version      1.0.1
// @license MIT
// @description  Upload an XML file and convert it to JSON format, then display the result on the page
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // create a form for uploading files
    var form = document.createElement("form");
    form.style.margin = "20px";

    // create an input element for the file
    var fileInput = document.createElement("input");
    fileInput.type = "file";
    fileInput.name = "file";
    fileInput.accept = "application/xml";
    form.appendChild(fileInput);

    // create a submit button
    var submitButton = document.createElement("input");
    submitButton.type = "submit";
    submitButton.value = "Convert to JSON";
    form.appendChild(submitButton);

    // append the form to the body
    document.body.appendChild(form);

    // create a div for displaying the result
    var resultDiv = document.createElement("div");
    resultDiv.style.margin = "20px";
    document.body.appendChild(resultDiv);

    // add an event listener for form submission
    form.addEventListener("submit", function(event) {
        event.preventDefault();

        // create a new FormData object and add the file to it
        var formData = new FormData();
        formData.append("file", fileInput.files[0]);

        // send a POST request to the server to convert the file
        var xhr = new XMLHttpRequest();
        xhr.open("POST", "/convert", true);
        xhr.onload = function() {
            // display the result
            resultDiv.innerHTML = xhr.responseText;
        };
        xhr.send(formData);
    });
})();