From 0e33a3cb710ede7476a23d5e817e21fe447959cc Mon Sep 17 00:00:00 2001 From: O2bmm Date: Mon, 11 Dec 2023 01:08:59 +0800 Subject: [PATCH 1/2] Add Option Do not close the last tab --- background_scripts/main.js | 11 ++++++++++- lib/settings.js | 1 + pages/options.html | 14 ++++++++++++++ pages/options.js | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/background_scripts/main.js b/background_scripts/main.js index ab8eb9e19..eae81b157 100644 --- a/background_scripts/main.js +++ b/background_scripts/main.js @@ -254,7 +254,16 @@ const BackgroundCommands = { // In Firefox, Ctrl-W will not close a pinned tab, but on Chrome, it will. We try to be // consistent with each browser's UX for pinned tabs. if (tab.pinned && BgUtils.isFirefox()) return; - chrome.tabs.remove(tab.id); + if(Settings.get("keepLastTabOpen")){ + chrome.tabs.query({ currentWindow: true }, function (tabs) { + if(tabs.length == 1){ + chrome.tabs.create({ url: Settings.get("newTabUrl") }); + chrome.tabs.remove(tabs[0].id); + } + }); + } else { + chrome.tabs.remove(tab.id); + } }); }, restoreTab: mkRepeatCommand((request, callback) => diff --git a/lib/settings.js b/lib/settings.js index 3663af266..140878b2f 100644 --- a/lib/settings.js +++ b/lib/settings.js @@ -69,6 +69,7 @@ w: https://www.wikipedia.org/w/index.php?title=Special:Search&search=%s Wikipedi waitForEnterForFilteredHints: true, helpDialog_showAdvancedCommands: false, ignoreKeyboardLayout: false, + keepLastTabOpen: false, }; /* diff --git a/pages/options.html b/pages/options.html index 9562e9eb4..f68ae0d65 100644 --- a/pages/options.html +++ b/pages/options.html @@ -232,6 +232,20 @@ + + + +
+
+ Do not close the last tab +
+
+ + + Default search
engine diff --git a/pages/options.js b/pages/options.js index 886beeb5a..f9cebd3b3 100644 --- a/pages/options.js +++ b/pages/options.js @@ -17,6 +17,7 @@ const options = { searchUrl: "string", settingsVersion: "string", // This is a hidden field. userDefinedLinkHintCss: "string", + keepLastTabOpen: "boolean", }; const OptionsPage = { From 1419f5797883bc60b69eb5b84079ff898adfb7cf Mon Sep 17 00:00:00 2001 From: O2bmm Date: Mon, 11 Dec 2023 13:20:40 +0800 Subject: [PATCH 2/2] Add Option Do not close the last tab --- background_scripts/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/background_scripts/main.js b/background_scripts/main.js index eae81b157..7d91cc16f 100644 --- a/background_scripts/main.js +++ b/background_scripts/main.js @@ -258,8 +258,8 @@ const BackgroundCommands = { chrome.tabs.query({ currentWindow: true }, function (tabs) { if(tabs.length == 1){ chrome.tabs.create({ url: Settings.get("newTabUrl") }); - chrome.tabs.remove(tabs[0].id); } + chrome.tabs.remove(tab.id); }); } else { chrome.tabs.remove(tab.id);