Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function init(): void {

void features.add(import.meta.url, {
include: [
pageDetect.isPR, // Find which one you need on https://fregante.github.io/github-url-detection/
pageDetect.isPR, // Find which one you need on https://refined-github.github.io/github-url-detection/
],
awaitDomReady: true,
init,
Expand Down
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"dependencies": {
"@cheap-glitch/mi-cron": "^1.0.1",
"@primer/octicons-react": "^17.5.0",
"@sindresorhus/to-milliseconds": "^2.0.0",
"array-union": "^3.0.1",
"batched-function": "^2.0.1",
"code-tag": "^1.1.0",
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ Thanks for contributing! 🦋🙌
- [](# "no-duplicate-list-update-time") [Hides the update time of conversations in lists when it matches the open/closed/merged time.](https://user-images.githubusercontent.com/1402241/111357166-ac3a3900-864e-11eb-884a-d6d6da88f7e2.png)
- [](# "linkify-user-labels") [Links the "Contributor" and "Member" labels on comments to the author’s commits on the repo.](https://user-images.githubusercontent.com/1402241/177033344-4d4eea63-e075-4096-b2d4-f4b879f1df31.png)
- [](# "jump-to-conversation-close-event") [Adds a link to jump to the latest close event of a conversation.](https://user-images.githubusercontent.com/16872793/177792713-64219754-f8df-4629-a9ec-33259307cfe7.gif)
- [](# "unhide-reactions-on-mobile") [Unhides reactions button on mobile.](https://user-images.githubusercontent.com/38327267/205493629-14563105-eaa1-4885-9f07-8b3ee9214c86.png)
- [](# "unhide-reactions-on-mobile") [Restores reactions button on mobile.](https://user-images.githubusercontent.com/38327267/205493629-14563105-eaa1-4885-9f07-8b3ee9214c86.png)
- [](# "netiquette") [Adds unobtrusive netiquette reminders.](https://user-images.githubusercontent.com/1402241/226551766-0e1b6b15-65a3-427e-8bb5-9ea7873993be.png)

<!-- Refer to style guide above. Keep this message between sections. -->

Expand Down
4 changes: 2 additions & 2 deletions source/features/closing-remarks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ async function addReleaseBanner(text = 'Now you can release this change'): Promi
attachElement('#issue-comment-box', {
before: () => (
<TimelineItem>
{createBanner({
{createBanner(url ? {
text,
url,
buttonLabel: <><TagIcon/> Draft a new release</>,
})}
} : {text})}
</TimelineItem>
),
});
Expand Down
29 changes: 17 additions & 12 deletions source/features/jump-to-conversation-close-event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,40 @@ import {wrap} from '../helpers/dom-utils';
import features from '../feature-manager';
import observe from '../helpers/selector-observer';

function addToConversation(discussionHeader: HTMLElement): void {
// Avoid native `title` by disabling pointer events, we have our own `aria-label`. We can't drop the `title` attribute because some features depend on it.
discussionHeader.style.pointerEvents = 'none';
export const closedOrMergedMarkerSelector = css`

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just extracting and reusing selectors

#partial-discussion-header :is(
[title^="Status: Closed"],
[title^="Status: Merged"]
)
`;

const lastCloseEvent = select.last(`
export function getLastCloseEvent(): HTMLElement | undefined {
return select.last(`
.TimelineItem-badge :is(
.octicon-issue-closed,
.octicon-git-merge,
.octicon-git-pull-request-closed,
.octicon-skip
)
`)!.closest('.TimelineItem')!;
`)!.closest('.TimelineItem') ?? undefined;
}

function addToConversation(discussionHeader: HTMLElement): void {
// Avoid native `title` by disabling pointer events, we have our own `aria-label`. We can't drop the `title` attribute because some features depend on it.
discussionHeader.style.pointerEvents = 'none';

wrap(discussionHeader,
<a
aria-label="Scroll to most recent close event"
className="tooltipped tooltipped-s"
href={'#' + lastCloseEvent.id}
href={'#' + getLastCloseEvent()!.id}
/>,
);
}

function init(signal: AbortSignal): void {
observe(
css`
#partial-discussion-header :is(
[title^="Status: Closed"],
[title^="Status: Merged"]
)
`,
closedOrMergedMarkerSelector,
addToConversation,
{signal},
);
Expand Down
77 changes: 77 additions & 0 deletions source/features/netiquette.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import React from 'dom-chef';
import * as pageDetect from 'github-url-detection';
import toMilliseconds from '@sindresorhus/to-milliseconds';
import select from 'select-dom';
import twas from 'twas';
import {InfoIcon} from '@primer/octicons-react';

import createBanner from '../github-helpers/banner';
import features from '../feature-manager';
import observe from '../helpers/selector-observer';
import {buildRepoURL} from '../github-helpers';
import {closedOrMergedMarkerSelector, getLastCloseEvent} from './jump-to-conversation-close-event';

const isClosedOrMerged = (): boolean => select.exists(closedOrMergedMarkerSelector);

/** Returns milliseconds passed since `date` */
function timeAgo(date: Date): number {
return Date.now() - date.getTime();
}

function getCloseDate(): Date {
const datetime = select('relative-time', getLastCloseEvent())!.getAttribute('datetime')!;
console.assert(datetime, 'Datetime attribute missing from relative-time');
return new Date(datetime);
}

const threeMonths = toMilliseconds({days: 90});

function addConversationBanner(newCommentField: HTMLElement): void {
if (!isClosedOrMerged()) {
return;
}

const closingDate = getCloseDate();
if (timeAgo(closingDate) < threeMonths) {
return;
}

const ago = <strong>{twas(closingDate.getTime())}</strong>;
const newIssue = <a href={buildRepoURL('issues/new/choose')}>new issue</a>;

newCommentField.before(
createBanner({
classes: 'p-2 m-2 text-small color-fg-muted border-0'.split(' '),
text: (
<div className="d-flex flex-items-center gap-2">
<InfoIcon className="m-0"/>
{/* TODO: Drop any after https://github.com/frenic/csstype/issues/177 */}
<span style={{textWrap: 'balance'} as any}>
This {pageDetect.isPR() ? 'PR' : 'issue'} was closed {ago}. Please consider opening a {newIssue} instead of leaving a comment here.
</span>
</div>
),
}),
);
}

function init(signal: AbortSignal): void {
observe('#issue-comment-box file-attachment', addConversationBanner, {signal});
}

void features.add(import.meta.url, {
include: [
pageDetect.isConversation,
],
awaitDomReady: true, // We're specifically looking for the last event
init,
});

/*

Test URLs

- Old issue: https://github.com/refined-github/refined-github/issues/3076
- Old PR: https://github.com/refined-github/refined-github/pull/159

*/
9 changes: 5 additions & 4 deletions source/github-helpers/banner.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'dom-chef';
import {RequireAllOrNone} from 'type-fest';

type BannerProps = {
type BannerProps = RequireAllOrNone<{
text: Array<string | JSX.Element> | string | JSX.Element;
url?: string;
buttonLabel: JSX.Element | string;
classes?: string[];
};
url: string;
buttonLabel: JSX.Element | string;
}, 'url' | 'buttonLabel'>;

// This could be a `<Banner/>` element but dom-chef doesn't pass props
// https://github.com/vadimdemedes/dom-chef/issues/77
Expand Down
1 change: 1 addition & 0 deletions source/refined-github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,4 @@ import './features/scrollable-areas';
import './features/clean-repo-header';
import './features/emphasize-draft-pr-label';
import './features/file-age-color';
import './features/netiquette';