Skip to content

Commit

Permalink
See if the tab exists before creating a new one.
Browse files Browse the repository at this point in the history
  • Loading branch information
bwinton committed Sep 15, 2015
1 parent 33f2a8f commit 27303b5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ chrome.browserAction.setBadgeText({text: '(ツ)'});
chrome.browserAction.setBadgeBackgroundColor({color: '#eae'});

chrome.browserAction.onClicked.addListener(function(aTab) {
chrome.tabs.create({'url': 'http://chilloutandwatchsomecatgifs.com/', 'active': true});
chrome.tabs.query({'url': 'http://chilloutandwatchsomecatgifs.com/'}, (tabs) => {
if (tabs.length === 0) {
// There is no catgif tab!
chrome.tabs.create({'url': 'http://chilloutandwatchsomecatgifs.com/', 'active': true});
} else {
// Do something here…
}
});
});

0 comments on commit 27303b5

Please sign in to comment.