Skip to content

Commit 98df006

Browse files
authored
Improve list command performance. This is done by initally storing all tabs titles/urls in double entries arrays (matching windows/tabs indexes) instead of requesting the values in a double for loop. (#7)
1 parent 8fea921 commit 98df006

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

chrome.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,27 +97,28 @@ function chromeControl(argv) {
9797
// List all open tabs
9898
function list() {
9999
// Iterate all tabs in all windows
100-
let urlToTitle = {}
101-
chrome.windows().forEach((window, winIdx) => {
102-
window.tabs().forEach((tab, tabIdx) => {
103-
urlToTitle[tab.url()] = {
104-
'title': tab.title() || 'No Title',
105-
'url': tab.url(),
100+
// Double entries arrays matching windows/tabs indexes (Using this improves a lot the performances)
101+
let allTabsTitle = chrome.windows.tabs.title()
102+
let allTabsUrls = chrome.windows.tabs.url()
103+
104+
var titleToUrl = {}
105+
for (var winIdx = 0; winIdx < allTabsTitle.length; winIdx++) {
106+
for (var tabIdx = 0; tabIdx < allTabsTitle[winIdx].length; tabIdx ++) {
107+
let title = allTabsTitle[winIdx][tabIdx]
108+
let url = allTabsUrls[winIdx][tabIdx]
109+
110+
titleToUrl[title] = {
111+
'title': title || 'No Title',
112+
'url': url,
106113
'winIdx': winIdx,
107114
'tabIdx': tabIdx,
108115

109116
// Alfred specific properties
110117
'arg': `${winIdx},${tabIdx}`,
111-
'subtitle': tab.url(),
118+
'subtitle': url,
112119
}
113-
})
114-
})
115-
116-
// Create a title to url map
117-
let titleToUrl = {}
118-
Object.keys(urlToTitle).forEach(url => {
119-
titleToUrl[urlToTitle[url].title] = urlToTitle[url]
120-
})
120+
}
121+
}
121122

122123
// Generate output
123124
out = { 'items': [] }

0 commit comments

Comments
 (0)