Skip to content

Commit

Permalink
🎉 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
epilande committed Dec 15, 2020
0 parents commit 41ad49c
Show file tree
Hide file tree
Showing 12 changed files with 206 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
max_line_length = 80
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
logs
*.log
.DS_Store
.vscode
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"endOfLine": "lf",
"singleQuote": false,
"tabWidth": 2,
"trailingComma": "all"
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Emmanuel Pilande

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<div align="center">
<h1>Alfred Browser Tabs 🔍</h1>
</div>

<p align="center">
<strong>Search browser tabs from Chrome, Brave, & Safari</strong>
</p>

## Why?

You have hundreds of tabs open that you need to swift through and ain't nobody got time for that.

## Features

- 🏎 Blazing fast!
- 💪 Supports Chrome, Brave, & Safari.
- 🔍 Fuzzy search title & URLs.
- ✨ Relevant results (last active window).
- 🌶️ Customizable hotkeys & keywords.
- 👯‍♀️ Copy URL.

## Installation

1. Download the Alfred Workflow.
1. Double-click to import into Alfred (requires Powerpack).
1. Review workflow, add hotkeys, customize.

## Usage

I would recommend setting up a hotkey to toggle the workflow to immediately search open tabs.

### Commands

- `chrome tabs {query}` - Fetch tabs from Google Chrome and filter based on query.
- `brave tabs {query}` - Fetch tabs from Brave Browser and filter based on query.
- `safari tabs {query}` - Fetch tabs from Safari and filter based on query.

### Copy to clipboard

Holding the `CTRL` key while selecting an item will copy the selected tab URL to your clipboard.

## License

[MIT License](https://oss.ninja/mit/epilande/)
Binary file added src/assets/brave-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/chrome-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/assets/safari-icon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions src/focus-tab-webkit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env osascript -l JavaScript

function run(args) {
let safari = Application("Safari");
let query = args[0];
let [windowIndex, url] = query.split(",");

function getTab() {
let result;
let window = safari.windows[windowIndex];
if (window) {
for (let index in window.tabs) {
let tab = window.tabs[index];
let tabURL = tab.url() || tab.name();
if (tabURL && tabURL.startsWith(url)) {
result = tab;
break;
}
}
return result;
}
}

let tab = getTab();
safari.activate();
safari.windows[windowIndex].currentTab = tab;
}
16 changes: 16 additions & 0 deletions src/focus-tab.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env osascript -l JavaScript

function run(args) {
ObjC.import("stdlib");
let browser = $.getenv("browser");
let chrome = Application(browser);
let query = args[0];
let [arg1, arg2] = query.split(",");
let windowIndex = parseInt(arg1);
let tabIndex = parseInt(arg2);

chrome.activate();
chrome.windows[windowIndex].visible = true;
chrome.windows[windowIndex].activeTabIndex = tabIndex + 1;
chrome.windows[windowIndex].index = 1;
}
36 changes: 36 additions & 0 deletions src/list-tabs-webkit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env osascript -l JavaScript

function run(args) {
let browser = args[0];
let chrome = Application(browser);
chrome.includeStandardAdditions = true;
let windowCount = chrome.windows.length;
let tabsTitle = chrome.windows.tabs.name();
let tabsUrl = chrome.windows.tabs.url();
let tabsMap = {};

for (let w = 0; w < windowCount; w++) {
for (let t = 0; t < tabsTitle[w].length; t++) {
let url = tabsUrl[w][t] || "";
let matchUrl = url.replace(/(^\w+:|^)\/\//, "");
let title = tabsTitle[w][t] || matchUrl;

tabsMap[url] = {
title,
url,
subtitle: url,
windowIndex: w,
tabIndex: t,
arg: `${w},${url || title}`,
match: `${title} ${matchUrl}`,
};
}
}

let items = Object.keys(tabsMap).reduce((acc, url) => {
acc.push(tabsMap[url]);
return acc;
}, []);

return JSON.stringify({ items });
}
39 changes: 39 additions & 0 deletions src/list-tabs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env osascript -l JavaScript

function run(args) {
let browser = args[0];
let chrome = Application(browser);
chrome.includeStandardAdditions = true;
let windowCount = chrome.windows.length;
let tabsTitle =
browser === "Safari"
? chrome.windows.tabs.name()
: chrome.windows.tabs.title();
let tabsUrl = chrome.windows.tabs.url();
let tabsMap = {};

for (let w = 0; w < windowCount; w++) {
for (let t = 0; t < tabsTitle[w].length; t++) {
let url = tabsUrl[w][t] || "";
let matchUrl = url.replace(/(^\w+:|^)\/\//, "");
let title = tabsTitle[w][t] || matchUrl;

tabsMap[url] = {
title,
url,
subtitle: url,
windowIndex: w,
tabIndex: t,
arg: `${w},${t},${url}`,
match: `${title} ${matchUrl}`,
};
}
}

let items = Object.keys(tabsMap).reduce((acc, url) => {
acc.push(tabsMap[url]);
return acc;
}, []);

return JSON.stringify({ items });
}

0 comments on commit 41ad49c

Please sign in to comment.