From 197d5d3ff7c0cdfb4cbfa13344dc13ef55ba09f8 Mon Sep 17 00:00:00 2001 From: Kid Date: Wed, 24 Mar 2021 17:42:24 +0800 Subject: [PATCH 01/19] Drop from and into words in `clean-conversation-headers` --- .../features/clean-conversation-headers.tsx | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index 22f15172e73f..7ee31c7c53df 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -1,9 +1,13 @@ +import React from 'dom-chef'; import './clean-conversation-headers.css'; import select from 'select-dom'; import {observe} from 'selector-observer'; +import {ArrowLeftIcon} from '@primer/octicons-react'; import * as pageDetect from 'github-url-detection'; import features from '.'; +import getDefaultBranch from '../github-helpers/get-default-branch'; +import {getCurrentBranch} from '../github-helpers'; const deinit: VoidFunction[] = []; @@ -26,21 +30,26 @@ function initIssue(): void { function initPR(): void { const observer = observe('.gh-header-meta .flex-auto:not(.rgh-clean-conversation-header)', { - add(byline) { + async add(byline) { byline.classList.add('rgh-clean-conversation-header'); - const isSameAuthor = select('.js-discussion > .TimelineItem:first-child .author')?.textContent === select('.author', byline)!.textContent; + const isSameAuthor = select('.TimelineItem:first-child .author')?.textContent === select('.author', byline)!.textContent; const baseBranch = select('.commit-ref:not(.head-ref)', byline)!; - const isDefaultBranch = (baseBranch.firstElementChild as HTMLAnchorElement).pathname.split('/').length === 3; + const isDefaultBranch = getCurrentBranch() === await getDefaultBranch(); + + byline.childNodes[pageDetect.isClosedPR() ? pageDetect.isMergedPR() ? 5 : 7 : 9].replaceWith(<> ); - // Removes: [octocat wants to merge 1] commit into github:master from octocat:feature - // Removes: [octocat] merged 1 commit into master from feature - for (const node of [...byline.childNodes].slice(isSameAuthor ? 0 : 2, pageDetect.isMergedPR() ? 2 : 4)) { + // Removes: [octocat wants to merge 1 commit into] github:master from octocat:feature + // Removes: [octocat merged 1 commit into] master from feature + for (const node of [...byline.childNodes].slice(isSameAuthor ? 0 : 2, pageDetect.isMergedPR() ? 3 : 5)) { node.remove(); } - baseBranch.previousSibling!.textContent = ' into '; if (!isSameAuthor) { byline.prepend('by '); + + if (pageDetect.isMergedPR()) { + baseBranch.before(' · '); + } } if (!isDefaultBranch && !(pageDetect.isClosedPR() && baseBranch.title.endsWith(':master'))) { From 8ebed2e4dee551e6a2a44449687e4f78c9b5f0a9 Mon Sep 17 00:00:00 2001 From: Kid Date: Wed, 24 Mar 2021 17:53:29 +0800 Subject: [PATCH 02/19] Lint --- source/features/clean-conversation-headers.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index 7ee31c7c53df..16c8f01514da 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -36,7 +36,7 @@ function initPR(): void { const baseBranch = select('.commit-ref:not(.head-ref)', byline)!; const isDefaultBranch = getCurrentBranch() === await getDefaultBranch(); - byline.childNodes[pageDetect.isClosedPR() ? pageDetect.isMergedPR() ? 5 : 7 : 9].replaceWith(<> ); + byline.childNodes[pageDetect.isClosedPR() ? (pageDetect.isMergedPR() ? 5 : 7) : 9].replaceWith(<> ); // Removes: [octocat wants to merge 1 commit into] github:master from octocat:feature // Removes: [octocat merged 1 commit into] master from feature From 7e853ea783bcb87878baa1f0f3a5b62425cf803e Mon Sep 17 00:00:00 2001 From: Kid Date: Wed, 24 Mar 2021 18:04:31 +0800 Subject: [PATCH 03/19] Change dot symbol --- source/features/clean-conversation-headers.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index 16c8f01514da..d9192ae99d66 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -48,7 +48,7 @@ function initPR(): void { byline.prepend('by '); if (pageDetect.isMergedPR()) { - baseBranch.before(' · '); + baseBranch.before(' • '); } } From d2b22d387dfb074cfac4507e73f90a6be30b2aa2 Mon Sep 17 00:00:00 2001 From: Kid Date: Wed, 24 Mar 2021 20:18:43 +0800 Subject: [PATCH 04/19] Rework --- source/features/clean-conversation-headers.tsx | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index d9192ae99d66..951f4a241ee4 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -7,7 +7,6 @@ import * as pageDetect from 'github-url-detection'; import features from '.'; import getDefaultBranch from '../github-helpers/get-default-branch'; -import {getCurrentBranch} from '../github-helpers'; const deinit: VoidFunction[] = []; @@ -15,6 +14,7 @@ function initIssue(): void { const observer = observe('.gh-header-meta .flex-auto:not(.rgh-clean-conversation-header)', { add(byline) { byline.classList.add('rgh-clean-conversation-header'); + const {childNodes: bylineNodes} = byline; // Removes: octocat opened this issue on 1 Jan [·] 1 comments bylineNodes[4].textContent = bylineNodes[4].textContent!.replace('·', ''); @@ -32,9 +32,12 @@ function initPR(): void { const observer = observe('.gh-header-meta .flex-auto:not(.rgh-clean-conversation-header)', { async add(byline) { byline.classList.add('rgh-clean-conversation-header'); - const isSameAuthor = select('.TimelineItem:first-child .author')?.textContent === select('.author', byline)!.textContent; - const baseBranch = select('.commit-ref:not(.head-ref)', byline)!; - const isDefaultBranch = getCurrentBranch() === await getDefaultBranch(); + + const isSameAuthor = select('.author', byline)!.textContent === select('.TimelineItem:first-child .author')?.textContent; + + const base = select('.commit-ref', byline)!; + const baseBranch = base.title.split(':')[1]; + const isDefaultBranch = baseBranch === await getDefaultBranch() || (pageDetect.isClosedPR() && baseBranch === "master"); byline.childNodes[pageDetect.isClosedPR() ? (pageDetect.isMergedPR() ? 5 : 7) : 9].replaceWith(<> ); @@ -48,12 +51,12 @@ function initPR(): void { byline.prepend('by '); if (pageDetect.isMergedPR()) { - baseBranch.before(' • '); + base.before(' • '); } } - if (!isDefaultBranch && !(pageDetect.isClosedPR() && baseBranch.title.endsWith(':master'))) { - baseBranch.classList.add('rgh-clean-conversation-headers-non-default-branch'); + if (!isDefaultBranch) { + base.classList.add('rgh-clean-conversation-headers-non-default-branch'); } } }); From 47bd9a917fdffe88368bf7733ddd2a21328d7b94 Mon Sep 17 00:00:00 2001 From: Kid Date: Wed, 24 Mar 2021 20:20:41 +0800 Subject: [PATCH 05/19] woo --- source/features/clean-conversation-headers.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index 951f4a241ee4..9d6819120d1b 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -33,7 +33,7 @@ function initPR(): void { async add(byline) { byline.classList.add('rgh-clean-conversation-header'); - const isSameAuthor = select('.author', byline)!.textContent === select('.TimelineItem:first-child .author')?.textContent; + const isSameAuthor = select('.author', byline)!.textContent === select('.TimelineItem .author')?.textContent; const base = select('.commit-ref', byline)!; const baseBranch = base.title.split(':')[1]; From 7c1d4a95e1e87b99505d940e26b452af382320ff Mon Sep 17 00:00:00 2001 From: Kid Date: Wed, 24 Mar 2021 20:23:12 +0800 Subject: [PATCH 06/19] Fix quotes --- source/features/clean-conversation-headers.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index 9d6819120d1b..3f22d2964e22 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -37,7 +37,7 @@ function initPR(): void { const base = select('.commit-ref', byline)!; const baseBranch = base.title.split(':')[1]; - const isDefaultBranch = baseBranch === await getDefaultBranch() || (pageDetect.isClosedPR() && baseBranch === "master"); + const isDefaultBranch = baseBranch === await getDefaultBranch() || (pageDetect.isClosedPR() && baseBranch === 'master'); byline.childNodes[pageDetect.isClosedPR() ? (pageDetect.isMergedPR() ? 5 : 7) : 9].replaceWith(<> ); From 1a30a87f247283faa63081a929d8db310302cc37 Mon Sep 17 00:00:00 2001 From: Kid Date: Wed, 24 Mar 2021 20:45:17 +0800 Subject: [PATCH 07/19] Extract author --- source/features/clean-conversation-headers.tsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index 3f22d2964e22..e3640a12043b 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -33,7 +33,8 @@ function initPR(): void { async add(byline) { byline.classList.add('rgh-clean-conversation-header'); - const isSameAuthor = select('.author', byline)!.textContent === select('.TimelineItem .author')?.textContent; + const author = select('.author', byline)!; + const isSameAuthor = pageDetect.isPRConversation() && author.textContent === select('.TimelineItem .author')!.textContent; const base = select('.commit-ref', byline)!; const baseBranch = base.title.split(':')[1]; @@ -48,11 +49,8 @@ function initPR(): void { } if (!isSameAuthor) { - byline.prepend('by '); - - if (pageDetect.isMergedPR()) { - base.before(' • '); - } + author.before('by '); + author.after(' • '); } if (!isDefaultBranch) { From 6f5ab401172a7537055d95d54685eeb9b97b54b0 Mon Sep 17 00:00:00 2001 From: Kid Date: Wed, 24 Mar 2021 20:53:39 +0800 Subject: [PATCH 08/19] Update screenshot --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index e2b962668c83..4627190c5c5e 100644 --- a/readme.md +++ b/readme.md @@ -211,7 +211,7 @@ Thanks for contributing! 🦋🙌 - [](# "pinned-issues-update-time") [Adds the updated time to pinned issues.](https://user-images.githubusercontent.com/1402241/75525936-bb524700-5a4b-11ea-9225-466bda58b7de.png) - [](# "clean-pinned-issues") [Changes the layout of pinned issues from side-by-side to a standard list.](https://user-images.githubusercontent.com/1402241/84509958-c82a3c00-acc4-11ea-8399-eaf06a59e9e4.png) - [](# "remove-label-faster") [Adds one-click buttons to remove labels in conversations.](https://user-images.githubusercontent.com/36174850/89980178-0bc80480-dc7a-11ea-8ded-9e25f5f13d1a.gif) -- [](# "clean-conversation-headers") [Removes duplicate information in the header of issues and PRs ("User wants to merge X commits from Y into Z")](https://user-images.githubusercontent.com/44045911/89736767-686ec800-da9e-11ea-81c3-252e9813140b.png) +- [](# "clean-conversation-headers") [Removes duplicate information in the header of issues and PRs ("User wants to merge X commits from Y into Z")](https://user-images.githubusercontent.com/44045911/112313541-ef497b80-8ce2-11eb-8723-3ba74376f119.png) - [](# "dim-bots") [Dims commits and PRs by bots to reduce noise.](https://user-images.githubusercontent.com/1402241/65263190-44c52b00-db36-11e9-9b33-d275d3c8479d.gif) - [](# "esc-to-cancel") [Adds a shortcut to cancel editing a conversation title: esc.](https://user-images.githubusercontent.com/35100156/98303086-d81d2200-1fbd-11eb-8529-70d48d889bcf.gif) - [](# "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) From 9f3deca45bf3c2033e316d09d9ab3cf0c72d2c02 Mon Sep 17 00:00:00 2001 From: Kid Date: Wed, 24 Mar 2021 20:58:55 +0800 Subject: [PATCH 09/19] Update screenshot again --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 4627190c5c5e..81c8b44923fc 100644 --- a/readme.md +++ b/readme.md @@ -211,7 +211,7 @@ Thanks for contributing! 🦋🙌 - [](# "pinned-issues-update-time") [Adds the updated time to pinned issues.](https://user-images.githubusercontent.com/1402241/75525936-bb524700-5a4b-11ea-9225-466bda58b7de.png) - [](# "clean-pinned-issues") [Changes the layout of pinned issues from side-by-side to a standard list.](https://user-images.githubusercontent.com/1402241/84509958-c82a3c00-acc4-11ea-8399-eaf06a59e9e4.png) - [](# "remove-label-faster") [Adds one-click buttons to remove labels in conversations.](https://user-images.githubusercontent.com/36174850/89980178-0bc80480-dc7a-11ea-8ded-9e25f5f13d1a.gif) -- [](# "clean-conversation-headers") [Removes duplicate information in the header of issues and PRs ("User wants to merge X commits from Y into Z")](https://user-images.githubusercontent.com/44045911/112313541-ef497b80-8ce2-11eb-8723-3ba74376f119.png) +- [](# "clean-conversation-headers") [Removes duplicate information in the header of issues and PRs ("User wants to merge X commits from Y into Z")](https://user-images.githubusercontent.com/44045911/112314137-a34b0680-8ce3-11eb-9e0e-8afd6c8235c2.png) - [](# "dim-bots") [Dims commits and PRs by bots to reduce noise.](https://user-images.githubusercontent.com/1402241/65263190-44c52b00-db36-11e9-9b33-d275d3c8479d.gif) - [](# "esc-to-cancel") [Adds a shortcut to cancel editing a conversation title: esc.](https://user-images.githubusercontent.com/35100156/98303086-d81d2200-1fbd-11eb-8529-70d48d889bcf.gif) - [](# "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) From 3b87b67c9a9750ed77057cad4efd7ba4f1e848bd Mon Sep 17 00:00:00 2001 From: Kid <44045911+kidonng@users.noreply.github.com> Date: Wed, 24 Mar 2021 22:07:15 +0800 Subject: [PATCH 10/19] Update source/features/clean-conversation-headers.tsx Co-authored-by: yakov116 <16872793+yakov116@users.noreply.github.com> --- source/features/clean-conversation-headers.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index e3640a12043b..2137df148f00 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -1,5 +1,5 @@ -import React from 'dom-chef'; import './clean-conversation-headers.css'; +import React from 'dom-chef'; import select from 'select-dom'; import {observe} from 'selector-observer'; import {ArrowLeftIcon} from '@primer/octicons-react'; From 413550c85cb952074015db80c5f1513b4ec55c30 Mon Sep 17 00:00:00 2001 From: Yakov <16872793+yakov116@users.noreply.github.com> Date: Sun, 11 Apr 2021 00:09:21 -0400 Subject: [PATCH 11/19] Make it faster and use `onConversationHeaderUpdate` --- .../features/clean-conversation-headers.tsx | 93 ++++++++++--------- 1 file changed, 48 insertions(+), 45 deletions(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index 2137df148f00..bed0ce1448fd 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -1,78 +1,81 @@ import './clean-conversation-headers.css'; import React from 'dom-chef'; import select from 'select-dom'; -import {observe} from 'selector-observer'; +import elementReady from 'element-ready'; import {ArrowLeftIcon} from '@primer/octicons-react'; import * as pageDetect from 'github-url-detection'; import features from '.'; import getDefaultBranch from '../github-helpers/get-default-branch'; +import onConversationHeaderUpdate from '../github-events/on-conversation-header-update'; -const deinit: VoidFunction[] = []; +async function initIssue(): Promise { + const byline = await elementReady('.gh-header-meta .flex-auto:not(.rgh-clean-conversation-header)'); + if (!byline) { + return; + } -function initIssue(): void { - const observer = observe('.gh-header-meta .flex-auto:not(.rgh-clean-conversation-header)', { - add(byline) { - byline.classList.add('rgh-clean-conversation-header'); + byline.classList.add('rgh-clean-conversation-header'); - const {childNodes: bylineNodes} = byline; - // Removes: octocat opened this issue on 1 Jan [·] 1 comments - bylineNodes[4].textContent = bylineNodes[4].textContent!.replace('·', ''); + const {childNodes: bylineNodes} = byline; + // Removes: octocat opened this issue on 1 Jan [·] 1 comments + bylineNodes[4].textContent = bylineNodes[4].textContent!.replace('·', ''); - // Removes: [octocat opened this issue on 1 Jan] · 1 comments - for (const node of [...bylineNodes].slice(0, 4)) { - node.remove(); - } - } - }); - deinit.push(observer.abort); + // Removes: [octocat opened this issue on 1 Jan] · 1 comments + for (const node of [...bylineNodes].slice(0, 4)) { + node.remove(); + } } -function initPR(): void { - const observer = observe('.gh-header-meta .flex-auto:not(.rgh-clean-conversation-header)', { - async add(byline) { - byline.classList.add('rgh-clean-conversation-header'); +async function initPR(): Promise { + const byline = await elementReady('.gh-header-meta .flex-auto:not(.rgh-clean-conversation-header)'); + if (!byline) { + return; + } - const author = select('.author', byline)!; - const isSameAuthor = pageDetect.isPRConversation() && author.textContent === select('.TimelineItem .author')!.textContent; + byline.classList.add('rgh-clean-conversation-header'); - const base = select('.commit-ref', byline)!; - const baseBranch = base.title.split(':')[1]; - const isDefaultBranch = baseBranch === await getDefaultBranch() || (pageDetect.isClosedPR() && baseBranch === 'master'); + const author = select('.author', byline)!; + const isSameAuthor = pageDetect.isPRConversation() && author.textContent === select('.TimelineItem .author')!.textContent; - byline.childNodes[pageDetect.isClosedPR() ? (pageDetect.isMergedPR() ? 5 : 7) : 9].replaceWith(<> ); + const base = select('.commit-ref', byline)!; + const baseBranch = base.title.split(':')[1]; + const isDefaultBranch = baseBranch === await getDefaultBranch() || (pageDetect.isClosedPR() && baseBranch === 'master'); - // Removes: [octocat wants to merge 1 commit into] github:master from octocat:feature - // Removes: [octocat merged 1 commit into] master from feature - for (const node of [...byline.childNodes].slice(isSameAuthor ? 0 : 2, pageDetect.isMergedPR() ? 3 : 5)) { - node.remove(); - } + byline.childNodes[pageDetect.isClosedPR() ? (pageDetect.isMergedPR() ? 5 : 7) : 9].replaceWith(<> ); - if (!isSameAuthor) { - author.before('by '); - author.after(' • '); - } + // Removes: [octocat wants to merge 1 commit into] github:master from octocat:feature + // Removes: [octocat merged 1 commit into] master from feature + for (const node of [...byline.childNodes].slice(isSameAuthor ? 0 : 2, pageDetect.isMergedPR() ? 3 : 5)) { + node.remove(); + } - if (!isDefaultBranch) { - base.classList.add('rgh-clean-conversation-headers-non-default-branch'); - } - } - }); - deinit.push(observer.abort); + if (!isSameAuthor) { + author.before('by '); + author.after(' • '); + } + + if (!isDefaultBranch) { + base.classList.add('rgh-clean-conversation-headers-non-default-branch'); + } } void features.add(__filebasename, { include: [ pageDetect.isIssue ], + additionalListeners: [ + onConversationHeaderUpdate + ], awaitDomReady: false, - init: initIssue, - deinit + init: initIssue }, { include: [ pageDetect.isPR ], + additionalListeners: [ + onConversationHeaderUpdate + ], awaitDomReady: false, - init: initPR, - deinit + init: initPR }); From db1bb40f1f19d24aa26ec3998b3d800f1e9dea33 Mon Sep 17 00:00:00 2001 From: Yakov <16872793+yakov116@users.noreply.github.com> Date: Sun, 11 Apr 2021 00:19:07 -0400 Subject: [PATCH 12/19] The author may not be ready on time --- source/features/clean-conversation-headers.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index bed0ce1448fd..e665f19089cb 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -36,7 +36,7 @@ async function initPR(): Promise { byline.classList.add('rgh-clean-conversation-header'); const author = select('.author', byline)!; - const isSameAuthor = pageDetect.isPRConversation() && author.textContent === select('.TimelineItem .author')!.textContent; + const isSameAuthor = pageDetect.isPRConversation() && author.textContent === (await elementReady('.TimelineItem .author'))!.textContent; const base = select('.commit-ref', byline)!; const baseBranch = base.title.split(':')[1]; From c4d456be0c245817af6885aa6b80c0b356cb105a Mon Sep 17 00:00:00 2001 From: Yakov <16872793+yakov116@users.noreply.github.com> Date: Tue, 13 Apr 2021 20:53:39 -0400 Subject: [PATCH 13/19] use a function and split var --- source/features/clean-conversation-headers.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index e665f19089cb..e19f0c9e0285 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -27,6 +27,14 @@ async function initIssue(): Promise { } } +function childNodeNumber(): number { + if (pageDetect.isOpenPR()) { + return 9; + } + + return pageDetect.isMergedPR() ? 5 : 7; +} + async function initPR(): Promise { const byline = await elementReady('.gh-header-meta .flex-auto:not(.rgh-clean-conversation-header)'); if (!byline) { @@ -40,9 +48,8 @@ async function initPR(): Promise { const base = select('.commit-ref', byline)!; const baseBranch = base.title.split(':')[1]; - const isDefaultBranch = baseBranch === await getDefaultBranch() || (pageDetect.isClosedPR() && baseBranch === 'master'); - byline.childNodes[pageDetect.isClosedPR() ? (pageDetect.isMergedPR() ? 5 : 7) : 9].replaceWith(<> ); + byline.childNodes[childNodeNumber()].replaceWith(<> ); // Removes: [octocat wants to merge 1 commit into] github:master from octocat:feature // Removes: [octocat merged 1 commit into] master from feature @@ -55,7 +62,9 @@ async function initPR(): Promise { author.after(' • '); } - if (!isDefaultBranch) { + const wasDefaultBranch = pageDetect.isClosedPR() && baseBranch === 'master'; + const isDefaultBranch = baseBranch === await getDefaultBranch(); + if (!isDefaultBranch && !wasDefaultBranch) { base.classList.add('rgh-clean-conversation-headers-non-default-branch'); } } From a909893cb035f6f39cea07373cfdad094f08f560 Mon Sep 17 00:00:00 2001 From: Yakov <16872793+yakov116@users.noreply.github.com> Date: Wed, 14 Apr 2021 08:37:50 -0400 Subject: [PATCH 14/19] Lint --- source/features/clean-conversation-headers.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index e19f0c9e0285..0119616f55cc 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -27,7 +27,7 @@ async function initIssue(): Promise { } } -function childNodeNumber(): number { +function fromNodeNumber(): number { if (pageDetect.isOpenPR()) { return 9; } @@ -49,11 +49,16 @@ async function initPR(): Promise { const base = select('.commit-ref', byline)!; const baseBranch = base.title.split(':')[1]; - byline.childNodes[childNodeNumber()].replaceWith(<> ); + // Replace the word "from" with an arrow + byline.childNodes[fromNodeNumber()].replaceWith(<> ); // Removes: [octocat wants to merge 1 commit into] github:master from octocat:feature // Removes: [octocat merged 1 commit into] master from feature - for (const node of [...byline.childNodes].slice(isSameAuthor ? 0 : 2, pageDetect.isMergedPR() ? 3 : 5)) { + const duplicateNodes = [...byline.childNodes].slice( + isSameAuthor ? 0 : 2, + pageDetect.isMergedPR() ? 3 : 5 + ); + for (const node of duplicateNodes) { node.remove(); } From 889bc67287b909bf0bb314ea1827fd9f0bbdbf7a Mon Sep 17 00:00:00 2001 From: Yakov <16872793+yakov116@users.noreply.github.com> Date: Wed, 14 Apr 2021 19:09:29 -0400 Subject: [PATCH 15/19] Feedback --- source/features/clean-conversation-headers.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index 0119616f55cc..311ecaa31ac0 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -18,13 +18,13 @@ async function initIssue(): Promise { byline.classList.add('rgh-clean-conversation-header'); const {childNodes: bylineNodes} = byline; - // Removes: octocat opened this issue on 1 Jan [·] 1 comments - bylineNodes[4].textContent = bylineNodes[4].textContent!.replace('·', ''); - // Removes: [octocat opened this issue on 1 Jan] · 1 comments - for (const node of [...bylineNodes].slice(0, 4)) { - node.remove(); + for (let i = 0; i < 4; i++) { + bylineNodes[0].remove(); } + + // Removes: octocat opened this issue on 1 Jan [·] 1 comments + byline.firstChild!.textContent = byline.firstChild!.textContent!.replace('·', ''); } function fromNodeNumber(): number { @@ -46,7 +46,7 @@ async function initPR(): Promise { const author = select('.author', byline)!; const isSameAuthor = pageDetect.isPRConversation() && author.textContent === (await elementReady('.TimelineItem .author'))!.textContent; - const base = select('.commit-ref', byline)!; + const base = select('.base-ref', byline)!; const baseBranch = base.title.split(':')[1]; // Replace the word "from" with an arrow From fa37a54149963dae0412cbdbe9135c015b15a066 Mon Sep 17 00:00:00 2001 From: Yakov <16872793+yakov116@users.noreply.github.com> Date: Wed, 14 Apr 2021 20:02:00 -0400 Subject: [PATCH 16/19] Drop `fromNodeNumber` --- source/features/clean-conversation-headers.tsx | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index 311ecaa31ac0..d032dd5f13b3 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -27,14 +27,6 @@ async function initIssue(): Promise { byline.firstChild!.textContent = byline.firstChild!.textContent!.replace('·', ''); } -function fromNodeNumber(): number { - if (pageDetect.isOpenPR()) { - return 9; - } - - return pageDetect.isMergedPR() ? 5 : 7; -} - async function initPR(): Promise { const byline = await elementReady('.gh-header-meta .flex-auto:not(.rgh-clean-conversation-header)'); if (!byline) { @@ -46,11 +38,11 @@ async function initPR(): Promise { const author = select('.author', byline)!; const isSameAuthor = pageDetect.isPRConversation() && author.textContent === (await elementReady('.TimelineItem .author'))!.textContent; - const base = select('.base-ref', byline)!; + const [base, headBranch] = select.all('.commit-ref', byline)!; const baseBranch = base.title.split(':')[1]; // Replace the word "from" with an arrow - byline.childNodes[fromNodeNumber()].replaceWith(<> ); + headBranch.previousSibling!.replaceWith(<> ); // Removes: [octocat wants to merge 1 commit into] github:master from octocat:feature // Removes: [octocat merged 1 commit into] master from feature From 20a48116eae7471da98811e028f622c2a1bdb29a Mon Sep 17 00:00:00 2001 From: Yakov <16872793+yakov116@users.noreply.github.com> Date: Wed, 14 Apr 2021 22:50:41 -0400 Subject: [PATCH 17/19] Drop bylineNodes Co-Authored-By: Fregante --- source/features/clean-conversation-headers.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index d032dd5f13b3..4b31b42d288c 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -17,10 +17,9 @@ async function initIssue(): Promise { byline.classList.add('rgh-clean-conversation-header'); - const {childNodes: bylineNodes} = byline; // Removes: [octocat opened this issue on 1 Jan] · 1 comments for (let i = 0; i < 4; i++) { - bylineNodes[0].remove(); + byline.firstChild!.remove(); } // Removes: octocat opened this issue on 1 Jan [·] 1 comments From f69efe34a8673528c518c32336f1f8c0de611cf4 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Thu, 15 Apr 2021 09:59:40 +0700 Subject: [PATCH 18/19] Review --- source/features/clean-conversation-headers.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index 4b31b42d288c..58578f72c561 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -41,7 +41,7 @@ async function initPR(): Promise { const baseBranch = base.title.split(':')[1]; // Replace the word "from" with an arrow - headBranch.previousSibling!.replaceWith(<> ); + headBranch.previousSibling!.replaceWith(' ', , ' '); // Removes: [octocat wants to merge 1 commit into] github:master from octocat:feature // Removes: [octocat merged 1 commit into] master from feature From 726d9528f6ce4cb5da5e8b623c58913a92d8403b Mon Sep 17 00:00:00 2001 From: Yakov <16872793+yakov116@users.noreply.github.com> Date: Wed, 14 Apr 2021 23:02:55 -0400 Subject: [PATCH 19/19] Center the icon --- source/features/clean-conversation-headers.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/features/clean-conversation-headers.tsx b/source/features/clean-conversation-headers.tsx index 58578f72c561..7c8a6413d455 100644 --- a/source/features/clean-conversation-headers.tsx +++ b/source/features/clean-conversation-headers.tsx @@ -41,7 +41,7 @@ async function initPR(): Promise { const baseBranch = base.title.split(':')[1]; // Replace the word "from" with an arrow - headBranch.previousSibling!.replaceWith(' ', , ' '); + headBranch.previousSibling!.replaceWith(' ', , ' '); // Removes: [octocat wants to merge 1 commit into] github:master from octocat:feature // Removes: [octocat merged 1 commit into] master from feature