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

[Question] Export already saved tweet database to another browser? #17

Closed
biggestsonicfan opened this issue Oct 24, 2022 · 3 comments
Closed
Labels
question Further information is requested

Comments

@biggestsonicfan
Copy link

I'm upgrading my hard disk and doing a fresh distro install. I'd like to be able to transfer which tweets have already been saved to my new Firefox install but I'm not really sure where the tampermonkey data is stored for tcas.

Is it a straightforward process and my google-fu is just failing me?

@AlttiRi
Copy link
Owner

AlttiRi commented Oct 24, 2022

I currently did not implemented this #12

It stores the data in LocalStorage.
You can manually copy it from the old browser to the new one.
See "ujs-..." values.

OK, I will write the temporal script to simplify the manual work.

@AlttiRi
Copy link
Owner

AlttiRi commented Oct 24, 2022

The outdated version

To export:

let exportObject = [
    "ujs-click-n-save-settings",
    "ujs-images-history-by",
    "ujs-twitter-downloaded-images-names",
    "ujs-twitter-downloaded-image-tweet-ids", 
    "ujs-twitter-downloaded-video-tweet-ids"
    ].reduce((acc, name) => {
        const value = localStorage.getItem(name);
        if (value === null) {
            return acc;
        }
        acc[name] = localStorage.getItem(name);
        return acc;
    }, {});
downloadBlob(new Blob([JSON.stringify(exportObject)]), "ujs-c'n's-export.json");
function downloadBlob(blob, name, url) {
    const anchor = document.createElement("a");
    anchor.setAttribute("download", name || "");
    const blobUrl = URL.createObjectURL(blob);
    anchor.href = blobUrl + (url ? ("#" + url) : "");
    anchor.click();
    setTimeout(() => URL.revokeObjectURL(blobUrl), 30000);
}

To import:

let input = document.createElement("input");
input.type = "file";
input.accept = "application/json";
document.body.prepend(input);
input.addEventListener("change", async event => {
    const json = JSON.parse(await input.files[0].text());

    console.log("json", json);
    globalThis.json = json;

    Object.entries(json).forEach(([key, value]) => {
        localStorage.setItem(key, value);
    });
});
input.click();

The new version is here: #12 (comment)

@biggestsonicfan
Copy link
Author

OH whoops, didn't see the issue was already open, LOL! Closing as duplicate!

@AlttiRi AlttiRi added the question Further information is requested label Nov 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants