Skip to content

Instantly share code, notes, and snippets.

@jalaziz
Last active Mar 15, 2021
Embed
What would you like to do?
Tabs Outliner Scripts
import json
import os
export_file = 'tree-exported-Sat-Apr-09-2016.tree'
backup_export_file = '{}.bak'.format(export_file)
new_tree = []
seen_urls = set()
os.rename(export_file, backup_export_file)
with open(backup_export_file) as f:
tree = json.load(f)
for node in reversed(tree):
if isinstance(node, list):
item = node[1]
if ('type' not in item) or (item['type'] == 'tab'):
url = item['data']['url']
if url in seen_urls:
print(f'skipping duplicate: {url}')
continue
seen_urls.add(url)
new_tree.append(node)
new_tree = list(reversed(new_tree))
window_count = -1
tab_count = -1
for node in new_tree:
if isinstance(node, list):
item = node[1]
pos = []
if item.get('type') in ('win', 'savedwin'):
window_count += 1
tab_count = -1
pos = [window_count]
else:
tab_count += 1
pos = [window_count, tab_count]
node[2] = pos
with open(export_file, 'w') as f:
json.dump(new_tree, f)
import json
import os
from urllib.parse import urldefrag
export_file = 'tree-exported-Sun-Mar-14-2021.tree'
backup_export_file = '{}.bak'.format(export_file)
new_tree = []
seen_urls = set()
os.rename(export_file, backup_export_file)
with open(backup_export_file) as f:
tree = json.load(f)
for node in reversed(tree):
if isinstance(node, list):
item = node[1]
if ('type' not in item) or (item['type'] == 'tab'):
url = item['data']['url']
if url.startswith('chrome-extension://klbibkeccnjlkjkiokjodocebajanakg/suspended.html'):
_, fragment = urldefrag(url)
uri = fragment.split('uri=', 1)[1]
print(f'cleaning TGS url from {url} to {uri}')
item['data']['url'] = uri
new_tree.append(node)
new_tree = list(reversed(new_tree))
with open(export_file, 'w') as f:
json.dump(new_tree, f)
@jalaziz
Copy link
Author

jalaziz commented Apr 10, 2016

Some TODOs:

  • Remove empty windows
  • Preserve tab trees
  • Detect duplicate pages with different anchor tags or query parameters

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