diff options
| -rw-r--r-- | readme.md | 1 | ||||
| -rw-r--r-- | source/features/unwrap-useless-dropdowns.tsx | 76 | ||||
| -rw-r--r-- | source/libs/page-detect.ts | 19 | ||||
| -rw-r--r-- | source/refined-github.ts | 1 |
4 files changed, 87 insertions, 10 deletions
@@ -328,6 +328,7 @@ Thanks for contributing! 🦋🙌 - [](# "fix-view-file-link-in-pr") [Points the "View file" in PRs to the branch instead of the commit, so the Edit/Delete buttons will be enabled on the "View file" page, if needed.](https://user-images.githubusercontent.com/1402241/69044026-c5b17d80-0a26-11ea-86ae-c95f89d3669a.png) - [](# "linkify-labels-on-dashboard") [Makes labels clickable in the dashboard’s "Recent activity" box.](https://user-images.githubusercontent.com/1402241/69045444-6ef97300-0a29-11ea-99a3-9a622c395709.png) - [](# "reload-failed-proxied-images") [Retries downloading images that failed downloading due to GitHub limited proxying.](https://user-images.githubusercontent.com/14858959/64068746-21991100-cc45-11e9-844e-827f5ac9b51e.png) +- [](# "unwrap-useless-dropdowns") [Makes some dropdowns 1-click instead of unnecessarily 2-click.](https://user-images.githubusercontent.com/1402241/80859624-9bfdb300-8c62-11ea-837f-7b7a28e6fdfc.png) - [](# "linkify-notification-repository-header") [Linkifies the header of each notification group (when grouped by repository).](https://user-images.githubusercontent.com/1402241/80849887-81531c00-8c19-11ea-8777-7294ce318630.png) <!-- Refer to style guide above. Keep this message between sections. --> diff --git a/source/features/unwrap-useless-dropdowns.tsx b/source/features/unwrap-useless-dropdowns.tsx new file mode 100644 index 00000000..51140f10 --- /dev/null +++ b/source/features/unwrap-useless-dropdowns.tsx @@ -0,0 +1,76 @@ +import select from 'select-dom'; +import elementReady from 'element-ready'; +import features from '../libs/features'; +import * as pageDetect from '../libs/page-detect'; + +// Replace dropdown while keeping its sizing/positioning classes +function replaceDropdownInPlace(dropdown: Element, form: Element): void { + dropdown.replaceWith(form); + form.classList.add(...dropdown.classList); + form.classList.remove('dropdown', 'details-reset', 'details-overlay'); +} + +async function unwrapNotifications(): Promise<void | false> { + await elementReady('.js-check-all-container > :nth-child(2)'); // Wait for filters to be ready + const forms = select.all('[action="/notifications/beta/update_view_preference"]'); + if (forms.length === 0) { + return false; + } + + if (forms.length > 2) { + throw new Error('GitHub added new view types. This feature is obsolete.'); + } + + const dropdown = forms[0].closest('details')!; + const currentView = select('summary i', dropdown)!.nextSibling!.textContent!.trim(); + const desiredForm = currentView === 'Date' ? forms[0] : forms[1]; + + // Replace dropdown + replaceDropdownInPlace(dropdown, desiredForm); + + // Fix button’s style + const button = select('[type="submit"]', desiredForm)!; + button.className = 'btn'; + button.textContent = `Group by ${button.textContent!.toLowerCase()}`; +} + +async function unwrapActionJobRun(): Promise<void | false> { + const desiredForm = await elementReady('.js-check-suite-rerequest-form'); + if (!desiredForm) { + return false; + } + + const availableOptions = desiredForm + .closest('.dropdown-menu')! + .querySelectorAll('li > *'); // GitHub left an empty `li` in there 😒 + if (availableOptions.length > 1) { + throw new Error('GitHub added items to the dropdown. This feature is obsolete.'); + } + + // Fix button’s style + const button = select('button', desiredForm)!; + button.className = 'btn btn-sm'; + button.prepend(select('.octicon-sync')!); + + // Replace dropdown + const dropdown = desiredForm.closest('details')!; + replaceDropdownInPlace(dropdown, desiredForm); +} + +features.add({ + id: __filebasename, + description: 'Makes some dropdowns 1-click instead of unnecessarily 2-click.', + screenshot: 'https://user-images.githubusercontent.com/1402241/80859624-9bfdb300-8c62-11ea-837f-7b7a28e6fdfc.png' +}, { + include: [ + pageDetect.isNotifications + ], + waitForDomReady: false, + init: unwrapNotifications +}, { + include: [ + pageDetect.isActionJobRun + ], + waitForDomReady: false, + init: unwrapActionJobRun +}); diff --git a/source/libs/page-detect.ts b/source/libs/page-detect.ts index 7def85c3..10339105 100644 --- a/source/libs/page-detect.ts +++ b/source/libs/page-detect.ts @@ -27,15 +27,7 @@ export const _isCommit = [ ]; export const isCommitList = (): boolean => isRepoCommitList() || isPRCommitList(); -export const _isCommitList = [ - 'https://github.com/sindresorhus/refined-github/commits/master?page=2', - 'https://github.com/sindresorhus/refined-github/commits/test-branch', - 'https://github.com/sindresorhus/refined-github/commits/0.13.0', - 'https://github.com/sindresorhus/refined-github/commits/230c2', - 'https://github.com/sindresorhus/refined-github/commits/230c2935fc5aea9a681174ddbeba6255ca040d63', - 'https://github.com/sindresorhus/refined-github/pull/148/commits', - 'https://github.com/sindresorhus/refined-github/commits?author=fregante' -]; +export const _isCommitList = skip; export const isRepoCommitList = (): boolean => String(getRepoPath()).startsWith('commits'); export const _isRepoCommitList = [ @@ -44,7 +36,8 @@ export const _isRepoCommitList = [ 'https://github.com/sindresorhus/refined-github/commits/0.13.0', 'https://github.com/sindresorhus/refined-github/commits/230c2', 'https://github.com/sindresorhus/refined-github/commits/230c2935fc5aea9a681174ddbeba6255ca040d63', - 'https://github.com/sindresorhus/refined-github/commits?author=fregante' + 'https://github.com/sindresorhus/refined-github/commits?author=fregante', + 'https://github.com/sindresorhus/runs/commits/' ]; export const isCompare = (): boolean => String(getRepoPath()).startsWith('compare'); @@ -410,3 +403,9 @@ export const _isActionPage = [ 'https://github.com/marketplace/actions/github-action-for-assignee-to-reviewer', 'https://github.com/marketplace/actions/hugo-actions' ]; + +export const isActionJobRun = (): boolean => String(getRepoPath()).startsWith('runs/'); +export const _isActionJobRun = [ + 'https://github.com/sindresorhus/refined-github/runs/639481849' +]; + diff --git a/source/refined-github.ts b/source/refined-github.ts index 1cb752c7..7f50e90c 100644 --- a/source/refined-github.ts +++ b/source/refined-github.ts @@ -173,6 +173,7 @@ import './features/clear-pr-merge-commit-message'; import './features/go-to-action-from-file'; import './features/action-used-by-link'; import './features/batch-mark-files-as-viewed'; +import './features/unwrap-useless-dropdowns'; import './features/linkify-notification-repository-header'; import './features/stop-redirecting-in-notification-bar'; |
