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 c582e51..ac26fb4 100644 Binary files a/src/chrome++.ini and b/src/chrome++.ini differ 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_