diff --git a/build/__snapshots__/features-meta.json b/build/__snapshots__/features-meta.json index 603190153c8..bc938e51088 100644 --- a/build/__snapshots__/features-meta.json +++ b/build/__snapshots__/features-meta.json @@ -579,6 +579,11 @@ "description": "Jumps to first non-viewed file in a pull request when clicking on the progress bar.", "screenshot": "https://github-production-user-asset-6210df.s3.amazonaws.com/140871606/257011208-764f509d-fed9-424b-84e9-c01cf2fd428b.gif" }, + { + "id": "pr-notification-link", + "description": "Points PR notifications to the conversation tabs instead of the commits page, which may be a 404.", + "screenshot": "https://github.com/refined-github/refined-github/assets/1402241/621f6512-655e-4565-a37b-2b159ea0ffce" + }, { "id": "prevent-comment-loss", "description": "While writing/editing comments, open the preview links in new tab instead of navigating away from the page.", diff --git a/build/__snapshots__/imported-features.txt b/build/__snapshots__/imported-features.txt index 41c06d4a1b4..ad05f6f3099 100644 --- a/build/__snapshots__/imported-features.txt +++ b/build/__snapshots__/imported-features.txt @@ -113,6 +113,7 @@ pr-branch-auto-delete pr-commit-lines-changed pr-filters pr-jump-to-first-non-viewed-file +pr-notification-link prevent-comment-loss prevent-duplicate-pr-submission prevent-link-loss diff --git a/readme.md b/readme.md index 13be6081994..007e46d6121 100644 --- a/readme.md +++ b/readme.md @@ -350,6 +350,7 @@ Thanks for contributing! 🦋🙌 - [](# "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) - [](# "stop-redirecting-in-notification-bar") [Stops redirecting to notification inbox from notification bar actions while holding Alt.](https://user-images.githubusercontent.com/202916/80318782-c38cef80-880c-11ea-9226-72c585f42a51.png) - [](# "last-notification-page-button") [Adds a link to the last page of notifications.](https://user-images.githubusercontent.com/16872793/199828181-3ff2cef3-8740-4efa-8122-8f2f222bd657.png) +- [](# "pr-notification-link") [Points PR notifications to the conversation tabs instead of the commits page, which may be a 404.](https://github.com/refined-github/refined-github/assets/1402241/621f6512-655e-4565-a37b-2b159ea0ffce) - [](# "sticky-notifications-actions") [Make the notifications action bar sticky.](https://github.com/refined-github/refined-github/assets/1402241/5b370430-2319-4c78-88e7-c2c06cd1c30f) diff --git a/source/features/pr-notification-link.tsx b/source/features/pr-notification-link.tsx new file mode 100644 index 00000000000..c8f6721c00a --- /dev/null +++ b/source/features/pr-notification-link.tsx @@ -0,0 +1,33 @@ +import * as pageDetect from 'github-url-detection'; + +import features from '../feature-manager.js'; +import observe from '../helpers/selector-observer.js'; + +const regex = /\/files\/[\da-f]{40}..[\da-f]{40}$/; + +function trimLink(link: HTMLAnchorElement): void { + if (regex.test(link.pathname)) { + link.pathname = link.pathname.replace(regex, ''); + link.hash = '#issue-comment-box'; + } +} + +function init(signal: AbortSignal): void { + // It's ok if it's not 100% safe because trimLink's regex is super specific + observe('[href*="/pull/"][href*="/files/"][href*=".."]', trimLink, {signal}); +} + +void features.add(import.meta.url, { + include: [ + pageDetect.isNotifications, + ], + init, +}); + +/* + +Test URL: + +https://github.com/notifications + +*/ diff --git a/source/refined-github.ts b/source/refined-github.ts index 067386da30c..0398de4156b 100644 --- a/source/refined-github.ts +++ b/source/refined-github.ts @@ -221,4 +221,5 @@ import './features/visit-tag.js'; import './features/prevent-comment-loss.js'; import './features/fix-no-pr-search.js'; import './features/clean-readme-url.js'; +import './features/pr-notification-link.js'; import './features/click-outside-modal.js';