-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaggregate_bsky_tabs.py
More file actions
110 lines (79 loc) · 3.08 KB
/
aggregate_bsky_tabs.py
File metadata and controls
110 lines (79 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import operator
import common
cl = common.get_client()
tabs = common.parse_tabs(cl)
bsky_marker = "https://bsky.app"
bsky_tabs = [tab for tab in tabs if bsky_marker in tab.url]
# all tabs containing bluesky windows right now
bluesky_windows = {}
for tab in bsky_tabs:
if tab.window not in bluesky_windows:
bluesky_windows[tab.window] = 1
else:
bluesky_windows[tab.window] += 1
min_window = str(min([map(int, bluesky_windows.keys())]))
# first tab is me-specific thing
first_tab_ignored = False
first_tab = None
# tagging the first tab that's pinned in my first browser window
for tab in bsky_tabs:
if tab.window == min_window:
if not first_tab_ignored:
first_tab = tab
#first_tab_ignored = True
continue
# closing Bluesky Home tabs
for tab in bsky_tabs:
if tab.url == bsky_marker+"/home" \
and tab != first_tab:
print("Closing home tab:", tab.get_full_id())
cl.close_tabs([tab.get_full_id()])
for tab in bsky_tabs:
if tab.url == "https://bsky.app/notifications" \
and tab != first_tab:
print("Closing notif tab:", tab.get_full_id())
cl.close_tabs([tab.get_full_id()])
for tab in bsky_tabs:
if tab.url == "https://bsky.app/" \
and tab != first_tab:
print("Closing feed tab:", tab.get_full_id())
cl.close_tabs([tab.get_full_id()])
# closed a bunch of tabs - regenerating the data
tabs = common.parse_tabs(cl)
bsky_tabs = [tab for tab in tabs if "https://bsky.app" in tab.url]
bluesky_windows = {}
for tab in bsky_tabs:
if tab.window not in bluesky_windows:
bluesky_windows[tab.window] = 1
else:
bluesky_windows[tab.window] += 1
# determining a window where the majority of Bluesky tabs are
largest_window = max(bluesky_windows.items(), key=operator.itemgetter(1))[0]
# moving all the tabs into that window
# the process is involved since you need to recalculate tab indices - I'd rather rely on the brotab code for that
old_tabs = common.serialize_tabs(tabs)
#print(bsky_tabs)
for tab in bsky_tabs:
if tab.window == min_window:
if not first_tab_ignored:
first_tab_ignored = True
continue
if tab.window != largest_window:
print("Moving tab {} from window {} to window {}".format(tab.get_full_id(), tab.window, largest_window))
tab.window = largest_window
new_tabs = common.serialize_tabs(tabs)
# this code recalculates the tab indices and also calls the move command
common.update_tabs(cl, old_tabs, new_tabs)
tabs = common.parse_tabs(cl)
# cleaning the bluesky window from anything that's not bluesky
# TODO - can't open a new window to dump tabs into, so, need to think of other way to clean up the bluesky window
"""
bluesky_window_tabs = [tab for tab in tabs if tab.window == bluesky_window]
unrelated_tabs = [tab for tab in bluesky_window_tabs if "//bsky.app" not in tab.url]
for tab in unrelated_tabs:
if tab.url == "https://bsky.app/home":
break
#print("Closing home tab:", tab.get_full_id())
#cl.close_tabs([tab.get_full_id()])
"""
import close_empty_windows