Chrome: don't open an Options tab for each window

This commit is contained in:
Deathamns 2015-03-12 14:07:16 +01:00
parent 8711bfc097
commit 86ac9763b0
1 changed files with 42 additions and 40 deletions

View File

@ -159,61 +159,63 @@ vAPI.tabs.open = function(details) {
active: !!details.active active: !!details.active
}; };
if ( details.tabId ) { if ( !details.tabId ) {
// update doesn't accept index, must use move
chrome.tabs.update(parseInt(details.tabId, 10), _details, function(tab) {
// if the tab doesn't exist
if ( vAPI.lastError() ) {
chrome.tabs.create(_details);
} else if ( details.index !== undefined ) {
chrome.tabs.move(tab.id, {index: details.index});
}
});
} else {
if ( details.index !== undefined ) { if ( details.index !== undefined ) {
_details.index = details.index; _details.index = details.index;
} }
chrome.tabs.create(_details); chrome.tabs.create(_details);
return;
} }
// update doesn't accept index, must use move
chrome.tabs.update(parseInt(details.tabId, 10), _details, function(tab) {
// if the tab doesn't exist
if ( vAPI.lastError() ) {
chrome.tabs.create(_details);
} else if ( details.index !== undefined ) {
chrome.tabs.move(tab.id, {index: details.index});
}
});
}; };
if ( details.index === -1 ) { if ( details.index !== -1 ) {
vAPI.tabs.get(null, function(tab) {
if ( tab ) {
details.index = tab.index + 1;
} else {
delete details.index;
}
subWrapper();
});
}
else {
subWrapper(); subWrapper();
return;
} }
vAPI.tabs.get(null, function(tab) {
if ( tab ) {
details.index = tab.index + 1;
} else {
delete details.index;
}
subWrapper();
});
}; };
if ( details.select ) { if ( !details.select ) {
chrome.tabs.query({ currentWindow: true }, function(tabs) { wrapper();
var rgxHash = /#.*/; return;
// this is questionable }
var url = targetURL.replace(rgxHash, '');
var selected = tabs.some(function(tab) {
if ( tab.url.replace(rgxHash, '') === url ) {
chrome.tabs.update(tab.id, { active: true });
return true;
}
});
if ( !selected ) { chrome.tabs.query({}, function(tabs) {
wrapper(); var rgxHash = /#.*/;
// this is questionable
var url = targetURL.replace(rgxHash, '');
var selected = tabs.some(function(tab) {
if ( tab.url.replace(rgxHash, '') === url ) {
chrome.tabs.update(tab.id, { active: true });
chrome.windows.update(tab.windowId, { focused: true });
return true;
} }
}); });
}
else { if ( !selected ) {
wrapper(); wrapper();
} }
});
}; };
/******************************************************************************/ /******************************************************************************/