From 3c08342e98e271541dbc09e28b570c44ee0098ee Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 1 Oct 2017 15:34:29 +0300 Subject: [PATCH] open usercss installer tab next to the source tab --- background/background.js | 2 +- background/usercss-helper.js | 10 +++++++--- js/messaging.js | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/background/background.js b/background/background.js index 0d5be065..70302a99 100644 --- a/background/background.js +++ b/background/background.js @@ -324,7 +324,7 @@ function onRuntimeMessage(request, sender, sendResponse) { return KEEP_CHANNEL_OPEN; case 'openUsercssInstallPage': - usercssHelper.openInstallPage(sender.tab.id, request).then(sendResponse); + usercssHelper.openInstallPage(sender.tab, request).then(sendResponse); return KEEP_CHANNEL_OPEN; case 'closeTab': diff --git a/background/usercss-helper.js b/background/usercss-helper.js index c3a8432c..1b4eb71e 100644 --- a/background/usercss-helper.js +++ b/background/usercss-helper.js @@ -78,11 +78,15 @@ var usercssHelper = (() => { ); } - function openInstallPage(tabId, request) { + function openInstallPage(tab, request) { const url = '/install-usercss.html' + '?updateUrl=' + encodeURIComponent(request.updateUrl) + - '&tabId=' + tabId; - return wrapReject(openURL({url})); + '&tabId=' + tab.id; + return wrapReject(openURL({ + url, + index: tab.index + 1, + openerTabId: tab.id, + })); } return {build, save, findDup, openInstallPage}; diff --git a/js/messaging.js b/js/messaging.js index ff346bfd..1098a9eb 100644 --- a/js/messaging.js +++ b/js/messaging.js @@ -180,7 +180,7 @@ function getTabRealURL(tab) { // opens a tab or activates the already opened one, // reuses the New Tab page if it's focused now -function openURL({url, currentWindow = true}) { +function openURL({url, index, openerTabId, currentWindow = true}) { if (!url.includes('://')) { url = chrome.runtime.getURL(url); } @@ -204,7 +204,7 @@ function openURL({url, currentWindow = true}) { chrome.tabs.update({url}, resolve); } else { // create a new tab - const options = {url}; + const options = {url, index}; if (tab && (!FIREFOX || FIREFOX >= 57) && !chromeInIncognito) { options.openerTabId = tab.id; }