Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fthdgn committed Jan 14, 2020
0 parents commit 743be01
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 0 deletions.
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 Fatih Doğan

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.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### Organize Windows and Tabs Extension for Google Chrome

This extension adds these functions:
* Extension icon primary function:
Merge all windows on target window, and sorts all tabs according to tab url alphabetically.
* Extension icon right click function: Close tabs from this domain:
Closes all tabs with same domain.

This extension ignores pinned tabs and popup windows such as web apps.
69 changes: 69 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
function sortAndMergeTabs() {
chrome.windows.getCurrent(function (currentWindow) {
chrome.windows.getAll({ "populate": true }, function (windows) {
tabs = []
windows.forEach(window => {
if (window.type != "popup") {
window.tabs.forEach(tab => {
if (tab.pinned != true) {
tabs.push(tab)
}
})
}
})
tabs.sort(function (a, b) {
if (a.url < b.url) {
return -1
} else if (a.url > b.url) {
return 1
} else {
return 0
}
})
tabs.forEach(tab => {
chrome.tabs.move(tab.id,
{ "windowId": currentWindow.id, "index": tabs.length * 2 });
})
});
})
}

function closeTabsFromCurrentDomain() {
chrome.tabs.getSelected(tab => {
var url = new URL(tab.url)
closeTabsFromDomain(url.host)
})
}

function closeTabsFromDomain(domain) {

chrome.windows.getAll({ "populate": true }, function (windows) {
tabs = []
windows.forEach(window => {
if (window.type != "popup") {
window.tabs.forEach(tab => {
if (tab.pinned != true) {
var url = new URL(tab.url)
if (url.host == domain) {
chrome.tabs.remove(tab.id)
}
}
})
}
})
});
}

chrome.browserAction.onClicked.addListener(sortAndMergeTabs);

chrome.contextMenus.onClicked.addListener(event => {
if (event.menuItemId == "close_tabs_from_this_domain") {
closeTabsFromCurrentDomain()
}
})

chrome.contextMenus.create({
"title": "Close tabs from this domain",
"id": "close_tabs_from_this_domain",
contexts: ["browser_action"],
});
Binary file added icons/128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/48.png
Loading
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 manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"background": {
"persistent": false,
"scripts": [
"background.js"
]
},
"browser_action": {
"default_icon": "icons/48.png",
"default_title": "Organize Windows and Tabs"
},
"homepage_url": "https://github.com/fthdgn/chrome_organize_windows_tabs/",
"description": "Organize Windows and Tabs",
"icons": {
"128": "icons/128.png",
"48": "icons/48.png",
"16": "icons/16.png"
},
"manifest_version": 2,
"name": "Organize Windows and Tabs",
"offline_enabled": true,
"permissions": [
"tabs",
"contextMenus"
],
"version": "1.0.0"
}

0 comments on commit 743be01

Please sign in to comment.