#937·dillinger

[feature] Add an import export of the whole sessions.

Author: 0wwafaCreated Jul 3, 2026Updated Jul 18, 2026

I have many open documents in dillinger. Since they are saved in localStorage, a nice function would be to backup/restore them individually or all together.

Something like:

(function() {
    const data = JSON.stringify(localStorage, null, 2);
    const blob = new Blob([data], { type: "application/json" });
    const url = URL.createObjectURL(blob);

    const today = new Date().toISOString().split('T')[0];

    const a = document.createElement("a");
    a.href = url;

    a.download = `${window.location.hostname}-backup-${today}.json`;
    document.body.appendChild(a);
    a.click();

    // Clean up
    document.body.removeChild(a);
    URL.revokeObjectURL(url);
})();

and

(function() {
    const fileInput = document.createElement('input');
    fileInput.type = 'file';
    fileInput.accept = '.json';
    fileInput.style.display = 'none';

    fileInput.onchange = e => {
        const file = e.target.files[0];
        if (!file) return;

        const reader = new FileReader();
        reader.onload = readerEvent => {
            try {
                const content = readerEvent.target.result;
                const data = JSON.parse(content);

                localStorage.clear();

                // Restore the keys
                Object.keys(data).forEach(key => {
                    localStorage.setItem(key, data[key]);
                });

                document.location.reload(true);
            } catch (error) {
                console.error("Error parsing the backup file. Is it a valid JSON?", error);
            }
        };

        reader.readAsText(file);
    };

    document.body.appendChild(fileInput);
    fileInput.click();

    document.body.removeChild(fileInput);
})();