Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Export Toby
// code courtesy of Toby team
chrome.storage.local.get("state", o => (
((f, t) => {
let e = document.createElement("a");
e.setAttribute("href", `data:text/plain;charset=utf-8,${encodeURIComponent(t)}`);
e.setAttribute("download", f);
e.click();
})(`TobyBackup${Date.now()}.json`, o.state)
));
@introspectionism

This comment has been minimized.

Copy link

@introspectionism introspectionism commented Feb 5, 2018

hi!

could you please elaborate on how you're using this for exporting toby data?
thanks!

cheers,
frode.

@correcto

This comment has been minimized.

Copy link

@correcto correcto commented Feb 22, 2018

I would also like to know. Thanks in advance!

@krishpop

This comment has been minimized.

Copy link
Owner Author

@krishpop krishpop commented Feb 22, 2018

@klevstul @correcto just run it in the chrome console window, and it should let you save a backup json

@AlcHawk

This comment has been minimized.

Copy link

@AlcHawk AlcHawk commented Feb 23, 2018

Thanks! This is really helpful!

@JPOak

This comment has been minimized.

Copy link

@JPOak JPOak commented Jul 9, 2018

Thanks for this. The reason I can't fully get onboard with Toby is that there is no export feature. Meaning that it would be very difficult to move away from it if you decide to in the future.

Your script worked great. Do you know of any process that I can use to make this readable for an import feature in Chrome or Firefox? Thanks.

@dwiehoff

This comment has been minimized.

Copy link

@dwiehoff dwiehoff commented Jul 21, 2018

@ShaklinSyed

This comment has been minimized.

Copy link

@ShaklinSyed ShaklinSyed commented Aug 13, 2018

Hi,

Just tried the script in the console. got Failed Network error.

@ac130kz

This comment has been minimized.

Copy link

@ac130kz ac130kz commented Aug 30, 2018

Works great! Thank you

@pythoninthegrass

This comment has been minimized.

Copy link

@pythoninthegrass pythoninthegrass commented Oct 18, 2018

Worked perfectly! Thanks so much, @krishpop

@hilaryfamiliar

This comment has been minimized.

Copy link

@hilaryfamiliar hilaryfamiliar commented Oct 21, 2018

Hi,

Just tried the script in the console. got Failed Network error.

I had the same issue until I saw my error mention 'local' so I tried running the script with Chrome open on a main Toby ~ dashboard ~ tab and it worked like a charm.

Much appreciated!

@pietervanw

This comment has been minimized.

Copy link

@pietervanw pietervanw commented Feb 14, 2019

Great piece of code, thanks a lot!

Is there an easy way to get a list of just the URLs?

http://url1.com
http://url2.com
http://url3.com
http://url4.com
http://url5.com
http://url6.com
http://url7.com
...
http://urln.com

@dwiehoff: To get a flat list of all the URL's in a JSON export, you can use a command-line tool like jq:

jq '.lists[].cards[].url' your_backup_file_name.json

You could also solve this in the Javascript code probably, but this got the job done for me.

(please note: not tested on any other version besides the JSON export I just created myself)

For more info on jq, see also:
https://stedolan.github.io/jq/
https://thoughtbot.com/blog/jq-is-sed-for-json

@jesstelford

This comment has been minimized.

Copy link

@jesstelford jesstelford commented May 11, 2019

For a simplified (and readable) JSON export, you can use this:

chrome.storage.local.get("state", ({ state }) => {
  const lists = JSON.parse(state).lists.map(({title, cards}) => ({
    title,
    cards: cards.map(({ customTitle, title, url }) => ({
      title: customTitle || title,
      url,
    })),
  }));

  let e = document.createElement("a");
  e.setAttribute("href", `data:text/plain;charset=utf-8,${encodeURIComponent(JSON.stringify(lists, null, 2))}`);
  e.setAttribute("download", `TobyBackup${Date.now()}.json`);
  e.click();
});

And for a human readable export to a text file (in markdown format), you can use this:

chrome.storage.local.get("state", ({ state }) => {
  const markdown = `
# Toby Export
${JSON.parse(state).lists.map(({title, cards}) => `## ${title}
${cards.map(({ customTitle, title, url }) => `- [${customTitle || title}](${url})`).join('\n')}`).join('\n\n')}`;
  let e = document.createElement("a");
  e.setAttribute("href", `data:text/plain;charset=utf-8,${encodeURIComponent(markdown)}`);
  e.setAttribute("download", `TobyBackup${Date.now()}.md`);
  e.click();
});

You can then open the .md file in any text editor, or copy+paste the export into a Markdown editor such as https://dillinger.io/ to get clickable links.

@jpsear

This comment has been minimized.

Copy link

@jpsear jpsear commented May 12, 2019

@jesstelford Fantastic, thank you!

@nickmadedesign

This comment has been minimized.

Copy link

@nickmadedesign nickmadedesign commented Jun 14, 2019

Great piece of code, thanks a lot!

Is there an easy way to get a list of just the URLs?

http://url1.com
http://url2.com
http://url3.com
http://url4.com
http://url5.com
http://url6.com
http://url7.com
...
http://urln.com

@dwiehoff: To get a flat list of all the URL's in a JSON export, you can use a command-line tool like jq:

jq '.lists[].cards[].url' your_backup_file_name.json

You could also solve this in the Javascript code probably, but this got the job done for me.

(please note: not tested on any other version besides the JSON export I just created myself)

For more info on jq, see also:
https://stedolan.github.io/jq/
https://thoughtbot.com/blog/jq-is-sed-for-json

@pietervanw Any thoughts on how to grab the URLs of a specific list by the title?

@pietervanw

This comment has been minimized.

Copy link

@pietervanw pietervanw commented Jun 15, 2019

@nickmadedesign:
with jq, try this:
jq '.lists[] | select(.title == "Name of the List") | .cards[].url' your_backup_file.json

To list all your lists, do this:
jq '.lists[].title' your_backup_file.json

Again, this can also be solved in JavaScript but if you like having a full backup and extracting your relevant data from that, then this would work.

@nickmadedesign

This comment has been minimized.

Copy link

@nickmadedesign nickmadedesign commented Jun 15, 2019

@nickmadedesign:
with jq, try this:
jq '.lists[] | select(.title == "Name of the List") | .cards[].url' your_backup_file.json

To list all your lists, do this:
jq '.lists[].title' your_backup_file.json

Again, this can also be solved in JavaScript but if you like having a full backup and extracting your relevant data from that, then this would work.

Ah, right. Perfect. Thank you!

@adriatic

This comment has been minimized.

Copy link

@adriatic adriatic commented Aug 25, 2019

I am counting that this thread is still visited by people who can help me. I was careless and have not created my account with Toby, so all of my saved URLs are on my local files system, created under the account name defined by my local logon to Chrome browser.

Yesterday, I had to logout from Chrome - and I forgot to check which account was used to create Toby list of URL. So getting back to use my Toby collections - I got this:

image

The screenshot indicates how I was perceived as a guest (of Toby), so I tried all of my Chrome accounts, to get to see my two pages worth of bookmarks, to no avail. Is there a way to get my painfully collected urls?

@fredthedead

This comment has been minimized.

Copy link

@fredthedead fredthedead commented Oct 12, 2019

Is there a way to do the inverse? take an export (in JSON for example) and inject it to Toby's local storage

@Natedude

This comment has been minimized.

Copy link

@Natedude Natedude commented Jan 9, 2020

put into chrome console and keep getting:

Uncaught TypeError: Cannot read property ‘local’ of undefined at :1:16

@dorelljames

This comment has been minimized.

Copy link

@dorelljames dorelljames commented Feb 8, 2020

Thanks for this. Do you guys know how to import the exported collection to say a new account?

@rifaterdemsahin

This comment has been minimized.

Copy link

@rifaterdemsahin rifaterdemsahin commented May 2, 2020

chrome.storage.local.get("state", o => (
((f, t) => {
let e = document.createElement("a");
e.setAttribute("href", 'data:text/plain;charset=utf-8,${encodeURIComponent(t)}');
e.setAttribute("download", f);
e.click();
})('TobyBackup${Date.now()}.json', o.state)
));
VM44:1 Uncaught TypeError: Cannot read property 'local' of undefined
at :1:16

@rifaterdemsahin

This comment has been minimized.

Copy link

@rifaterdemsahin rifaterdemsahin commented May 2, 2020

dummy me it got resolved when i ran it in toby page ^^^

@cjj1120

This comment has been minimized.

Copy link

@cjj1120 cjj1120 commented Jun 3, 2020

put into chrome console and keep getting:

Uncaught TypeError: Cannot read property ‘local’ of undefined at :1:16

u gotta open Toby tab, ctrl shift J, copy paste the command, then it will prompt n download ur saved URL

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