-
Notifications
You must be signed in to change notification settings - Fork 12
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
Export, import, merge history #12
Comments
While it is not implemented you can manually import/export (history + settings) by running the follow code in the browser's console: The outdated versionTo 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), 8000);
} 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 code snippets: #12 (comment) |
On twitter the button is unclickable due to the twitter logo. Going to another site it allows me to click the button and select the file but nothing happens. |
It should be done exactly on Each "site" (origin) has its own LocalStorage database. Just checked it works fine for me. |
Also |
Ah, got it, it worked that time, thank you! |
You've got to be kidding me. This import overwrites existing entries and doesn't merge them?! I lost all my history again... |
Yes, this temporal workaround overwrites. I did not write, that it does merge: The merge option should be the third option (export, import and merge). |
Here is the new versions. With the merge code snippet. ONLY FOR THE OLD VERSIONTo 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] = JSON.parse(value);
return acc;
}, {});
downloadBlob(new Blob([JSON.stringify(exportObject)]), "ujs-tcas-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), 8000);
} To import: let importInput = document.createElement("input");
importInput.type = "file";
importInput.accept = "application/json";
document.body.prepend(importInput);
importInput.addEventListener("change", async event => {
const json = JSON.parse(await importInput.files[0].text());
console.log("json", json);
globalThis.json = json;
Object.entries(json).forEach(([key, value]) => {
localStorage.setItem(key, JSON.stringify(value));
});
});
importInput.click(); To merge: let mergeInput = document.createElement("input");
mergeInput.type = "file";
mergeInput.accept = "application/json";
document.body.prepend(mergeInput);
mergeInput.addEventListener("change", async event => {
const json = JSON.parse(await mergeInput.files[0].text());
console.log("json", json);
globalThis.json = json;
Object.entries(json).forEach(([key, value]) => {
const existedValue = JSON.parse(localStorage.getItem(key));
if (Array.isArray(existedValue)) {
value = [...new Set([...existedValue, ...value])];
}
localStorage.setItem(key, JSON.stringify(value));
});
});
mergeInput.click(); |
Finally, made it.
0838777 Migrate to new LocalStorage names |
I need to implement export, import, merge download history.
However, I need to totally refactor the related code. Make the
localStorage
values names more clear.Also I need to change the archive format for videos, since there multi-videos tweets.At least for new ones.
So, I need to keep for videos the new and old history arrays.
Temporary, you can use in the browsers console the follow code snippets: #12 (comment) for exporting, importing, merging the history.
Just open the browser's console on https://twitter.com and paste the required code snippet.
For importing/merging click on the web page first to focus the page of the web site.
The text was updated successfully, but these errors were encountered: