-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
26 lines (20 loc) · 1.06 KB
/
Copy pathbackground.js
File metadata and controls
26 lines (20 loc) · 1.06 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
/*
* HackerNew was created by DataFoundries LLC. The BrainTool company.
* Copyright (C) 2022-present. MIT license <https://github.com/tconfrey/HackerNew/>
* Tame your tabs and control your online life with BrainTool <https://braintool.org/>
*/
chrome.runtime.onMessage.addListener(async (msg, sender) => {
// Open a tab w url as requested. Put it in the HackerNew tabgroup if it exists, create if not
const url = msg.url;
const hnTab = sender.tab.id;
const hnWin = sender.tab.windowId;
const tgs = await chrome.tabGroups.query({'title': 'HackerNew'});
let tgid = tgs.length ? tgs[0].id : null;
const tab = await chrome.tabs.create({'url': url});
const args = tgid ?
{'groupId': tgid, 'tabIds': [hnTab, tab.id]} :
{'createProperties': {'windowId': hnWin}, 'tabIds': [hnTab, tab.id]};
// const args = tgid ? {'groupId': tgid, 'tabIds': [hnTab, tab.id]} : {'tabIds': [hnTab, tab.id]};
tgid = await chrome.tabs.group(args);
chrome.tabGroups.update(tgid, {'title': 'HackerNew', 'color': 'orange'});
});