Skip to content

Commit c3c5236

Browse files
committed
Fixed #1445 Support for Tab Groups
1 parent 5bbb25a commit c3c5236

File tree

10 files changed

+724
-560
lines changed

10 files changed

+724
-560
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Surfingkeys is doing its best to make full use of keyboard for web browsing, but
4141
| Capture page | Y | Y | Y |
4242
| PDF viewer | Y | N | N |
4343
| Sync across devices | Y | N | Y |
44+
| Tab Groups | Y | N | N |
4445
| Proxy | Y | N | N |
4546
| Markdown preview |Y | Y | N |
4647

config/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function modifyManifest(browser, mode, buffer) {
3232
manifest.permissions.push("downloads.shelf");
3333
manifest.permissions.push("favicon");
3434
manifest.permissions.push("userScripts");
35+
manifest.permissions.push("tabGroups");
3536
manifest.incognito = "split";
3637
manifest.options_page = "pages/options.html";
3738
manifest.background = {

src/background/start.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,58 @@ function start(browser) {
781781
});
782782
});
783783
};
784+
self.createTabGroup = function(message, sender, sendResponse) {
785+
chrome.tabs.group({tabIds: [sender.tab.id], groupId: message.groupId}, function(groupId) {
786+
if (message.title || message.color) {
787+
chrome.tabGroups.update(groupId, {
788+
title: message.title,
789+
color: message.color
790+
});
791+
}
792+
});
793+
};
794+
self.ungroupTab = function(message, sender, sendResponse) {
795+
chrome.tabs.ungroup([sender.tab.id]);
796+
};
797+
self.collapseGroup = function(message, sender, sendResponse) {
798+
chrome.tabGroups.update(message.groupId, {collapsed: message.collapsed});
799+
};
800+
self.getTabGroups = function(message, sender, sendResponse) {
801+
chrome.tabGroups.query({}, function(groups) {
802+
let activeGroup = -1;
803+
// retrieve all tabs of each group
804+
chrome.tabs.query({}, function(tabs) {
805+
const tabsInGroup = {};
806+
tabs.forEach(function(tab) {
807+
if (tab.groupId && tab.groupId !== chrome.tabGroups.TAB_GROUP_ID_NONE) {
808+
if (!tabsInGroup[tab.groupId]) {
809+
tabsInGroup[tab.groupId] = [];
810+
}
811+
if (tab.id === sender.tab.id) {
812+
activeGroup = tab.groupId;
813+
}
814+
tabsInGroup[tab.groupId].push({
815+
id: tab.id,
816+
title: tab.title,
817+
url: tab.url,
818+
active: tab.active,
819+
index: tab.index
820+
});
821+
}
822+
});
823+
824+
groups = groups.filter((g) => !g.hermit);
825+
groups.forEach(function(group) {
826+
group.tabs = tabsInGroup[group.id] || [];
827+
group.active = group.id === activeGroup;
828+
});
829+
830+
_response(message, sendResponse, {
831+
groups: groups
832+
});
833+
});
834+
});
835+
};
784836
self.togglePinTab = function(message, sender, sendResponse) {
785837
getActiveTab(function(tab) {
786838
return chrome.tabs.update(tab.id, {

src/content_scripts/common/default.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export default function(api, clipboard, insert, normal, hints, visual, front, br
3333
mapkey('T', '#3Choose a tab', function() {
3434
front.chooseTab();
3535
});
36+
mapkey(';G', '#3Group this tab', function() {
37+
front.groupTab();
38+
});
3639
mapkey('?', '#0Show usage', function() {
3740
front.showUsage();
3841
});

src/content_scripts/front.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ function createFront(insert, normal, hints, visual, browser) {
316316
}
317317
};
318318

319+
self.groupTab = function() {
320+
self.command({
321+
action: 'groupTab'
322+
});
323+
};
324+
319325
/**
320326
* Open the omnibar.
321327
*

src/content_scripts/ui/command.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ export default (normal, command, omnibar) => {
121121
command('clearQueueURLs', 'clear URLs in queue waiting for open', function(args) {
122122
RUNTIME('clearQueueURLs');
123123
});
124+
command('createTabGroup', 'group all tabs by domain: createTabGroup [title] [grey|blue|red|yellow|green|pink|purple|cyan|orange]', function(args) {
125+
RUNTIME('createTabGroup', {title: args[0], color: args[1]});
126+
});
124127
command('timeStamp', 'print time stamp in human readable format', function(args) {
125128
var dt = new Date(parseInt(args[0]));
126129
omnibar.listWords([dt.toString()]);

src/content_scripts/ui/frontend.css

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,9 @@ body {
190190
margin: 5px;
191191
box-shadow: 0px 2px 10px rgb(0 0 0 / 88%);
192192
}
193+
#sk_omnibarSearchResult.commands>ul>li {
194+
justify-content: space-between;
195+
}
193196
#sk_status {
194197
position: fixed;
195198
bottom: 0;
@@ -310,7 +313,7 @@ kbd {
310313
position: fixed;
311314
top: 0;
312315
left: 0;
313-
background: #000;
316+
background: #00000085;
314317
overflow: auto;
315318
z-index: 2147483000;
316319
}
@@ -396,6 +399,23 @@ div.sk_tab_hint {
396399
border-radius: 3px;
397400
box-shadow: 0px 3px 7px 0px rgba(0, 0, 0, 0.3);
398401
}
402+
div.sk_tab_group {
403+
font-size: large;
404+
color: #e1e1e1;
405+
padding: 4px;
406+
border: 1px solid #ccc;
407+
border-radius: 6px;
408+
margin: 10px;
409+
display: inline-block;
410+
background: #000;
411+
}
412+
div.sk_tab_group_header {
413+
display: flex;
414+
justify-content: space-between;
415+
}
416+
div.sk_tab_group_header>div {
417+
display: inline-flex;
418+
}
399419
#sk_bubble {
400420
position: absolute;
401421
padding: 9px;

0 commit comments

Comments
 (0)