XML to JSON Converter

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

Stan na 05-04-2023. Zobacz najnowsza wersja.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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);
    });
})();