summaryrefslogtreecommitdiff
path: root/source/features
diff options
context:
space:
mode:
Diffstat (limited to 'source/features')
-rw-r--r--source/features/linkify-branch-refs.tsx54
1 files changed, 1 insertions, 53 deletions
diff --git a/source/features/linkify-branch-refs.tsx b/source/features/linkify-branch-refs.tsx
index 8a495aa4..0cbb981b 100644
--- a/source/features/linkify-branch-refs.tsx
+++ b/source/features/linkify-branch-refs.tsx
@@ -1,53 +1,10 @@
import React from 'dom-chef';
-import select from 'select-dom';
import elementReady from 'element-ready';
import features from '../libs/features';
-import * as pageDetect from '../libs/page-detect';
import {getOwnerAndRepo} from '../libs/utils';
import {wrap} from '../libs/dom-utils';
-function inPR(): void {
- let deletedBranch: string | undefined;
- const lastBranchAction = select.all(`
- .discussion-item-head_ref_deleted .commit-ref,
- .discussion-item-head_ref_restored .commit-ref
- `).pop();
- if (lastBranchAction && lastBranchAction.closest('.discussion-item-head_ref_deleted')) {
- deletedBranch = lastBranchAction.textContent!.trim();
- }
-
- // Find the URLs first, some elements don't have titles
- const urls = new Map<string, string>();
- for (const el of select.all('.commit-ref[title], .base-ref[title], .head-ref[title]')) {
- const [repo, branch] = el.title.split(':');
- const branchName = el.textContent!.trim();
- urls.set(
- branchName,
- `/${repo}`
- );
- if (branchName !== deletedBranch) {
- urls.set(
- branchName,
- `/${repo}/tree/${encodeURIComponent(branch)}`
- );
- }
- }
-
- for (const el of select.all('.commit-ref')) {
- const branchName = el.textContent!.trim();
-
- if (branchName !== 'unknown repository') {
- if (branchName === deletedBranch) {
- el.title = 'Deleted';
- el.style.textDecoration = 'line-through';
- }
-
- wrap(el, <a href={urls.get(branchName)}></a>);
- }
- }
-}
-
-async function inQuickPR(): Promise<void> {
+async function init(): Promise<void> {
const el = await elementReady('.branch-name');
if (el) {
const {ownerName, repoName} = getOwnerAndRepo();
@@ -56,19 +13,10 @@ async function inQuickPR(): Promise<void> {
}
}
-function init(): void {
- if (pageDetect.isPR()) {
- inPR();
- } else if (pageDetect.isQuickPR()) {
- inQuickPR();
- }
-}
-
features.add({
id: __featureName__,
description: 'Click on branch references in pull requests',
include: [
- features.isPR,
features.isQuickPR
],
load: features.onAjaxedPages,