|
20 | 20 | (function () { |
21 | 21 | 'use strict'; |
22 | 22 |
|
| 23 | + const VERSION = '1.6.8'; |
| 24 | + |
23 | 25 | const SILENT = 0; |
24 | 26 | const QUIET = 1; |
25 | 27 | const INFO = 2; |
|
29 | 31 |
|
30 | 32 | let CURRENT_LOG_LEVEL = QUIET; |
31 | 33 |
|
| 34 | + // Change to SILENT, QUIET, INFO, DEBUG, VERBOSE, or TRACE |
| 35 | + const LOG_LEVEL_OVERRIDE = DEBUG; |
| 36 | + |
32 | 37 | const USERSCRIPT_NAME = 'GitHub Custom Global Navigation'; |
33 | 38 |
|
34 | | - function log(level, message, variable = -1) { |
| 39 | + function log (level, message, variable = undefined) { |
35 | 40 | if (CURRENT_LOG_LEVEL < level) return; |
36 | 41 |
|
37 | | - console.log(`${USERSCRIPT_NAME}: ${message}`); |
38 | | - if (variable !== -1) console.log(variable); |
| 42 | + const levelName = { |
| 43 | + 0: 'silent', |
| 44 | + 1: 'quiet', |
| 45 | + 2: 'info', |
| 46 | + 3: 'debug', |
| 47 | + 4: 'verbose', |
| 48 | + 5: 'trace', |
| 49 | + }[level]; |
| 50 | + |
| 51 | + const log = `[${VERSION}] [${levelName}] ${USERSCRIPT_NAME}: ${message}`; |
| 52 | + |
| 53 | + console.groupCollapsed(log); |
| 54 | + |
| 55 | + if (variable !== undefined) console.dir(variable, { depth: null }); |
| 56 | + |
| 57 | + console.trace(); |
| 58 | + console.groupEnd(); |
39 | 59 | } |
40 | 60 |
|
41 | 61 | function logError(message, variable = null) { |
|
1293 | 1313 | button.appendChild(divElement); |
1294 | 1314 | } |
1295 | 1315 |
|
1296 | | - function updateAvatarButton() { |
1297 | | - log(DEBUG, 'updateAvatarButton()'); |
1298 | | - |
1299 | | - const elementSelector = SELECTORS.sidebars.right; |
1300 | | - const backdropSelector = elementSelector.backdrop; |
1301 | | - |
1302 | | - const backdrop = HEADER.querySelector(backdropSelector); |
1303 | | - |
1304 | | - if (!backdrop) { |
1305 | | - log(DEBUG, `Selector ${backdropSelector} not found`); |
1306 | | - return; |
1307 | | - } |
1308 | | - |
1309 | | - const avatarButton = HEADER.querySelector(SELECTORS.avatar.button); |
1310 | | - |
1311 | | - if (!avatarButton) { |
1312 | | - log(DEBUG, `Selector ${SELECTORS.avatar.button} not found`); |
1313 | | - return; |
1314 | | - } |
1315 | | - |
1316 | | - if (backdrop.classList.contains('Overlay--hidden')) { |
1317 | | - if (avatarButton.hasAttribute('data-close-dialog-id')) { |
1318 | | - const dialogId = avatarButton.getAttribute('data-close-dialog-id'); |
1319 | | - avatarButton.setAttribute('data-show-dialog-id', dialogId); |
1320 | | - |
1321 | | - avatarButton.removeAttribute('data-close-dialog-id'); |
1322 | | - } |
1323 | | - } else { |
1324 | | - if (avatarButton.hasAttribute('data-show-dialog-id')) { |
1325 | | - const dialogId = avatarButton.getAttribute('data-show-dialog-id'); |
1326 | | - avatarButton.setAttribute('data-close-dialog-id', dialogId); |
1327 | | - |
1328 | | - avatarButton.removeAttribute('data-show-dialog-id'); |
1329 | | - } |
1330 | | - } |
1331 | | - } |
1332 | | - |
1333 | 1316 | function updateAvatar() { |
1334 | 1317 | log(DEBUG, 'updateAvatar()'); |
1335 | 1318 |
|
|
1527 | 1510 | LEFT_SIDEBAR_PRELOADED = true; |
1528 | 1511 | } |
1529 | 1512 |
|
1530 | | - function preloadRightSidebar() { |
1531 | | - log(DEBUG, 'preloadRightSidebar()'); |
1532 | | - |
1533 | | - if (RIGHT_SIDEBAR_PRELOADED) return; |
1534 | | - |
1535 | | - const temporaryStyleId = 'temporaryStyle'; |
1536 | | - |
1537 | | - const avatarButton = HEADER.querySelector(SELECTORS.avatar.button); |
1538 | | - if (!avatarButton) { |
1539 | | - setTimeout(preloadRightSidebar, 100); |
1540 | | - } else { |
1541 | | - avatarButton.click(); |
1542 | | - const closeButton = document.querySelector(SELECTORS.sidebars.right.closeButton); |
1543 | | - |
1544 | | - if (!document.querySelector(createId(temporaryStyleId))) { |
1545 | | - // Hide the sidebar |
1546 | | - let temporaryStyle = document.createElement('style'); |
1547 | | - temporaryStyle.setAttribute('id', temporaryStyleId); |
1548 | | - temporaryStyle.textContent += ` |
1549 | | - #__primerPortalRoot__ |
1550 | | - { |
1551 | | - display: none; |
1552 | | - } |
1553 | | - `; |
1554 | | - document.body.appendChild(temporaryStyle); |
1555 | | - } |
1556 | | - |
1557 | | - if (!closeButton) { |
1558 | | - setTimeout(preloadRightSidebar, 100); |
1559 | | - } else { |
1560 | | - closeButton.click(); |
1561 | | - |
1562 | | - log(INFO, 'Right sidebar preloaded'); |
1563 | | - document.querySelector(createId(temporaryStyleId)).remove(); |
1564 | | - RIGHT_SIDEBAR_PRELOADED = true; |
1565 | | - } |
1566 | | - } |
1567 | | - } |
1568 | | - |
1569 | 1513 | function updateSidebars() { |
1570 | 1514 | log(DEBUG, 'updateSidebars()'); |
1571 | 1515 |
|
|
1576 | 1520 |
|
1577 | 1521 | if (elementConfig.backdrop.color !== '') { |
1578 | 1522 | HEADER_STYLE.textContent += ` |
1579 | | - ${elementSelector.backdrop} |
| 1523 | + ${elementSelector.left.backdrop}, |
| 1524 | + ${elementSelector.right.backdrop} |
1580 | 1525 | { |
1581 | 1526 | background: ${CONFIG.sidebars.backdrop.color} !important; |
1582 | 1527 | } |
|
1587 | 1532 |
|
1588 | 1533 | if (elementConfig.right.floatUnderneath) { |
1589 | 1534 | HEADER_STYLE.textContent += ` |
1590 | | - ${elementSelector.right.modalDialog} |
| 1535 | + ${elementSelector.right.backdrop} |
1591 | 1536 | { |
1592 | | - border-top-right-radius: 0.75rem !important; |
1593 | | - border-bottom-right-radius: 0.75rem !important; |
1594 | 1537 | bottom: initial !important; |
1595 | 1538 | margin-top: 55px; |
1596 | 1539 | margin-right: 20px; |
1597 | 1540 | } |
| 1541 | +
|
| 1542 | + ${elementSelector.right.modalDialog} |
| 1543 | + { |
| 1544 | + border-top-right-radius: 0.75rem !important; |
| 1545 | + border-bottom-right-radius: 0.75rem !important; |
| 1546 | + } |
1598 | 1547 | `; |
1599 | 1548 | } |
1600 | 1549 |
|
1601 | | - if (elementConfig.right.preload) preloadRightSidebar(); |
1602 | | - |
1603 | 1550 | if (elementConfig.right.maxHeight) { |
1604 | 1551 | HEADER_STYLE.textContent += ` |
1605 | 1552 | ${elementSelector.right.modalDialog} |
|
2392 | 2339 | verbose: VERBOSE, |
2393 | 2340 | trace: TRACE, |
2394 | 2341 | }[GMC.get('log_level')]; |
| 2342 | + |
| 2343 | + if (LOG_LEVEL_OVERRIDE) CURRENT_LOG_LEVEL = LOG_LEVEL_OVERRIDE; |
2395 | 2344 | } |
2396 | 2345 |
|
2397 | 2346 | function gmcSaved() { |
|
3327 | 3276 | return 'break'; |
3328 | 3277 | } else { |
3329 | 3278 | if (CONFIG.avatar.dropdownIcon) insertAvatarDropdown(); |
3330 | | - if (CONFIG.avatar.canCloseSidebar) updateAvatarButton(); |
3331 | 3279 |
|
3332 | 3280 | if (CONFIG.repositoryHeader.import) { |
3333 | 3281 | // When starting in a repository tab like Issues, the proper repository header |
|
3522 | 3470 | bottomBorder: `.${REPOSITORY_HEADER_CLASS} .border-bottom.mx-xl-5`, |
3523 | 3471 | }, |
3524 | 3472 | sidebars: { |
3525 | | - backdrop: 'dialog.Overlay.SidePanel::backdrop', |
3526 | 3473 | left: { |
| 3474 | + backdrop: 'dialog[data-target="deferred-side-panel.panel"]::backdrop', |
3527 | 3475 | modalDialog: '.Overlay--placement-left', |
3528 | 3476 | }, |
3529 | 3477 | right: { |
3530 | 3478 | topDiv: '#__primerPortalRoot__', |
3531 | 3479 | wrapper: '#__primerPortalRoot__ > div', |
3532 | 3480 | backdrop: '#__primerPortalRoot__ > div > [data-position-regular="right"]', |
| 3481 | + modalDialog: '#__primerPortalRoot__ > div > [data-position-regular="right"] > div', |
3533 | 3482 | closeButton: '#__primerPortalRoot__ button[aria-label="Close"]', |
3534 | 3483 | divider: 'li[data-component="ActionList.Divider"]', |
3535 | 3484 | }, |
|
3738 | 3687 | remove: false, |
3739 | 3688 | size: '', |
3740 | 3689 | dropdownIcon: false, |
3741 | | - canCloseSidebar: true, |
3742 | 3690 | }, |
3743 | 3691 | globalBar: { |
3744 | 3692 | boxShadowColor: '', |
|
3985 | 3933 | remove: false, |
3986 | 3934 | size: '', |
3987 | 3935 | dropdownIcon: false, |
3988 | | - canCloseSidebar: true, |
3989 | 3936 | }, |
3990 | 3937 | globalBar: { |
3991 | 3938 | boxShadowColor: '', |
|
4236 | 4183 | remove: false, |
4237 | 4184 | size: '24px', |
4238 | 4185 | dropdownIcon: true, |
4239 | | - canCloseSidebar: true, |
4240 | 4186 | }, |
4241 | 4187 | globalBar: { |
4242 | 4188 | boxShadowColor: '#21262D', |
|
4268 | 4214 | preload: true, |
4269 | 4215 | floatUnderneath: true, |
4270 | 4216 | width: '', |
4271 | | - maxHeight: '50vh', |
| 4217 | + maxHeight: '60vh', |
4272 | 4218 | }, |
4273 | 4219 | }, |
4274 | 4220 | repositoryHeader: { |
|
4483 | 4429 | remove: false, |
4484 | 4430 | size: '24px', |
4485 | 4431 | dropdownIcon: true, |
4486 | | - canCloseSidebar: true, |
4487 | 4432 | }, |
4488 | 4433 | globalBar: { |
4489 | 4434 | boxShadowColor: '#21262D', |
|
4515 | 4460 | preload: true, |
4516 | 4461 | floatUnderneath: true, |
4517 | 4462 | width: '', |
4518 | | - maxHeight: '50vh', |
| 4463 | + maxHeight: '60vh', |
4519 | 4464 | }, |
4520 | 4465 | }, |
4521 | 4466 | repositoryHeader: { |
|
5092 | 5037 | type: 'checkbox', |
5093 | 5038 | default: false, |
5094 | 5039 | }, |
5095 | | - light_avatar_canCloseSidebar: { |
5096 | | - label: 'Can close sidebar', |
5097 | | - type: 'checkbox', |
5098 | | - default: false, |
5099 | | - }, |
5100 | 5040 | light_globalBar_boxShadowColor: { |
5101 | 5041 | label: '<h3>Global bar</h3><div class="gmc-label">Box shadow color</div>', |
5102 | 5042 | type: 'text', |
|
5715 | 5655 | type: 'checkbox', |
5716 | 5656 | default: false, |
5717 | 5657 | }, |
5718 | | - dark_avatar_canCloseSidebar: { |
5719 | | - label: 'Can close sidebar', |
5720 | | - type: 'checkbox', |
5721 | | - default: false, |
5722 | | - }, |
5723 | 5658 | dark_globalBar_boxShadowColor: { |
5724 | 5659 | label: '<h3>Global bar</h3><div class="gmc-label">Box shadow color</div>', |
5725 | 5660 | type: 'text', |
|
0 commit comments