Skip to content

Commit

Permalink
Filter tabs by existence of URL
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorgalvao committed Oct 15, 2024
1 parent 88a5293 commit 93aac6b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Tasks/com.alfredapp.automation.core/safari/.common/tabs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ function run(argv) {
// Act on tabs
const tabs = windows
.flatMap(window => window.tabs())
.filter(tab => tab !== null)
.map(tab => [tab.url(), tab.name()])
.map(tab => [tab?.url(), tab?.name()])
.filter(tab => tab[0])

switch (outFormat) {
case "url": return alfredArgs(tabs.map(tab => tab[0]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function browserVariant(appName) {
}

function lookFor(matchString, inText, useRegex) {
if (!inText) return false
if (useRegex) return RegExp(matchString).test(inText)
return inText.includes(matchString)
}
Expand Down Expand Up @@ -75,8 +76,8 @@ function run(argv) {
// Act on tabs
const matchingTabs = windows
.flatMap(window => window.tabs())
.filter(tab => tab !== null)
.map(tab => [tab.url(), tab.name()])
.map(tab => [tab?.url(), tab?.name()])
.filter(tab => tab[0])
.filter(tab => lookFor(matchString, tab[0], regex))

switch (outFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function browserVariant(appName) {
}

function lookFor(matchString, inText, useRegex) {
if (!inText) return false
if (useRegex) return RegExp(matchString).test(inText)
return inText.includes(matchString)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function browserVariant(appName) {
}

function lookFor(matchString, inText, useRegex) {
if (!inText) return false
if (useRegex) return RegExp(matchString).test(inText)
return inText.includes(matchString)
}
Expand Down Expand Up @@ -74,8 +75,7 @@ function run(argv) {
// Act on tabs
const matchingTabs = windows
.flatMap(window => window.tabs())
.filter(tab => tab !== null)
.filter(tab => lookFor(matchString, tab.url(), regex))
.filter(tab => lookFor(matchString, tab?.url(), regex))

const tabURLs = matchingTabs.map(tab => tab.url())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function browserVariant(appName) {
}

function lookFor(matchString, inText, useRegex) {
if (!inText) return false
if (useRegex) return RegExp(matchString).test(inText)
return inText.includes(matchString)
}
Expand Down Expand Up @@ -75,8 +76,8 @@ function run(argv) {
// Act on tabs
const matchingTabs = windows
.flatMap(window => window.tabs())
.filter(tab => tab !== null)
.map(tab => [tab.url(), tab.name()])
.map(tab => [tab?.url(), tab?.name()])
.filter(tab => tab[0])
.filter(tab => !lookFor(matchString, tab[0], regex))

switch (outFormat) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function browserVariant(appName) {
}

function lookFor(matchString, inText, useRegex) {
if (!inText) return false
if (useRegex) return RegExp(matchString).test(inText)
return inText.includes(matchString)
}
Expand Down Expand Up @@ -74,8 +75,7 @@ function run(argv) {
// Act on tabs
const matchingTabs = windows
.flatMap(window => window.tabs())
.filter(tab => tab !== null)
.filter(tab => !lookFor(matchString, tab.url(), regex))
.filter(tab => !lookFor(matchString, tab?.url(), regex))

const tabURLs = matchingTabs.map(tab => tab.url())

Expand Down

0 comments on commit 93aac6b

Please sign in to comment.