Skip to content

Commit

Permalink
pr-notification-link - New feature (#7104)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Dec 17, 2023
1 parent 7339ae8 commit cf69a82
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions build/__snapshots__/features-meta.json
Expand Up @@ -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.",
Expand Down
1 change: 1 addition & 0 deletions build/__snapshots__/imported-features.txt
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions readme.md
Expand Up @@ -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 <kbd>Alt</kbd>.](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)

<!-- Refer to style guide above. Keep this message between sections. -->
Expand Down
33 changes: 33 additions & 0 deletions 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
*/
1 change: 1 addition & 0 deletions source/refined-github.ts
Expand Up @@ -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';

0 comments on commit cf69a82

Please sign in to comment.