Skip to content

Commit 87b63d9

Browse files
committed
Move HTML list builder to the background module
1 parent 36c54a5 commit 87b63d9

3 files changed

Lines changed: 36 additions & 37 deletions

File tree

webextensions/background/background.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import * as Permissions from '/common/permissions.js';
2424
import * as TSTAPI from '/common/tst-api.js';
2525
import * as SidebarConnection from '/common/sidebar-connection.js';
2626
import * as UserOperationBlocker from '/common/user-operation-blocker.js';
27-
import * as TreeBehavior from '/common/tree-behavior.js';
2827
import '/common/bookmark.js'; // we need to load this once in the background page to register the global listener
2928

3029
import Tab from '/common/Tab.js';
@@ -481,7 +480,7 @@ export async function confirmToCloseTabs(tabs, { windowId, configKey, messageKey
481480
}
482481

483482
const listing = configs.warnOnCloseTabsWithListing ?
484-
TreeBehavior.tabsToHTMLList(tabs, { maxRows: configs.warnOnCloseTabsWithListingMaxRows }) :
483+
tabsToHTMLList(tabs, { maxRows: configs.warnOnCloseTabsWithListingMaxRows }) :
485484
'';
486485
const dialogParams = {
487486
content: `
@@ -549,6 +548,38 @@ Commands.onTabsClosing.addListener((tabIds, options = {}) => {
549548
return confirmToCloseTabs(tabIds, options);
550549
});
551550

551+
export function tabsToHTMLList(tabs, { maxRows }) {
552+
const rootLevelOffset = tabs.map(tab => parseInt(tab.$TST.getAttribute(Constants.kLEVEL) || 0)).sort()[0];
553+
return (
554+
`<ul style="border: 1px inset;
555+
display: flex;
556+
flex-direction: column;
557+
flex-grow: 1;
558+
flex-shrink: 1;
559+
margin: 0.5em 0;
560+
min-height: ${(Math.max(1, maxRows || 0)) + 1}em;
561+
max-height: ${(Math.max(1, maxRows || 0)) + 1}em;
562+
overflow: auto;
563+
padding: 0.5em;">` +
564+
tabs.map(tab => `<li style="align-items: center;
565+
display: flex;
566+
flex-direction: row;
567+
padding-left: calc((${tab.$TST.getAttribute(Constants.kLEVEL)} - ${rootLevelOffset}) * 0.25em);"
568+
title="${sanitizeForHTMLText(tab.title)}"
569+
><img style="display: flex;
570+
max-height: 1em;
571+
max-width: 1em;"
572+
alt=""
573+
src="${sanitizeForHTMLText(tab.favIconUrl || browser.extension.getURL('resources/icons/globe-16.svg'))}"
574+
><span style="display: flex;
575+
margin-left: 0.25em;
576+
overflow: hidden;
577+
white-space: nowrap;"
578+
>${sanitizeForHTMLText(tab.title)}</span></li>`).join('') +
579+
`</ul>`
580+
);
581+
}
582+
552583
function reserveToClearGrantedRemovingTabs() {
553584
const lastGranted = configs.grantedRemovingTabIds.join(',');
554585
setTimeout(() => {

webextensions/background/handle-group-tabs.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Tab from '/common/Tab.js';
2828
import * as TabsGroup from './tabs-group.js';
2929
import * as TabsOpen from './tabs-open.js';
3030
import * as Tree from './tree.js';
31+
import * as Background from './background.js';
3132

3233
function log(...args) {
3334
internalLogger('background/handle-group-tabs', ...args);
@@ -469,7 +470,7 @@ async function confirmToAutoGroupNewTabsFromOthers(tabs) {
469470
const windowId = tabs[0].windowId;
470471

471472
const listing = configs.warnOnAutoGroupNewTabsWithListing ?
472-
TreeBehavior.tabsToHTMLList(tabs, { maxRows: configs.warnOnAutoGroupNewTabsWithListingMaxRows }) :
473+
Background.tabsToHTMLList(tabs, { maxRows: configs.warnOnAutoGroupNewTabsWithListingMaxRows }) :
473474
'';
474475
const dialogParams = {
475476
content: `

webextensions/common/tree-behavior.js

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77

88
import {
99
log as internalLogger,
10-
configs,
11-
sanitizeForHTMLText
10+
configs
1211
} from './common.js';
1312
import * as Constants from './constants.js';
1413
import * as SidebarConnection from './sidebar-connection.js';
@@ -389,35 +388,3 @@ function cleanUpTreeStructureArray(treeStructure, defaultParent) {
389388
});
390389
return treeStructure;
391390
}
392-
393-
export function tabsToHTMLList(tabs, { maxRows }) {
394-
const rootLevelOffset = tabs.map(tab => parseInt(tab.$TST.getAttribute(Constants.kLEVEL) || 0)).sort()[0];
395-
return (
396-
`<ul style="border: 1px inset;
397-
display: flex;
398-
flex-direction: column;
399-
flex-grow: 1;
400-
flex-shrink: 1;
401-
margin: 0.5em 0;
402-
min-height: ${(Math.max(1, maxRows || 0)) + 1}em;
403-
max-height: ${(Math.max(1, maxRows || 0)) + 1}em;
404-
overflow: auto;
405-
padding: 0.5em;">` +
406-
tabs.map(tab => `<li style="align-items: center;
407-
display: flex;
408-
flex-direction: row;
409-
padding-left: calc((${tab.$TST.getAttribute(Constants.kLEVEL)} - ${rootLevelOffset}) * 0.25em);"
410-
title="${sanitizeForHTMLText(tab.title)}"
411-
><img style="display: flex;
412-
max-height: 1em;
413-
max-width: 1em;"
414-
alt=""
415-
src="${sanitizeForHTMLText(tab.favIconUrl || browser.extension.getURL('resources/icons/globe-16.svg'))}"
416-
><span style="display: flex;
417-
margin-left: 0.25em;
418-
overflow: hidden;
419-
white-space: nowrap;"
420-
>${sanitizeForHTMLText(tab.title)}</span></li>`).join('') +
421-
`</ul>`
422-
);
423-
}

0 commit comments

Comments
 (0)