Skip to content

Commit cc22b10

Browse files
committed
First version of the extension
1 parent 608dbc1 commit cc22b10

File tree

5 files changed

+75
-2
lines changed

5 files changed

+75
-2
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,24 @@
1-
# prevent-duplicate-tabs-chrome-extension
2-
Chrome extension that detects when a duplicate tab is opened and activates already existing tab
1+
# "Prevent Duplicate Tabs" Chrome extension
2+
3+
Chrome extension that detects when a duplicate tab is opened and activates already existing tab.
4+
5+
## How to install
6+
7+
I have not published this extension into Chrome Web Store, so your will need to install extension locally:
8+
9+
1. Clone extension to your machine - e.g. `git clone https://github.com/Litee/prevent-duplicate-tabs-chrome-extension.git`
10+
1. Look at `background.js` and into `manifest.json`. It is always a good idea to check that code does not do anything suspicious and does not have too many permissions ;)
11+
1. Open chrome://extensions tab in your Chrome browser
12+
1. Activate developer mode (required for next step)
13+
1. Install extension as unpacked
14+
15+
Ping me if you liked this extension and I may consider publishing it into Chrome Web Store.
16+
17+
## TODOs
18+
19+
* Support white lists
20+
* De-duplicate already opened tabs
21+
22+
## Disclaimers
23+
24+
* Icon made by [Picol](https://www.flaticon.com/authors/picol) from [Flaticon](https://www.flaticon.com/) is licensed by [CC 3.0 BY](http://creativecommons.org/licenses/by/3.0/)

background.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
chrome.tabs.onCreated.addListener(newTab => {
2+
if (newTab.url) {
3+
verifyAndDeduplicate(newTab.id, newTab.url);
4+
}
5+
});
6+
7+
chrome.tabs.onUpdated.addListener((updatedTabId, updateInfo, updatedTab) => {
8+
if (updateInfo.url) {
9+
verifyAndDeduplicate(updatedTabId, updateInfo.url);
10+
}
11+
});
12+
13+
function verifyAndDeduplicate(currentTabId, currentTabUrl) {
14+
chrome.tabs.query({}, tabs => {
15+
var duplicateTab = null;
16+
tabs.forEach(otherTab => {
17+
if (otherTab.id !== currentTabId && otherTab.url === currentTabUrl) {
18+
duplicateTab = otherTab;
19+
}
20+
});
21+
if (duplicateTab) {
22+
chrome.tabs.update(duplicateTab.id, {
23+
"active": true
24+
});
25+
chrome.windows.update(duplicateTab.windowId, {
26+
focused: true
27+
})
28+
chrome.tabs.remove(currentTabId);
29+
}
30+
});
31+
}

icon-128.png

1.08 KB
Loading

icon-16.png

474 Bytes
Loading

manifest.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "Prevent Duplicate Tabs",
3+
"version": "0.0.1",
4+
"manifest_version": 2,
5+
"description": "Chrome extension that detects when a duplicate tab is opened and activates already existing tab",
6+
"icons": {
7+
"16": "icon-16.png",
8+
"128": "icon-128.png"
9+
},
10+
"background": {
11+
"scripts": [
12+
"background.js"
13+
]
14+
},
15+
"permissions": ["tabs"],
16+
"browser_action": {
17+
"default_icon": "icon-16.png",
18+
"default_title": "Prevent Duplicate Tabs"
19+
}
20+
}

0 commit comments

Comments
 (0)