Created
March 24, 2023 21:33
-
-
Save kevinfjbecker/81bd1dc5f72f2ea2672771f284bfb640 to your computer and use it in GitHub Desktop.
In-console parser for Chrome bookmarks bar export
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
root = document | |
.querySelector('h3[personal_toolbar_folder="true"]') | |
.parentElement | |
process_dt(root) | |
/** | |
* Process dl: | |
* dt | |
* h3 | |
* dl ... | |
* p | |
* | |
* or | |
* | |
* dt | |
* a | |
*/ | |
function process_a(a) | |
{ | |
return { | |
name: a.innerText, | |
link: a.attributes['href'].value, | |
add_date: a.attributes['add_date'].value | |
} | |
} | |
function process_dl(dl) | |
{ | |
return [... dl.children] | |
.filter(e => e.nodeName.toLowerCase() !== 'p') | |
.map(process_dt) | |
} | |
function process_dt(dt) | |
{ | |
if(dt.children.length === 1) | |
{ | |
return {...process_a(dt.children[0]), type: 'link'} | |
} | |
return { | |
...process_h3(dt.children[0]), | |
type: 'folder', | |
children: process_dl(dt.children[1]) | |
} | |
} | |
function process_h3(h3) | |
{ | |
return { | |
name: h3.innerText, | |
add_date: h3.attributes['add_date']?.value, | |
last_modified: h3.attributes['last_modified']?.value | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment