Skip to content

Commit

Permalink
feat: allow customizing new_tab_disable_name
Browse files Browse the repository at this point in the history
  • Loading branch information
Bush2021 committed Apr 1, 2024
1 parent b40ef02 commit b659f2e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 10 deletions.
55 changes: 45 additions & 10 deletions src/IAccessibleUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,34 @@ bool IsOnTheTabBar(NodePtr top, POINT pt) {

// 从当前标签页的名称判断是否是新标签页
bool IsNameNewTab(NodePtr top) {

std::vector<std::wstring> 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<wchar_t, decltype(&free)> new_tab_name(nullptr, free);
NodePtr PageTabList = FindElementWithRole(top, ROLE_SYSTEM_PAGETABLIST);
Expand All @@ -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;
}

Expand Down
Binary file modified src/chrome++.ini
Binary file not shown.
5 changes: 5 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_

0 comments on commit b659f2e

Please sign in to comment.