Last active
August 30, 2023 08:12
-
-
Save kentliau/025bc927885cedfdb30ba3f7130be734 to your computer and use it in GitHub Desktop.
OneTab backup script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")}; | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Call within the console