Last active
August 29, 2015 14:14
-
-
Save reillysiemens/0e824874de1b0b1db35e to your computer and use it in GitHub Desktop.
Dump tabs from Firefox tab groups to JSON.
This file contains hidden or 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
#!/usr/bin/env coffee | |
### | |
Copyright (c) 2015, Reilly Tucker Siemens <[email protected]> | |
Permission to use, copy, modify, and/or distribute this software for any | |
purpose with or without fee is hereby granted, provided that the above | |
copyright notice and this permission notice appear in all copies. | |
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
### | |
# TODO: Rewrite as asynchronous. Find default profile in Windows. | |
os = require 'os' | |
fs = require 'fs' | |
ini = require 'ini' # npm install ini (https://github.com/isaacs/ini) | |
# Find the default Firefox profile in Linux or OS X. No Windows yet. | |
if os.platform() is 'darwin' | |
firefoxDir = "#{process.env.HOME}/Library/Application\ Support/Firefox" | |
else | |
firefoxDir = "#{process.env.HOME}/.mozilla/firefox" | |
# Parse the profiles.ini file. | |
profiles = ini.parse(fs.readFileSync("#{firefoxDir}/profiles.ini", 'utf-8')) | |
# Find the path for the default profile. | |
defaultProfileDir = "#{firefoxDir}/#{profiles.Profile0.Path}" | |
# Get the filename for the sessionstore backup. | |
recoveryFile = "#{defaultProfileDir}/sessionstore-backups/recovery.js" | |
# Parse the recovery file. | |
recovery = JSON.parse(fs.readFileSync(recoveryFile, 'utf-8')) | |
# Find the existing tab view groups. | |
tabViewGroups = JSON.parse(recovery.windows[0].extData['tabview-group']) | |
# Create a new tab group object. | |
tabGroups = {} | |
# Make a new empty array for each tab view group title. | |
for own key, value of tabViewGroups | |
tabGroups[value.title] = [] | |
# For every tab... | |
recovery.windows[0].tabs.forEach (tab) -> | |
if tab.extData? | |
if JSON.parse(tab.extData['tabview-tab'])? | |
# If the tab is part of a tab view group find the ID. | |
tabGroupID = JSON.parse(tab.extData['tabview-tab']).groupID | |
# Add the tab's URL to the appropriate group array. | |
tabGroups[tabViewGroups[tabGroupID].title].push(tab.entries[0].url) | |
# Print the JSON formatted output. | |
console.log(JSON.stringify(tabGroups)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment