diff options
Diffstat (limited to 'source/features/clean-repo-filelist-actions.tsx')
-rw-r--r-- | source/features/clean-repo-filelist-actions.tsx | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/source/features/clean-repo-filelist-actions.tsx b/source/features/clean-repo-filelist-actions.tsx index 9105826f..4c3f7b06 100644 --- a/source/features/clean-repo-filelist-actions.tsx +++ b/source/features/clean-repo-filelist-actions.tsx @@ -15,42 +15,44 @@ function addTooltipToSummary(childElement: Element, tooltip: string): void { ); } -function init(): Deinit { - // `.btn` selects the desktop version - return observe('.btn[data-hotkey="t"]:not(.rgh-repo-filelist-actions)', { - add(searchButton) { - searchButton.classList.add('tooltipped', 'tooltipped-ne', 'rgh-repo-filelist-actions'); - searchButton.setAttribute('aria-label', 'Go to file'); +function cleanFilelistActions(searchButton: Element): void { + searchButton.classList.add('tooltipped', 'tooltipped-ne', 'rgh-repo-filelist-actions'); + searchButton.setAttribute('aria-label', 'Go to file'); + + // Replace "Go to file" with icon + searchButton.firstChild!.replaceWith(<SearchIcon/>); - // Replace "Go to file" with icon - searchButton.firstChild!.replaceWith(<SearchIcon/>); + // This button doesn't appear on `isSingleFile` + const addFileDropdown = searchButton.nextElementSibling!.querySelector('.dropdown-caret'); + if (addFileDropdown) { + addFileDropdown.parentElement!.classList.replace('d-md-flex', 'd-md-block'); - // This button doesn't appear on `isSingleFile` - const addFileDropdown = searchButton.nextElementSibling!.querySelector('.dropdown-caret'); - if (addFileDropdown) { - addFileDropdown.parentElement!.classList.replace('d-md-flex', 'd-md-block'); + // Replace "Add file" with icon + addFileDropdown.previousSibling!.replaceWith(<PlusIcon/>); - // Replace "Add file" with icon - addFileDropdown.previousSibling!.replaceWith(<PlusIcon/>); + addTooltipToSummary(addFileDropdown, 'Add file'); + } - addTooltipToSummary(addFileDropdown, 'Add file'); - } + const codeDropdownButton = select('get-repo summary'); + if (codeDropdownButton) { // This dropdown doesn't appear on `isSingleFile` + addTooltipToSummary(codeDropdownButton, 'Clone, open or download'); - const codeDropdownButton = select('get-repo summary'); - if (codeDropdownButton) { // This dropdown doesn't appear on `isSingleFile` - addTooltipToSummary(codeDropdownButton, 'Clone, open or download'); + // Users with Codespaces enabled already have an icon in the button https://github.com/refined-github/refined-github/pull/5074#issuecomment-983251719 + const codeIcon = select('.octicon-code', codeDropdownButton); + if (codeIcon) { + // Remove "Code" text + codeIcon.nextSibling!.remove(); + } else { + // Replace "Code" text with icon + codeDropdownButton.firstChild!.replaceWith(<CodeIcon/>); + } + } +} - // Users with Codespaces enabled already have an icon in the button https://github.com/refined-github/refined-github/pull/5074#issuecomment-983251719 - const codeIcon = select('.octicon-code', codeDropdownButton); - if (codeIcon) { - // Remove "Code" text - codeIcon.nextSibling!.remove(); - } else { - // Replace "Code" text with icon - codeDropdownButton.firstChild!.replaceWith(<CodeIcon/>); - } - } - }, +function init(): Deinit { + // `.btn` selects the desktop version + return observe('.btn[data-hotkey="t"]:not(.rgh-repo-filelist-actions)', { + add: cleanFilelistActions, }); } |