Created
December 12, 2021 17:19
-
-
Save rytsikau/658cb2e8a0cfbfcb771a9ddf5a1873b0 to your computer and use it in GitHub Desktop.
Convert Firefox bookmarks file (JSON format) to plain text
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
'--------------------------------------------------------------------------------------------------' | |
' Convert Firefox bookmarks file (JSON format) to plain text (v.20211212) ' | |
'--------------------------------------------------------------------------------------------------' | |
set-executionpolicy unrestricted -scope currentuser | |
$erroractionpreference = "silentlycontinue"; remove-variable *; $erroractionpreference = "continue" | |
$inputFile = "bookmarks.json" | |
$outputFile = "bookmarks.txt" | |
$separator = "`t" | |
$baseDate = Get-Date "1/1/1970" | |
$obj = Get-Content $inputFile -Encoding UTF8 | ConvertFrom-Json | |
while ($obj -ne $null) | |
{ | |
foreach ($node in $obj) | |
{ | |
if ($node.uri -ne $null) | |
{ | |
try { $dateAdded = $baseDate.AddMilliseconds([Int64]($node.dateAdded/1000)).ToString("yyyyMMdd-HHmmss") } | |
catch { $dateAdded = $baseDate.ToString("yyyyMMdd-HHmmss") } | |
try { $lastModified = $baseDate.AddMilliseconds([Int64]($node.lastModified/1000)).ToString("yyyyMMdd-HHmmss") } | |
catch { $lastModified = $baseDate.ToString("yyyyMMdd-HHmmss") } | |
$content += $dateAdded + $separator + $lastModified + $separator + $node.uri + $separator + $node.title + "`n" | |
} | |
} | |
$obj = $obj.children | |
} | |
$content | Out-File $outputFile | |
" Ready! " | |
'--------------------------------------------------------------------------------------------------' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment