From b659f2e11a72a12db91cd2bbdce2c44051bb6d5f Mon Sep 17 00:00:00 2001 From: Bush2021 <79072750+Bush2021@users.noreply.github.com> Date: Sun, 31 Mar 2024 21:59:01 -0400 Subject: [PATCH] feat: allow customizing new_tab_disable_name --- src/IAccessibleUtils.h | 55 +++++++++++++++++++++++++++++++++-------- src/chrome++.ini | Bin 7514 -> 8538 bytes src/config.h | 5 ++++ 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/IAccessibleUtils.h b/src/IAccessibleUtils.h index 646adec..d2f8ce2 100644 --- a/src/IAccessibleUtils.h +++ b/src/IAccessibleUtils.h @@ -306,6 +306,34 @@ bool IsOnTheTabBar(NodePtr top, POINT pt) { // 从当前标签页的名称判断是否是新标签页 bool IsNameNewTab(NodePtr top) { + + std::vector disableTabNames; + std::wstring disableTabNamesStr = GetDisableTabName(); + std::wstring::size_type start = 0; + std::wstring::size_type end = disableTabNamesStr.find(L','); + while (end != std::wstring::npos) { + std::wstring name = disableTabNamesStr.substr(start, end - start); + if (!name.empty() && name.front() == L'"') { + name.erase(0, 1); + } + if (!name.empty() && name.back() == L'"') { + name.erase(name.size() - 1); + } + disableTabNames.push_back(name); + start = end + 1; + end = disableTabNamesStr.find(L',', start); + } + if (start < disableTabNamesStr.length()) { + std::wstring name = disableTabNamesStr.substr(start); + if (!name.empty() && name.front() == L'"') { + name.erase(0, 1); + } + if (!name.empty() && name.back() == L'"') { + name.erase(name.size() - 1); + } + disableTabNames.push_back(name); + } + bool flag = false; std::unique_ptr new_tab_name(nullptr, free); NodePtr PageTabList = FindElementWithRole(top, ROLE_SYSTEM_PAGETABLIST); @@ -332,17 +360,24 @@ bool IsNameNewTab(NodePtr top) { return false; } - TraversalAccessible(PageTabPane, [&flag, &new_tab_name](NodePtr child) { - if (GetAccessibleState(child) & STATE_SYSTEM_SELECTED) { - GetAccessibleName(child, [&flag, &new_tab_name](BSTR bstr) { - std::wstring_view bstr_view(bstr); - std::wstring_view new_tab_view(new_tab_name.get()); - flag = (bstr_view.find(new_tab_view) != std::wstring::npos) || - (bstr_view.find(L"about:blank") != std::wstring::npos); + TraversalAccessible( + PageTabPane, [&flag, &new_tab_name, &disableTabNames](NodePtr child) { + if (GetAccessibleState(child) & STATE_SYSTEM_SELECTED) { + GetAccessibleName( + child, [&flag, &new_tab_name, &disableTabNames](BSTR bstr) { + std::wstring_view bstr_view(bstr); + std::wstring_view new_tab_view(new_tab_name.get()); + flag = (bstr_view.find(new_tab_view) != std::wstring::npos); + for (const auto& disableTabName : disableTabNames) { + if (bstr_view.find(disableTabName) != std::wstring::npos) { + flag = true; + break; + } + } + }); + } + return false; }); - } - return false; - }); return flag; } diff --git a/src/chrome++.ini b/src/chrome++.ini index c582e51693ba9f78437b182863d19a10814feab7..ac26fb431b7c893af33c34c91426f45a4ba6e2ae 100644 GIT binary patch delta 662 zcmZuvO-lk%6uo^4p|l7c$VFlhQ}nqVh@w?(MpD6~KxT46$(b=ntq3x~z*ZI$B}I$= zLC}9_)gP!|(W;MCojcE{ARgTJ?!D)n`|f@3S$ST%D@pEAFzU;YMH-pz?O@QI9qjj| zC`SfaZap}v<;kH4&Cw)m7SS!r18u-7dnn#D(&2j=$S|IB8Z1W*tgIKaVResdQxQAo zvRuW-^-5&83!#--vZMQ3Pvb1uyVx~wna!Gfmk8}pg=|z4wPlK8jU%oh%P0q#B0T0Y zieozM!)}6SVrky3Wpp`SLwF0}5_S{91yJ&!7eM@O)}d*f#YI{CZ}SH2f#G=V3t>@4 zXqdoT$cZuWNWKTDqgtMZxZqT$vw{%1H>FnZe^1q&$hb%0XjD=8jUx1F_&?>;Q|s~U zrX5OOt*@wbSwEr7Op;;#M%9-)JgBq-$(Mb1F|@qFhgwXo1T$}m2>nd1FY(dze-5W7 zR6&p{(y2gTLa5UpKfmaneQI5+tgsPN)Z)&Hq?}kbZ;_8<1ORC%2ulC} diff --git a/src/config.h b/src/config.h index 7bdfdac..01ac016 100644 --- a/src/config.h +++ b/src/config.h @@ -139,4 +139,9 @@ bool IsNewTabDisableFun() { return ::GetPrivateProfileIntW(L"Tabs", L"new_tab_disable", 1, IniPath.c_str()) != 0; } +// 自定义禁用标签页名称 +std::wstring GetDisableTabName() { + return IsIniExist() ? GetIniString(L"Tabs", L"new_tab_disable_name", L"") : L""; +} + #endif // CONFIG_H_