From 614f4021fb1b10002e773de33e77396a956c943a Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Mon, 18 Mar 2019 15:06:58 +0800 Subject: [PATCH 1/7] Add timemachine links to all repo links --- source/content.css | 8 ----- .../features/comments-time-machine-links.tsx | 30 +++++++++++++++++-- source/libs/icons.tsx | 2 ++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/source/content.css b/source/content.css index dd564624634..8b80c03f41a 100644 --- a/source/content.css +++ b/source/content.css @@ -713,14 +713,6 @@ a.tabnav-extra[href$='mastering-markdown/'] { display: none !important; } -/* For the `add-time-machine-links-to-comments` feature */ -:root .rgh-timestamp-button { - padding: 0; -} -:root .rgh-timestamp-button .octicon { - vertical-align: middle; -} - @keyframes fade-in { from { opacity: 0; diff --git a/source/features/comments-time-machine-links.tsx b/source/features/comments-time-machine-links.tsx index 50c72edfa1a..a46bd38eedb 100644 --- a/source/features/comments-time-machine-links.tsx +++ b/source/features/comments-time-machine-links.tsx @@ -10,19 +10,45 @@ function init() { for (const comment of comments) { const timestampEl = select('relative-time', comment.closest('.discussion-item-review') || comment); const timestamp = timestampEl.attributes['datetime'].value; // eslint-disable-line dot-notation + const humanDate = timestampEl.textContent; const href = `/${getRepoURL()}/tree/HEAD@{${timestamp}}`; timestampEl.parentElement.after( ' ', {icons.code()} ); + const links = select.all(` + [href^="${location.origin}"][href*="/blob/"], + [href^="${location.origin}"][href*="/tree/"] + `, comment.closest('.comment')); + for (const link of links) { + console.log(link) + const linkParts = link.pathname.split('/'); + // Skip permalinks + if (/^[0-9a-f]{40}$/.test(linkParts[3])) { + continue; + } + + linkParts[3] = `HEAD@{${timestamp}}`; // Change git ref + link.after( + ' ', + + {icons.clock()} + + ); + } + comment.classList.add('rgh-timestamp-tree-link'); } } diff --git a/source/libs/icons.tsx b/source/libs/icons.tsx index 4d8fd5b2cda..f5e69af5606 100644 --- a/source/libs/icons.tsx +++ b/source/libs/icons.tsx @@ -36,6 +36,8 @@ export const chevronDown = (): SVGElement => ; +export const clock = (): SVGElement => ; + export const commit = (): SVGElement => ; export const diff = (): SVGElement => ; From d6961b6c4780f4dea133fa4cc889908028690962 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Tue, 19 Mar 2019 01:37:00 +0800 Subject: [PATCH 2/7] Drop console.log --- source/features/comments-time-machine-links.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/source/features/comments-time-machine-links.tsx b/source/features/comments-time-machine-links.tsx index a46bd38eedb..5671058aa59 100644 --- a/source/features/comments-time-machine-links.tsx +++ b/source/features/comments-time-machine-links.tsx @@ -29,7 +29,6 @@ function init() { [href^="${location.origin}"][href*="/tree/"] `, comment.closest('.comment')); for (const link of links) { - console.log(link) const linkParts = link.pathname.split('/'); // Skip permalinks if (/^[0-9a-f]{40}$/.test(linkParts[3])) { From c60e862ad1d2b808c9abce833bb1587210793f0c Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Tue, 19 Mar 2019 01:46:02 +0800 Subject: [PATCH 3/7] Fix link --- source/features/comments-time-machine-links.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/features/comments-time-machine-links.tsx b/source/features/comments-time-machine-links.tsx index 5671058aa59..0152013204e 100644 --- a/source/features/comments-time-machine-links.tsx +++ b/source/features/comments-time-machine-links.tsx @@ -31,11 +31,11 @@ function init() { for (const link of links) { const linkParts = link.pathname.split('/'); // Skip permalinks - if (/^[0-9a-f]{40}$/.test(linkParts[3])) { + if (/^[0-9a-f]{40}$/.test(linkParts[4])) { continue; } - linkParts[3] = `HEAD@{${timestamp}}`; // Change git ref + linkParts[4] = `HEAD@{${timestamp}}`; // Change git ref link.after( ' ', Date: Wed, 17 Apr 2019 20:58:09 +0800 Subject: [PATCH 4/7] Strict TS --- source/features/comments-time-machine-links.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/features/comments-time-machine-links.tsx b/source/features/comments-time-machine-links.tsx index 4514ff03f72..90983ebd778 100644 --- a/source/features/comments-time-machine-links.tsx +++ b/source/features/comments-time-machine-links.tsx @@ -28,7 +28,7 @@ function init() { const links = select.all(` [href^="${location.origin}"][href*="/blob/"], [href^="${location.origin}"][href*="/tree/"] - `, comment.closest('.comment')); + `, comment.closest('.comment')!); for (const link of links) { const linkParts = link.pathname.split('/'); // Skip permalinks @@ -41,7 +41,7 @@ function init() { ' ', {icons.clock()} From 9e88023f3c39c11edc3297120f7283d86c48a616 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Wed, 17 Apr 2019 20:58:27 +0800 Subject: [PATCH 5/7] Exclude linkified URLs in code --- source/features/comments-time-machine-links.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/features/comments-time-machine-links.tsx b/source/features/comments-time-machine-links.tsx index 90983ebd778..749cca8301d 100644 --- a/source/features/comments-time-machine-links.tsx +++ b/source/features/comments-time-machine-links.tsx @@ -26,8 +26,8 @@ function init() { ); const links = select.all(` - [href^="${location.origin}"][href*="/blob/"], - [href^="${location.origin}"][href*="/tree/"] + [href^="${location.origin}"][href*="/blob/"]:not(.rgh-linkified-code), + [href^="${location.origin}"][href*="/tree/"]:not(.rgh-linkified-code) `, comment.closest('.comment')!); for (const link of links) { const linkParts = link.pathname.split('/'); From 894b7bc9b854a8054faab5555b27113e949db911 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Thu, 18 Apr 2019 15:32:19 +0800 Subject: [PATCH 6/7] Move link to dropdown --- .../features/comments-time-machine-links.tsx | 85 +++++++++++-------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/source/features/comments-time-machine-links.tsx b/source/features/comments-time-machine-links.tsx index 749cca8301d..d8c3372cfc7 100644 --- a/source/features/comments-time-machine-links.tsx +++ b/source/features/comments-time-machine-links.tsx @@ -4,52 +4,63 @@ import features from '../libs/features'; import * as icons from '../libs/icons'; import {getRepoURL} from '../libs/utils'; -function init() { - const comments = select.all('.timeline-comment-header:not(.rgh-timestamp-tree-link)'); +function addInlineLinks(comment: HTMLElement, timestamp: string) { + const links = select.all(` + [href^="${location.origin}"][href*="/blob/"]:not(.rgh-linkified-code), + [href^="${location.origin}"][href*="/tree/"]:not(.rgh-linkified-code) + `, comment); - for (const comment of comments) { - const timestampEl = select('relative-time', comment.closest('.discussion-item-review') || comment)!; - const timestamp = timestampEl.attributes.datetime.value; - const humanDate = timestampEl.textContent; - - const href = `/${getRepoURL()}/tree/HEAD@{${timestamp}}`; + for (const link of links) { + const linkParts = link.pathname.split('/'); + // Skip permalinks + if (/^[0-9a-f]{40}$/.test(linkParts[4])) { + continue; + } - timestampEl.parentElement!.after( + linkParts[4] = `HEAD@{${timestamp}}`; // Change git ref + link.after( ' ', - {icons.code()} + aria-label="Visit as permalink"> + {icons.clock()} ); + } +} - const links = select.all(` - [href^="${location.origin}"][href*="/blob/"]:not(.rgh-linkified-code), - [href^="${location.origin}"][href*="/tree/"]:not(.rgh-linkified-code) - `, comment.closest('.comment')!); - for (const link of links) { - const linkParts = link.pathname.split('/'); - // Skip permalinks - if (/^[0-9a-f]{40}$/.test(linkParts[4])) { - continue; - } - - linkParts[4] = `HEAD@{${timestamp}}`; // Change git ref - link.after( - ' ', - - {icons.clock()} - - ); - } +function addDropdownLink(comment: HTMLElement, timestamp: string) { + const dropdownPosition = select('.show-more-popover .dropdown-divider', comment); + + // Comment-less reviews don't have a dropdown + if (!dropdownPosition) { + return; + } + + dropdownPosition.after( + + View repo at this time + , +
+ ); +} + +async function init() { + const comments = select.all(` + :not(.js-new-comment-form) > .timeline-comment:not(.rgh-time-machine-links), + .review-comment:not(.rgh-time-machine-links) + `); + + for (const comment of comments) { + const timestamp = select('relative-time', comment)!.attributes.datetime.value; - comment.classList.add('rgh-timestamp-tree-link'); + addDropdownLink(comment, timestamp); + addInlineLinks(comment, timestamp); + comment.classList.add('rgh-time-machine-links'); } } From 8caec72501e518a7e4ea15ad7429572cfd1f45d7 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Sat, 20 Apr 2019 11:02:23 +0800 Subject: [PATCH 7/7] Mention in readme --- readme.md | 2 +- source/features/comments-time-machine-links.tsx | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index c138feaa34c..e3a2695cae8 100644 --- a/readme.md +++ b/readme.md @@ -114,7 +114,7 @@ GitHub Enterprise is also supported. More info in the options. - [Copy a file's content.](https://cloud.githubusercontent.com/assets/170270/14453865/8abeaefe-00c1-11e6-8718-9406cee1dc0d.png) - [Quickly access a commit's `.patch` and `.diff` files.](https://cloud.githubusercontent.com/assets/737065/13605562/22faa79e-e516-11e5-80db-2da6aa7965ac.png) - [Navigate from PR commit to raw commit by clicking the commit hash.](https://user-images.githubusercontent.com/101152/42968387-606b23f2-8ba3-11e8-8a4b-667bddc8d33c.png) -- [Browse a repository at the time of each comment.](https://user-images.githubusercontent.com/1402241/32310022-7fef6174-bf5d-11e7-960f-5041a8f073ac.png) +- [Browse a repository at the time of each comment,](https://user-images.githubusercontent.com/1402241/56450896-68076680-635b-11e9-8b24-ebd11cc4e655.png) including [each link.](https://user-images.githubusercontent.com/1402241/56450895-68076680-635b-11e9-86b4-b6c2f3745d51.png) - [Visit a user's public gists from their profile.](https://user-images.githubusercontent.com/11544418/34268306-1c974fd2-e678-11e7-9e82-861dfe7add22.png) - [Download entire folders from repositories using the `Download folder` button.](https://user-images.githubusercontent.com/1402241/35044451-fd3e2326-fbc2-11e7-82e1-61ec7bee612b.png) *(Uses [download-directory.github.io](https://download-directory.github.io).)* - [Collapse or expand a repository's browser file list.](https://user-images.githubusercontent.com/1402241/35480123-68b9af1a-043a-11e8-8934-3ead3cff8328.gif) diff --git a/source/features/comments-time-machine-links.tsx b/source/features/comments-time-machine-links.tsx index d8c3372cfc7..e2371bf56b3 100644 --- a/source/features/comments-time-machine-links.tsx +++ b/source/features/comments-time-machine-links.tsx @@ -42,7 +42,8 @@ function addDropdownLink(comment: HTMLElement, timestamp: string) { + role="menuitem" + title="Browse repository like it appeared on this day"> View repo at this time ,