Skip to content

Commit c881c82

Browse files
committed
Fix processing of right sidebar
1 parent 812e01e commit c881c82

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

src/github-custom-global-navigation.user.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,8 +1579,6 @@
15791579
${elementSelector.right.modalDialog}
15801580
{
15811581
pointer-events: all;
1582-
margin-top: 55px;
1583-
margin-right: 20px;
15841582
animation: .2s cubic-bezier(.33,1,.68,1) !important;
15851583
border-top-right-radius: 0.75rem !important;
15861584
border-bottom-right-radius: 0.75rem !important;
@@ -2181,23 +2179,37 @@
21812179
};
21822180
}
21832181

2184-
function addMenuItemToActionList() {
2182+
function addMenuItemToActionList(_event, retryCount = 0) {
21852183
log(VERBOSE, 'addMenuItemToActionList()');
2184+
log(VERBOSE, 'retryCount', retryCount);
21862185

21872186
const liElementId = 'custom-global-navigation-menu-item';
21882187

2189-
if (document.querySelector(createId(liElementId))) return;
2188+
if (document.querySelector(createId(liElementId))) {
2189+
log(DEBUG, 'Menu item already exists, skipping addition');
2190+
return;
2191+
}
21902192

21912193
const actionList = document.querySelector(SELECTORS.sidebars.right.actionList);
21922194
if (!actionList) {
2193-
log(DEBUG, 'Action list not found');
2194-
return setTimeout(addMenuItemToActionList, 100);
2195+
if (retryCount < 20) {
2196+
log(DEBUG, 'Action list not found, retrying...');
2197+
return setTimeout(() => addMenuItemToActionList(retryCount + 1), 100);
2198+
} else {
2199+
logError('Action list not found after 2 seconds, giving up');
2200+
return;
2201+
}
21952202
}
21962203

21972204
const signOutLink = actionList.querySelector(SELECTORS.sidebars.right.signOutLink);
21982205
if (!signOutLink) {
2199-
log(DEBUG, 'Logout link not found');
2200-
return;
2206+
if (retryCount < 20) {
2207+
log(DEBUG, 'Logout link not found, retrying...');
2208+
return setTimeout(() => addMenuItemToActionList(retryCount + 1), 100);
2209+
} else {
2210+
logError('Logout link not found after 2 seconds, giving up');
2211+
return;
2212+
}
22012213
}
22022214

22032215
const signOutLi = signOutLink.parentNode;
@@ -3666,7 +3678,7 @@
36663678
topDiv: '#__primerPortalRoot__',
36673679
wrapper: '#__primerPortalRoot__ > div',
36683680
backdrop: '#__primerPortalRoot__ > div > [data-position-regular="right"]',
3669-
modalDialog: '#__primerPortalRoot__ > div > [data-position-regular="right"] > div',
3681+
modalDialog: '#__primerPortalRoot__ div[role="dialog"]',
36703682
closeButton: '#__primerPortalRoot__ button[aria-label="Close"]',
36713683
divider: 'li[data-component="ActionList.Divider"]',
36723684
actionList: '[class^="prc-ActionList-"]',

0 commit comments

Comments
 (0)