Skip to content

Instantly share code, notes, and snippets.

@kentliau
Last active August 30, 2023 08:12
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save kentliau/025bc927885cedfdb30ba3f7130be734 to your computer and use it in GitHub Desktop.
Save kentliau/025bc927885cedfdb30ba3f7130be734 to your computer and use it in GitHub Desktop.
OneTab backup script
function backup() {
function downloadBlob(filename, blobUrl) {
var element = document.createElement('a');
element.setAttribute('href', blobUrl);
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
var now = new Date();
var date = "";
date += now.getFullYear();
date += ( (now.getMonth() + 1) < 10 ? "0" + (now.getMonth() + 1) : (now.getMonth() + 1) );
date += ( now.getDate() < 10 ? "0" + now.getDate() : now.getDate() );
date += "_";
date += ( now.getHours() < 10 ? "0" + now.getHours() : now.getHours() );
date += ( now.getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes() );
var jsonStateBlobURL = URL.createObjectURL(new Blob([localStorage.state], {type: "text/plain"}));
var jsonTopSiteBlobURL = URL.createObjectURL(new Blob([localStorage.topSites], {type: "text/plain"}));
var htmlBlobURL = URL.createObjectURL(new Blob([document.documentElement.outerHTML], {type: "text/plain"}));
downloadBlob(date+"_state.json", jsonStateBlobURL);
downloadBlob(date+"_topSites.json", jsonTopSiteBlobURL);
downloadBlob(date+".html", htmlBlobURL);
}
// Bookmarklet
// Make a new bookmark, copy and paste the string below to the url field.
/*
javascript:if(window.location.toString() == "chrome-extension://chphlpgkkbolifaimnlloiipkdnihall/onetab.html"){function backup() {function downloadBlob(filename, blobUrl) {var element = document.createElement('a');element.setAttribute('href', blobUrl);element.setAttribute('download', filename);element.style.display = 'none';document.body.appendChild(element);element.click();document.body.removeChild(element);};var now = new Date();var date = "";date += now.getFullYear();date += ( (now.getMonth() + 1) < 10 ? "0" + (now.getMonth() + 1) : (now.getMonth() + 1) );date += ( now.getDate() < 10 ? "0" + now.getDate() : now.getDate() );date += "_";date += ( now.getHours() < 10 ? "0" + now.getHours() : now.getHours() );date += ( now.getMinutes() < 10 ? "0" + now.getMinutes() : now.getMinutes() );var jsonStateBlobURL = URL.createObjectURL(new Blob([localStorage.state], {type: "text/plain"}));var jsonTopSiteBlobURL = URL.createObjectURL(new Blob([localStorage.topSites], {type: "text/plain"}));var htmlBlobURL = URL.createObjectURL(new Blob([document.documentElement.outerHTML], {type: "text/plain"}));downloadBlob(date+"_state.json", jsonStateBlobURL);downloadBlob(date+"_topSites.json", jsonTopSiteBlobURL);downloadBlob(date+".html", htmlBlobURL);}backup();}else{console.log("did nothing")};
*/
@kentliau
Copy link
Author

Call within the console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment