diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/features/easy-toggle-files.tsx | 34 | ||||
-rw-r--r-- | source/github-helpers/selectors.ts | 5 |
2 files changed, 39 insertions, 0 deletions
diff --git a/source/features/easy-toggle-files.tsx b/source/features/easy-toggle-files.tsx index db6d0381..74ed87e2 100644 --- a/source/features/easy-toggle-files.tsx +++ b/source/features/easy-toggle-files.tsx @@ -2,7 +2,9 @@ import {$} from 'select-dom'; import delegate, {DelegateEvent} from 'delegate-it'; import * as pageDetect from 'github-url-detection'; +import {codeSearchHeader} from '../github-helpers/selectors.js'; import features from '../feature-manager.js'; +import {isHasSelectorSupported} from '../helpers/select-has.js'; function toggleFile(event: DelegateEvent<MouseEvent>): void { const elementClicked = event.target as HTMLElement; @@ -15,14 +17,46 @@ function toggleFile(event: DelegateEvent<MouseEvent>): void { } } +function toggleCodeSearchFile(event: DelegateEvent<MouseEvent>): void { + const elementClicked = event.target as HTMLElement; + const headerBar = event.delegateTarget; + const toggle = $(':scope > button', headerBar)!; + + // The clicked element is either the bar itself or one of its children excluding the button + if (elementClicked === headerBar || (elementClicked.parentElement === headerBar && elementClicked !== toggle)) { + toggle.dispatchEvent(new MouseEvent('click', {bubbles: true, altKey: event.altKey})); + } +} + function init(signal: AbortSignal): void { delegate('.file-header', 'click', toggleFile, {signal}); } +function initSearchPage(signal: AbortSignal): void { + delegate(codeSearchHeader, 'click', toggleCodeSearchFile, {signal}); +} + void features.add(import.meta.url, { include: [ pageDetect.hasFiles, pageDetect.isGistRevision, ], init, +}, { + asLongAs: [ + isHasSelectorSupported, + ], + include: [ + pageDetect.isGlobalSearchResults, + ], + init: initSearchPage, }); + +/* + +## Test URLs + +- Pull Request: https://github.com/refined-github/refined-github/pull/7036/files +- Code Search: https://github.com/search?q=repo%3Arefined-github%2Frefined-github%20easy&type=code + +*/ diff --git a/source/github-helpers/selectors.ts b/source/github-helpers/selectors.ts index 453b4bc5..6b121ec8 100644 --- a/source/github-helpers/selectors.ts +++ b/source/github-helpers/selectors.ts @@ -48,3 +48,8 @@ export const actionsTab = '#actions-tab'; export const actionsTab_ = [ 'https://github.com/refined-github/sandbox', ]; + +export const codeSearchHeader = 'div:has(>:is([aria-label^="Collapse "], [aria-label^="Expand "]))'; +export const codeSearchHeader_ = [ + 'https://github.com/search?q=repo%3Arefined-github%2Frefined-github&type=code', +]; |