From 98a71d2812eecf23376e2bc4199e0eb73a219f45 Mon Sep 17 00:00:00 2001 From: 9adefaf01e5bf6426d838cd20eae582d2b6ba647 Date: Wed, 4 Mar 2015 05:06:43 +0300 Subject: [PATCH] Re-use an active new tab page for manager/editor --- popup.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/popup.js b/popup.js index 51d5cea2..acf4f5c5 100644 --- a/popup.js +++ b/popup.js @@ -125,13 +125,20 @@ function openLinkInTabOrWindow(event) { if (localStorage['openEditInWindow'] == 'true') { chrome.windows.create({url: event.target.href}); } else { - chrome.tabs.create({url: event.target.href}); + openLink(event); } } function openLink(event) { event.preventDefault(); - chrome.tabs.create({url: event.target.href}); + chrome.tabs.query({currentWindow: true, active: true}, function (tabs) { + if (tabs && tabs.length && tabs[0].url.match(/^chrome:\/\/newtab\/?$/)) { + chrome.tabs.update({url: event.target.href}); + close(); // close the popup + } else { + chrome.tabs.create({url: event.target.href}); + } + }); } function handleUpdate(style) {