Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 36 additions & 15 deletions chrome.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ function chromeControl(argv) {
if (argv.length !== 2) { usage() }
const arg = argv[1]
focus(arg)
} else if (cmd === 'copy') {
if (argv.length !== 2) { usage() }
const arg = argv[1]
copy(arg)
} else {
usage()
}
Expand All @@ -97,27 +101,28 @@ function chromeControl(argv) {
// List all open tabs
function list() {
// Iterate all tabs in all windows
let urlToTitle = {}
chrome.windows().forEach((window, winIdx) => {
window.tabs().forEach((tab, tabIdx) => {
urlToTitle[tab.url()] = {
'title': tab.title() || 'No Title',
'url': tab.url(),
// Double entries arrays matching windows/tabs indexes (Using this improves a lot the performances)
let allTabsTitle = chrome.windows.tabs.title()
let allTabsUrls = chrome.windows.tabs.url()

var titleToUrl = {}
for (var winIdx = 0; winIdx < allTabsTitle.length; winIdx++) {
for (var tabIdx = 0; tabIdx < allTabsTitle[winIdx].length; tabIdx ++) {
let title = allTabsTitle[winIdx][tabIdx]
let url = allTabsUrls[winIdx][tabIdx]

titleToUrl[title] = {
'title': title || 'No Title',
'url': url,
'winIdx': winIdx,
'tabIdx': tabIdx,

// Alfred specific properties
'arg': `${winIdx},${tabIdx}`,
'subtitle': tab.url(),
'subtitle': url,
}
})
})

// Create a title to url map
let titleToUrl = {}
Object.keys(urlToTitle).forEach(url => {
titleToUrl[urlToTitle[url].title] = urlToTitle[url]
})
}
}

// Generate output
out = { 'items': [] }
Expand Down Expand Up @@ -182,6 +187,22 @@ function focus(arg) {
chrome.activate()
}

// Focus on a specific tab
function copy(arg) {
let { winIdx, tabIdx } = parseWinTabIdx(arg)
let urlToTitle = {}
let selectedTab = tabIdx;

chrome.windows().forEach((window, winIdx) => {
window.tabs().forEach((tab, tabIdx) => {
if (tabIdx === selectedTab) {
urlToTitle = tab.url();
}
})
})
println(urlToTitle)
}

// Close duplicate tabs
function dedup() {
let urls = {}
Expand Down
Binary file modified integrations/Alfred/Chrome Control.alfredworkflow
Binary file not shown.