Skip to content

Commit ff75b7f

Browse files
authored
Merge pull request #1005 from Xsy41/fix/github-pr-tooltip
fix: restore repo PR tooltip on GitHub
2 parents bbd7133 + fe00e75 commit ff75b7f

File tree

1 file changed

+13
-8
lines changed
  • src/pages/ContentScripts/features/repo-pr-tooltip

1 file changed

+13
-8
lines changed

src/pages/ContentScripts/features/repo-pr-tooltip/index.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,8 @@ let PRDetail: PRDetail = {
2929
};
3030
let meta: RepoMeta;
3131
let platform: string;
32-
const pullRequestTabSelectors = [
33-
'a[data-tab-item="pull-requests"]',
34-
'#pull-requests-tab',
35-
'a[href$="/pulls"][data-selected-links*="repo_pulls"]',
36-
'a[href$="/pulls"]',
37-
];
32+
const pullRequestTabSelector = 'a[data-tab-item="pull-requests"]';
33+
const pullRequestFallbackSelectors = ['#pull-requests-tab', 'a[href$="/pulls"][data-selected-links*="repo_pulls"]'];
3834

3935
const getData = async () => {
4036
PRDetail.PROpened = await getPROpened(platform, repoName);
@@ -45,7 +41,13 @@ const getData = async () => {
4541
meta = (await metaStore.get(platform, repoName)) as RepoMeta;
4642
};
4743
const getPullRequestTab = () => {
48-
const $tabs = $(pullRequestTabSelectors.join(',')).filter((_, element) => !element.closest('template'));
44+
const $primaryTabs = $(pullRequestTabSelector).filter((_, element) => !element.closest('template'));
45+
const $visiblePrimaryTabs = $primaryTabs.filter(':visible');
46+
if ($visiblePrimaryTabs.length > 0 || $primaryTabs.length > 0) {
47+
return ($visiblePrimaryTabs.length > 0 ? $visiblePrimaryTabs : $primaryTabs).first();
48+
}
49+
50+
const $tabs = $(pullRequestFallbackSelectors.join(',')).filter((_, element) => !element.closest('template'));
4951
const $visibleTabs = $tabs.filter(':visible');
5052

5153
return ($visibleTabs.length > 0 ? $visibleTabs : $tabs).first();
@@ -55,8 +57,11 @@ const init = async (): Promise<void> => {
5557
platform = getPlatform();
5658
repoName = getRepoName();
5759
await getData();
58-
await elementReady(pullRequestTabSelectors.join(','));
60+
await elementReady([pullRequestTabSelector, ...pullRequestFallbackSelectors].join(','));
5961
const $prTab = getPullRequestTab();
62+
if ($prTab.length === 0) {
63+
return;
64+
}
6065
const placeholderElement = $('<div class="NativePopover" />').appendTo('body')[0];
6166
createRoot(placeholderElement).render(
6267
<NativePopover anchor={$prTab} width={340} arrowPosition="top-middle">

0 commit comments

Comments
 (0)