Last active
February 16, 2023 03:45
-
-
Save jalaziz/03ecd04e44d3fc8bc393448c04e580ef to your computer and use it in GitHub Desktop.
Tabs Outliner Scripts
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
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) |
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
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some TODOs: