Skip to content
Draft
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
5 changes: 5 additions & 0 deletions build/__snapshots__/features-meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@
"description": "Enables toggling file diffs by clicking on their header bar.",
"screenshot": "https://user-images.githubusercontent.com/47531779/99855419-be173e00-2b7e-11eb-9a55-0f6251aeb0ef.gif"
},
{
"id": "easy-toggle-hidden-comments",
"description": "Enables toggling hidden comments and resolved/outdated review threads by clicking on their header bar.",
"screenshot": null
},
{
"id": "embed-gist-inline",
"description": "Embeds short gists when linked in comments on their own lines.",
Expand Down
1 change: 1 addition & 0 deletions build/__snapshots__/imported-features.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"download-folder-button",
"easy-toggle-commit-messages",
"easy-toggle-files",
"easy-toggle-hidden-comments",
"embed-gist-inline",
"emphasize-draft-pr-label",
"esc-to-cancel",
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ https://github.com/refined-github/refined-github/wiki/Contributing#metadata-guid
- [](# "jump-to-conversation-close-event") [Adds a link to jump to the latest close event of a issue/PR.](https://user-images.githubusercontent.com/16872793/177792713-64219754-f8df-4629-a9ec-33259307cfe7.gif)
- [](# "close-as-unplanned") [Lets you "close issue as unplanned" in one click instead of three.](https://github-production-user-asset-6210df.s3.amazonaws.com/1402241/279745773-709cde60-c26a-4a0e-89e1-56444d25ebdf.png)
- [](# "locked-issue") [Show a label on locked issues and PRs.](https://user-images.githubusercontent.com/1402241/283015579-0a04becc-9bff-4aef-8770-272d6804970b.png)
- [](# "easy-toggle-hidden-comments") Enables toggling hidden comments and resolved/outdated review threads by clicking on their header bar.

<!--
Refer to style guide in the wiki. Keep this message between sections.
Expand Down
13 changes: 9 additions & 4 deletions source/features/easy-toggle-commit-messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import {$optional, closestElementOptional} from 'select-dom';

import features from '../feature-manager.js';

const activeElementsSelector = 'a, button, clipboard-copy, details';
export function wasInteractiveElementClicked(event: DelegateEvent<MouseEvent>): boolean {
return Boolean(
closestElementOptional(
['a', 'button', 'clipboard-copy', 'details'],
event.target as HTMLElement,
),
);
}

function toggleCommitMessage(event: DelegateEvent<MouseEvent>): void {
// The clicked element is a button, a link or a popup ("Verified" badge, CI details, etc.)
const elementClicked = event.target as HTMLElement;
if (closestElementOptional(activeElementsSelector, elementClicked)) {
if (wasInteractiveElementClicked(event)) {
return;
}

Expand Down
16 changes: 8 additions & 8 deletions source/features/easy-toggle-files.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import delegate, {type DelegateEvent} from 'delegate-it';
import * as pageDetect from 'github-url-detection';
import {$, closestElementOptional} from 'select-dom';
import {$} from 'select-dom';

import features from '../feature-manager.js';
import {codeSearchHeader} from '../github-helpers/selectors.js';
import {wasInteractiveElementClicked} from './easy-toggle-commit-messages.js';

function toggleFile(event: DelegateEvent<MouseEvent>): void {
const elementClicked = event.target as HTMLElement;
const headerBar = event.delegateTarget;

// Exclude interactive elements
if (!closestElementOptional(['a', 'button', 'clipboard-copy', 'details'], elementClicked)) {
$('button:has(> .octicon-chevron-down, > .octicon-chevron-right)', headerBar)
.dispatchEvent(new MouseEvent('click', {bubbles: true, altKey: event.altKey}));
if (wasInteractiveElementClicked(event)) {
return;
}

const headerBar = event.delegateTarget;
$('button:has(> .octicon-chevron-down, > .octicon-chevron-right)', headerBar)
.dispatchEvent(new MouseEvent('click', {bubbles: true, altKey: event.altKey}));
}

function toggleCodeSearchFile(event: DelegateEvent<MouseEvent>): void {
Expand Down
46 changes: 46 additions & 0 deletions source/features/easy-toggle-hidden-comments.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import delegate, {type DelegateEvent} from 'delegate-it';
import * as pageDetect from 'github-url-detection';
import {$} from 'select-dom';

import features from '../feature-manager.js';
import {wasInteractiveElementClicked} from './easy-toggle-commit-messages.js';

function toggle(event: DelegateEvent<MouseEvent>): void {
if (!wasInteractiveElementClicked(event)) {
$(
[
'.review-thread-chevron',
'button:has(> .octicon-unfold, > .octicon-fold)',
],
event.delegateTarget,
).click();
}
}

function init(signal: AbortSignal): void {
delegate(
[
'div[data-testid="comment-header"]:has(.octicon-unfold, .octicon-fold)',
'.js-toggle-outdated-comments',
],
'click',
toggle,
{signal},
);
}

void features.add(import.meta.url, {
include: [
pageDetect.isConversation,
],
init,
});

/*
Test URLs

https://github.com/refined-github/sandbox/issues/131#issuecomment-4297544223

https://github.com/refined-github/sandbox/pull/47#pullrequestreview-4175514676

*/
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/no-self-reference.js';
import './features/cmd-enter.js';
import './features/extensible-nav.js';
import './features/notifications-ui.js';
import './features/easy-toggle-hidden-comments.js';
Loading