diff options
author | 2020-01-28 11:18:31 +0100 | |
---|---|---|
committer | 2020-01-28 17:18:31 +0700 | |
commit | 35234d1f6201802c86cc9a75c742ab09a6cd9b96 (patch) | |
tree | 3866daaa780a97bdc5dd4bc740581056c20e7972 /source/features/link-to-file-in-file-history.tsx | |
parent | b97f474a0c00f0d8f405e4f6219e92e34260bfaf (diff) | |
download | refined-github-35234d1f6201802c86cc9a75c742ab09a6cd9b96.tar.gz refined-github-35234d1f6201802c86cc9a75c742ab09a6cd9b96.tar.zst refined-github-35234d1f6201802c86cc9a75c742ab09a6cd9b96.zip |
Fix `link-to-file-in-file-history` path detection on page 2+ (#2731)
Co-authored-by: Federico Brigante <github@bfred.it>
Diffstat (limited to 'source/features/link-to-file-in-file-history.tsx')
-rw-r--r-- | source/features/link-to-file-in-file-history.tsx | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/source/features/link-to-file-in-file-history.tsx b/source/features/link-to-file-in-file-history.tsx index b788b6be..3c934d5e 100644 --- a/source/features/link-to-file-in-file-history.tsx +++ b/source/features/link-to-file-in-file-history.tsx @@ -2,22 +2,23 @@ import React from 'dom-chef'; import select from 'select-dom'; import fileIcon from 'octicon/file.svg'; import features from '../libs/features'; -import {getRepoPath} from '../libs/utils'; import {groupSiblings} from '../libs/group-buttons'; function init(): void | false { - // /user/repo/commits/master/readme.md -> 'readme.md' - // /user/repo/commits/master/ -> '' - const path = getRepoPath()!.replace(/^commits\/[^/]+\/?/, ''); - if (!path) { + const breadcrumb = select('.breadcrumb'); + if (!breadcrumb) { + // Probably looking at the base /commits/<branch> page, not a subfolder or file. return false; } + // Extract the file path from the breadcrumb. Aware of branch names that contain slashes + const path = breadcrumb.textContent!.trim().replace(/^History for [^/]+/, ''); + for (const rootLink of select.all<HTMLAnchorElement>('[aria-label="Browse the repository at this point in the history"]')) { // `rootLink.pathname` points to /tree/ but GitHub automatically redirects to /blob/ when the path is of a file rootLink.before( <a - href={rootLink.pathname + '/' + path} + href={rootLink.pathname + path} className="btn btn-outline tooltipped tooltipped-sw" aria-label="See object at this point in the history" > |