Skip to content

Instantly share code, notes, and snippets.

@mi-lee
Last active June 27, 2018 23:01
Show Gist options
  • Save mi-lee/c705c4ec2a12405fcc12f3147d6d8fe9 to your computer and use it in GitHub Desktop.
Save mi-lee/c705c4ec2a12405fcc12f3147d6d8fe9 to your computer and use it in GitHub Desktop.
Backup OneTab Links (bookmarklet) - Saves a JSON blob of all your OneTab data to disk
javascript:!function(e){e.save=function(o,n){o||e.error("Console.save: No data"),n||(n="console.json"),"object"==typeof o&&(o=JSON.stringify(o,void 0,4));var t=new Blob([o],{type:"text/json"}),a=document.createEvent("MouseEvents"),c=document.createElement("a");c.download=n,c.href=window.URL.createObjectURL(t),c.dataset.downloadurl=["text/json",c.download,c.href].join(":"),a.initMouseEvent("click",!0,!1,window,0,0,0,0,0,!1,!1,!1,!1,0,null),c.dispatchEvent(a)}}(console),console.save(localStorage.state,"OneTabBackup.json");
// Unminified version below:
(function(console) {
console.save = function(data, filename) {
if (!data) {
console.error('Console.save: No data');
}
if (!filename) {
filename = 'console.json';
}
if (typeof data === "object") {
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {
type: 'text/json'
}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a');
a.download = filename;
a.href = window.URL.createObjectURL(blob);
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':');
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
a.dispatchEvent(e);
}
})(console);
console.save(localStorage.state, "OneTab.json")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment