From c72d94ee292352bb3363e4d417e9076c1a7218e4 Mon Sep 17 00:00:00 2001 From: "YUKI \"Piro\" Hiroshi" Date: Thu, 18 Jan 2024 03:33:06 +0900 Subject: [PATCH] Guess new tab command tab more certainly with its title #3291 --- webextensions/_locales/en/messages.json | 8 ++++++-- webextensions/_locales/ja/messages.json | 9 +++++++-- webextensions/background/api-tabs-listener.js | 2 +- webextensions/background/handle-new-tabs.js | 2 +- webextensions/common/Tab.js | 6 +++--- webextensions/common/common.js | 8 +++++--- webextensions/options/options.html | 3 +++ webextensions/sidebar/gap-canceller.js | 19 ++++++++++++------- 8 files changed, 38 insertions(+), 19 deletions(-) diff --git a/webextensions/_locales/en/messages.json b/webextensions/_locales/en/messages.json index 18a9301a2..43f356916 100644 --- a/webextensions/_locales/en/messages.json +++ b/webextensions/_locales/en/messages.json @@ -269,6 +269,9 @@ "api_requestedPermissions_type_cookies": { "message": "Detect container of browser tabs" }, + "guessNewOrphanTabAsOpenedByNewTabCommandTitle": { "message": "New Tab|New Private Tab" }, + + "context_menu_label": { "message": "Tree of tabs" }, "context_reloadTree_label": { "message": "&Reload this Tree" }, @@ -455,8 +458,9 @@ "config_autoAttachOnNewTabCommand_sibling": { "message": "Sibling of the current tab" }, "config_autoAttachOnNewTabCommand_nextSibling": { "message": "Next Sibling of the current tab" }, "config_autoAttachOnNewTabCommand_after": { "message": "\u200b" }, - "config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_before": { "message": "Guess a newly opened tab as opened by \"New Blank Tab\" action, when it is opened with URL(s) " }, - "config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_after": { "message": "(*You can list multiple URLs with a separator \"|\")" }, + "config_guessNewOrphanTabAsOpenedByNewTabCommandTitle_before": { "message": "Guess a newly opened tab as opened by \"New Blank Tab\" action, when it is opened with title(s) " }, + "config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_before": { "message": " or URL(s) " }, + "config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_after": { "message": "(*You can list multiple values with a separator \"|\")" }, "config_autoAttachOnNewTabButtonMiddleClick_before": { "message": "For middle click, open new blank tab as" }, "config_autoAttachOnNewTabButtonMiddleClick_noControl": { "message": "(no control)" }, diff --git a/webextensions/_locales/ja/messages.json b/webextensions/_locales/ja/messages.json index 59ee5a756..cedc19e86 100644 --- a/webextensions/_locales/ja/messages.json +++ b/webextensions/_locales/ja/messages.json @@ -268,6 +268,10 @@ "api_requestedPermissions_type_tabs": { "message": "ブラウザーのタブへのアクセス" }, "api_requestedPermissions_type_cookies": { "message": "ブラウザーのタブのコンテナーの識別" }, + + "guessNewOrphanTabAsOpenedByNewTabCommandTitle": { "message": "新しいタブ|新しいプライベートタブ" }, + + "context_menu_label": { "message": "タブのツリーを操作" }, "context_reloadTree_label": { "message": "このツリーを再読み込み(&R)" }, @@ -451,8 +455,9 @@ "config_autoAttachOnNewTabCommand_sibling": { "message": "現在のタブと同階層に" }, "config_autoAttachOnNewTabCommand_nextSibling": { "message": "現在のタブと同階層で隣に" }, "config_autoAttachOnNewTabCommand_after": { "message": "開く" }, - "config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_before": { "message": "URLが" }, - "config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_after": { "message": "であるタブが開かれた場合、新しい空のタブが開かれたとみなす(※「|」で区切って複数URLを列挙可能)" }, + "config_guessNewOrphanTabAsOpenedByNewTabCommandTitle_before": { "message": "タイトルが" }, + "config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_before": { "message": "またはURLが" }, + "config_guessNewOrphanTabAsOpenedByNewTabCommandUrl_after": { "message": "であるタブが開かれた場合、新しい空のタブが開かれたとみなす(※「|」で区切って複数の値を列挙可能)" }, "config_autoAttachOnNewTabButtonMiddleClick_before": { "message": "中クリックした時、新しい空のタブを" }, "config_autoAttachOnNewTabButtonMiddleClick_noControl": { "message": "(制御せず既定の位置に)" }, diff --git a/webextensions/background/api-tabs-listener.js b/webextensions/background/api-tabs-listener.js index f3aed1e68..3bcbdda75 100644 --- a/webextensions/background/api-tabs-listener.js +++ b/webextensions/background/api-tabs-listener.js @@ -14,7 +14,7 @@ * The Original Code is the Tree Style Tab. * * The Initial Developer of the Original Code is YUKI "Piro" Hiroshi. - * Portions created by the Initial Developer are Copyright (C) 2011-2021 + * Portions created by the Initial Developer are Copyright (C) 2011-2024 * the Initial Developer. All Rights Reserved. * * Contributor(s): YUKI "Piro" Hiroshi diff --git a/webextensions/background/handle-new-tabs.js b/webextensions/background/handle-new-tabs.js index f7943e514..e0709a677 100644 --- a/webextensions/background/handle-new-tabs.js +++ b/webextensions/background/handle-new-tabs.js @@ -136,7 +136,7 @@ Tab.onCreating.addListener((tab, info = {}) => { }).then(moved => !moved); }); } - log('behave as a tab opened with any URL'); + log('behave as a tab opened with any URL ', tab.title, tab.url); if (!info.restored && !info.positionedBySelf && !info.bypassTabControl && diff --git a/webextensions/common/Tab.js b/webextensions/common/Tab.js index 8663b0845..ab760bdd1 100644 --- a/webextensions/common/Tab.js +++ b/webextensions/common/Tab.js @@ -14,7 +14,7 @@ import { mapAndFilterUniq, toLines, sanitizeForRegExpSource, - isNewTabCommandURL, + isNewTabCommandTab, configs, } from './common.js'; @@ -302,8 +302,8 @@ export default class Tab { !configs.guessNewOrphanTabAsOpenedByNewTabCommand) return false; - if (!isNewTabCommandURL(this.tab.url)) - return false; + if (isNewTabCommandTab(this.tab)) + return true; // Firefox always opens a blank tab as the placeholder, when trying to // open a bookmark in a new tab. So, we cannot determine is the tab diff --git a/webextensions/common/common.js b/webextensions/common/common.js index 6653d9358..a054c3ff6 100644 --- a/webextensions/common/common.js +++ b/webextensions/common/common.js @@ -255,6 +255,7 @@ export const configs = new Configs({ autoAttachOnOpenedFromExternal: Constants.kNEWTAB_DO_NOTHING, autoAttachOnAnyOtherTrigger: Constants.kNEWTAB_DO_NOTHING, guessNewOrphanTabAsOpenedByNewTabCommand: true, + guessNewOrphanTabAsOpenedByNewTabCommandTitle: browser.i18n.getMessage('guessNewOrphanTabAsOpenedByNewTabCommandTitle'), guessNewOrphanTabAsOpenedByNewTabCommandUrl: 'about:newtab|about:privatebrowsing', inheritContextualIdentityToChildTabMode: Constants.kCONTEXTUAL_IDENTITY_DEFAULT, inheritContextualIdentityToSameSiteOrphanMode: Constants.kCONTEXTUAL_IDENTITY_FROM_LAST_ACTIVE, @@ -949,9 +950,10 @@ export function getWindowParamsFromSource(sourceWindow, { left, top, width, heig return params; } -export function isNewTabCommandURL(url) { - const newTabUrls = new Set(configs.guessNewOrphanTabAsOpenedByNewTabCommandUrl.split('|')); - return newTabUrls.has(url); +export function isNewTabCommandTab(tab) { + const newTabTitles = new Set(configs.guessNewOrphanTabAsOpenedByNewTabCommandTitle.split('|')); + const newTabUrls = new Set(configs.guessNewOrphanTabAsOpenedByNewTabCommandUrl.split('|')); + return newTabTitles.has(tab.title) || newTabUrls.has(tab.url); } diff --git a/webextensions/options/options.html b/webextensions/options/options.html index 2a867a0e2..10261bc26 100644 --- a/webextensions/options/options.html +++ b/webextensions/options/options.html @@ -463,6 +463,9 @@

__MSG_config_newTab_caption__