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
5 changes: 4 additions & 1 deletion source/features/bypass-checks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ async function bypass(detailsLink: HTMLAnchorElement): Promise<void> {
detailsLink.href,
'[data-hydro-click*="check_suite.external_click"]'
);
detailsLink.href = directLink!.href;

if (directLink) {
detailsLink.href = directLink.href;
}
}

async function init(): Promise<void> {
Expand Down
13 changes: 7 additions & 6 deletions source/features/comment-fields-keyboard-shortcuts.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import select from 'select-dom';
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';

import features from '.';
import onCommentFieldKeydown from '../github-events/on-comment-field-keydown';
Expand Down Expand Up @@ -39,13 +40,10 @@ function eventHandler(event: delegate.Event<KeyboardEvent, HTMLTextAreaElement>)

if (lastOwnComment) {
select<HTMLButtonElement>('.js-comment-edit-button', lastOwnComment)!.click();
const closeCurrentField = field
field
.closest('form')!
.querySelector<HTMLButtonElement>('.js-hide-inline-comment-form');

if (closeCurrentField) {
closeCurrentField.click();
}
.querySelector<HTMLButtonElement>('.js-hide-inline-comment-form')
?.click();

// Move caret to end of field
requestAnimationFrame(() => {
Expand All @@ -68,6 +66,9 @@ void features.add({
esc: 'Unfocuses comment field'
}
}, {
include: [
pageDetect.hasRichTextEditor
],
waitForDomReady: false,
repeatOnAjax: false,
init
Expand Down
4 changes: 1 addition & 3 deletions source/features/deep-reblame.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const getPullRequestBlameCommit = mem(async (commit: string, prNumber: number, c
const {repository} = await api.v4(`
repository(${getRepoGQL()}) {
file: object(expression: "${commit}:${currentFilename}") {
... on Blob {
id
}
id
}
object(expression: "${commit}") {
... on Commit {
Expand Down
3 changes: 3 additions & 0 deletions source/features/default-branch-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ void features.add({
pageDetect.isSingleFile,
pageDetect.isRepoCommitList
],
exclude: [
pageDetect.isRepoHome
],
waitForDomReady: false,
init
});
2 changes: 1 addition & 1 deletion source/features/download-folder-button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'dom-chef';
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';
import DownloadIcon from 'octicon/download.svg';
import * as pageDetect from 'github-url-detection';

import features from '.';

Expand Down
3 changes: 3 additions & 0 deletions source/features/fit-textareas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ void features.add({
description: 'Auto-resizes comment fields to fit their content and no longer show scroll bars, rather than have a height limit like GitHub’s native "fit to content" behavior.',
screenshot: 'https://user-images.githubusercontent.com/1402241/54336211-66fd5e00-4666-11e9-9c5e-111fccab004d.gif'
}, {
include: [
pageDetect.hasRichTextEditor
],
init
}, {
include: [
Expand Down
2 changes: 1 addition & 1 deletion source/features/fork-source-link-same-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void features.add({
],
exclude: [
() => !pageDetect.isForkedRepo(),
() => pageDetect.isRepoRoot()
pageDetect.isRepoRoot
],
init
});
23 changes: 13 additions & 10 deletions source/features/improve-shortcut-help.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from 'dom-chef';
import select from 'select-dom';

import features from '.';
import {isEditable} from '../helpers/dom-utils';

function splitKeys(keys: string): DocumentFragment[] {
return keys.split(' ').map(key => <> <kbd>{key}</kbd></>);
Expand Down Expand Up @@ -45,17 +46,19 @@ const observer = new MutationObserver(([{target}]) => {
}
});

function init(): void {
document.addEventListener('keypress', ({key, target}) => {
if (key !== '?' || target instanceof HTMLTextAreaElement || target instanceof HTMLInputElement) {
return;
}
function observeShortcutModal({key, target}: KeyboardEvent): void {
if (key !== '?' || isEditable(target)) {
return;
}

const modal = select('body > details > details-dialog');
if (modal) {
observer.observe(modal, {childList: true});
}
});
const modal = select('body > details > details-dialog');
if (modal) {
observer.observe(modal, {childList: true});
}
}

function init(): void {
document.addEventListener('keypress', observeShortcutModal);
}

void features.add({
Expand Down
2 changes: 1 addition & 1 deletion source/features/mark-merge-commits-in-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const filterMergeCommits = async (commits: string[]): Promise<string[]> => {

const mergeCommits = [];
for (const [key, commit] of Object.entries<AnyObject>(repository)) {
if (commit.parents.totalCount === 2) {
if (commit.parents.totalCount >= 2) {
mergeCommits.push(key.slice(1));
}
}
Expand Down
2 changes: 1 addition & 1 deletion source/features/minimize-upload-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import './minimize-upload-bar.css';
import React from 'dom-chef';
import select from 'select-dom';
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';
import UploadIcon from 'octicon/upload.svg';
import * as pageDetect from 'github-url-detection';

import features from '.';

Expand Down
4 changes: 4 additions & 0 deletions source/features/one-key-formatting.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import delegate from 'delegate-it';
import * as pageDetect from 'github-url-detection';
import * as textFieldEdit from 'text-field-edit';

import features from '.';
Expand Down Expand Up @@ -37,6 +38,9 @@ void features.add({
description: 'Wraps selected text when pressing one of Markdown symbols instead of replacing it: (`[` `’` `"` `(` etc).',
screenshot: 'https://user-images.githubusercontent.com/1402241/65020298-1f2dfb00-d957-11e9-9a2a-1c0ceab8d9e0.gif'
}, {
include: [
pageDetect.hasCode
],
waitForDomReady: false,
repeatOnAjax: false,
init
Expand Down
2 changes: 1 addition & 1 deletion source/features/pr-branches.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import PullRequestIcon from 'octicon/git-pull-request.svg';

import features from '.';
import * as api from '../github-helpers/api';
import {botSelectors} from './dim-bots';
import getDefaultBranch from '../github-helpers/get-default-branch';
import {getRepositoryInfo, getRepoGQL} from '../github-helpers';
import {botSelectors} from './dim-bots';

type RepositoryReference = {
owner: string;
Expand Down
13 changes: 6 additions & 7 deletions source/features/preview-hidden-comments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import select from 'select-dom';
import * as pageDetect from 'github-url-detection';

import features from '.';
import {upperCaseFirst} from '../github-helpers';

const allowedReasons = new Set(['resolved', 'outdated', 'off-topic']);

const capitalize = (text: string): string => text.charAt(0).toUpperCase() + text.slice(1);

const init = (): void => {
for (const details of select.all('.minimized-comment:not(.d-none) > details:not(.rgh-preview-hidden-comments)')) {
details.classList.add('rgh-preview-hidden-comments');
Expand All @@ -18,10 +17,10 @@ const init = (): void => {
continue;
}

const header = select(`
summary .timeline-comment-header-text,
summary .discussion-item-copy
`, details)!;
const header = select([
'summary .timeline-comment-header-text', // Issue and commit comments
'.discussion-item-icon + div' // Review Comments
], details)!;

const reason = /was marked as ([^.]+)/.exec(header.textContent!)?.[1] ?? '';
if (!allowedReasons.has(reason)) {
Expand All @@ -30,7 +29,7 @@ const init = (): void => {

header.append(
<span className="Details-content--open">{header.firstChild}</span>,
<span className="Details-content--closed">{`${capitalize(reason)} — ${commentText}`}</span>
<span className="Details-content--closed">{`${upperCaseFirst(reason)} — ${commentText}`}</span>
);
}
};
Expand Down
2 changes: 1 addition & 1 deletion source/features/release-download-count.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import './release-download-count.css';
import React from 'dom-chef';
import select from 'select-dom';
import * as pageDetect from 'github-url-detection';
import DownloadIcon from 'octicon/download.svg';
import * as pageDetect from 'github-url-detection';

import features from '.';
import * as api from '../github-helpers/api';
Expand Down
24 changes: 13 additions & 11 deletions source/features/selection-in-new-tab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import select from 'select-dom';
import features from '.';
import {isEditable} from '../helpers/dom-utils';

function init(): void {
document.addEventListener('keypress', (event: KeyboardEvent) => {
const selected = select<HTMLAnchorElement>('.navigation-focus .js-navigation-open[href]');
if (selected && event.key === 'O' && !isEditable(event.target)) {
void browser.runtime.sendMessage({
openUrls: [selected.href]
});
function openInNewTab({key, target}: KeyboardEvent): void {
const selected = select<HTMLAnchorElement>('.navigation-focus .js-navigation-open[href]');
if (selected && key === 'O' && !isEditable(target)) {
void browser.runtime.sendMessage({
openUrls: [selected.href]
});

// Get the list element that contains the unread class and mark it as read.
selected.closest('.unread')?.classList.replace('unread', 'read');
}
});
// Get the list element that contains the unread class and mark it as read.
selected.closest('.unread')?.classList.replace('unread', 'read');
}
}

function init(): void {
document.addEventListener('keypress', openInNewTab);
}

void features.add({
Expand Down
7 changes: 1 addition & 6 deletions source/features/show-associated-branch-prs-on-fork.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PullRequestIcon from 'octicon/git-pull-request.svg';
import features from '.';
import * as api from '../github-helpers/api';
import observeElement from '../helpers/simplified-element-observer';
import {getRepoGQL, getRepoURL} from '../github-helpers';
import {getRepoGQL, getRepoURL, upperCaseFirst} from '../github-helpers';

interface PullRequest {
number: number;
Expand Down Expand Up @@ -59,11 +59,6 @@ const getPullRequestsAssociatedWithBranch = cache.function(async (): Promise<Rec
cacheKey: () => 'associatedBranchPullRequests:' + getRepoURL()
});

// https://github.com/idimetrix/text-case/blob/master/packages/upper-case-first/src/index.ts
function upperCaseFirst(input: string): string {
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
}

const stateClass: Record<string, string> = {
Open: '--green',
Closed: '--red',
Expand Down
4 changes: 4 additions & 0 deletions source/features/tab-to-indent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {eventHandler} from 'indent-textarea';
import * as pageDetect from 'github-url-detection';

import features from '.';
import onCommentFieldKeydown from '../github-events/on-comment-field-keydown';
Expand All @@ -12,6 +13,9 @@ void features.add({
description: 'Enables <kbd>tab</kbd> and <kbd>shift+tab</kbd> for indentation in comment fields.',
screenshot: 'https://user-images.githubusercontent.com/1402241/33802977-beb8497c-ddbf-11e7-899c-698d89298de4.gif'
}, {
include: [
pageDetect.hasCode
],
waitForDomReady: false,
repeatOnAjax: false,
init
Expand Down
7 changes: 6 additions & 1 deletion source/github-helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export function compareNames(username: string, realname: string): boolean {
* @param {string} selector A css selector.
*/
export function getScopedSelector(selector: string): string {
return selector.split(',').map(sub => `:scope > ${sub.trim()}`).join(',');
return selector.split(',').map(sub => `:scope > ${sub.trim()}`).join();
}

export function looseParseInt(text: string): number {
Expand Down Expand Up @@ -109,3 +109,8 @@ export function preventPrCommitLinkLoss(url: string, pr: string, commit: string,

return `[\`${commit}\` (#${pr})](${url})`;
}

// https://github.com/idimetrix/text-case/blob/master/packages/upper-case-first/src/index.ts
export function upperCaseFirst(input: string): string {
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
}