├── README.md └── convertor.php /README.md: -------------------------------------------------------------------------------- 1 | # Chrome Bookmarks Converter 2 | A script for converting Chrome bookmark.bak files to Chrome Bookmark.html files so you can import your bookmarks from your AppData file. 3 | 4 | I ran into a situation where I forgot to export my bookmarks from Chrome before doing a re-install of Windows. I grabbed my backup, and found that you could not directly import the bookmarks.bak file that Chrome uses to store your boookmarks. 5 | 6 | After looking at the strucutre I built a parser to convert the file to the .html format Chrome was happy to import. 7 | 8 | # How to Run 9 | 1. Add convertor.php to a server. 10 | 2. Upload your .bak file as bookmarks.txt (or rename in the script to match). 11 | 3. Run the script. 12 | 4. Your bookmarks will be converted, and saved as export.html 13 | 14 | # Notes 15 | I threw this together pretty quick, so it may not be most efficient or support ALL use-cases for .bak file. It is recursive so it will keep folder structures intact. 16 | -------------------------------------------------------------------------------- /convertor.php: -------------------------------------------------------------------------------- 1 | '; 6 | print_r($json->roots); 7 | echo ''; 8 | 9 | $header = ' 10 | 13 | 14 | Bookmarks 15 |

Bookmarks

16 |

'; 17 | 18 | $out = fopen("export.html", "w"); 19 | writeIt($header); 20 | 21 | if($json->roots->bookmark_bar){ 22 | 23 | writeIt('

Bookmarks bar

'); 24 | writeIt('

'); 25 | 26 | deeper($json->roots->bookmark_bar->children, 1, 10); 27 | 28 | writeIt('

'); 29 | 30 | } 31 | 32 | if($json->roots->other){ 33 | 34 | writeIt('

Other bookmarks

'); 35 | writeIt('

'); 36 | 37 | deeper($json->roots->other->children, 1, 10); 38 | 39 | writeIt('

'); 40 | 41 | } 42 | 43 | writeIt('

'); 44 | fclose($out); 45 | 46 | 47 | function deeper($array, $depth = 0, $max_depth = false){ 48 | 49 | if($max_depth && ($depth == $max_depth)) return; 50 | 51 | foreach($array as $node){ 52 | if(property_exists($node, 'children')){ 53 | writeIt('

' . $node->name . '

', $depth); 54 | writeIt('

', $depth); 55 | deeper($node->children, $depth + 1, $max_depth); 56 | writeIt('

', $depth); 57 | }else if(property_exists($node, 'url')){ 58 | writeIt('

' . $node->name . '', $depth); 59 | } 60 | } 61 | 62 | } 63 | 64 | function writeIt($line, $depth = 0){ 65 | global $out; 66 | 67 | $tab = " "; 68 | for($p=0;$p<$depth;$p++){ 69 | $prepend .= $tab; 70 | } 71 | 72 | fwrite($out, $prepend . $line . PHP_EOL); 73 | 74 | } 75 | 76 | 77 | 78 | ?> 79 | --------------------------------------------------------------------------------