Owyn / Universal_Dark_Theme

browser userscript (extension) to apply a simple Dark Theme style for any website which you can configure per-site
10 stars 6 forks source link

Feature Request: Export/Import Local Storage Data #5

Open bakinazik opened 1 month ago

bakinazik commented 1 month ago

It will be more functional if you put backup buttons on the configuration page.

A simple example, maybe it will help.

(function() {
    'use strict';

    // Export Button
    let exportButton = document.createElement("button");
    exportButton.innerHTML = "Export";
    exportButton.style.position = "fixed";
    exportButton.style.top = "10px";
    exportButton.style.right = "10px";
    exportButton.style.zIndex = "1000";
    exportButton.onclick = function() {
        let data = JSON.stringify(localStorage);
        let blob = new Blob([data], { type: 'application/json' });
        let url = URL.createObjectURL(blob);
        let a = document.createElement('a');
        a.href = url;
        a.download = 'localStorageData.json';
        a.click();
        URL.revokeObjectURL(url);
    };
    document.body.appendChild(exportButton);

    // Import Button
    let importButton = document.createElement("button");
    importButton.innerHTML = "Import";
    importButton.style.position = "fixed";
    importButton.style.top = "50px";
    importButton.style.right = "10px";
    importButton.style.zIndex = "1000";
    importButton.onclick = function() {
        let input = document.createElement('input');
        input.type = 'file';
        input.accept = 'application/json';
        input.onchange = function(event) {
            let file = event.target.files[0];
            let reader = new FileReader();
            reader.onload = function(e) {
                let data = JSON.parse(e.target.result);
                for (let key in data) {
                    localStorage.setItem(key, data[key]);
                }
                alert('Imported!');
            };
            reader.readAsText(file);
        };
        input.click();
    };
    document.body.appendChild(importButton);
})();
Owyn commented 1 month ago

Interesting, yea backing up localstorage would certainly do the thing, I'm just not sure how much more useful it is compared to just selecting your excludes \ css and pressing ctrl+a, ctrl+c then putting it into a text file

bakinazik commented 1 month ago

There are three places to copy.. the backup option is probably much more useful than manual copy paste. After all, I don't think anyone who uses userscript is an end user. Therefore, I do not see it as a very important and necessary feature. It's up to you. If you have some free time you can add it, otherwise don't bother.