Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Export/Import Local Storage Data #5

Open
bakinazik opened this issue May 27, 2024 · 2 comments
Open

Feature Request: Export/Import Local Storage Data #5

bakinazik opened this issue May 27, 2024 · 2 comments

Comments

@bakinazik
Copy link

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
Copy link
Owner

Owyn commented May 27, 2024

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants