diff options
author | 2020-06-02 15:56:29 +0200 | |
---|---|---|
committer | 2020-06-02 15:56:29 +0200 | |
commit | 9ddcd95d766d26af8fe6362c65f32370464c5bd2 (patch) | |
tree | af6bcdd89c34c4bc51691bcf81a8fb8ab686a1ae /source/github-helpers | |
parent | 8b37902da5da3506d9fc26000c866a0fcf35df46 (diff) | |
download | refined-github-9ddcd95d766d26af8fe6362c65f32370464c5bd2.tar.gz refined-github-9ddcd95d766d26af8fe6362c65f32370464c5bd2.tar.zst refined-github-9ddcd95d766d26af8fe6362c65f32370464c5bd2.zip |
Faster and clearer `getCurrentBranch` function
Diffstat (limited to 'source/github-helpers')
-rw-r--r-- | source/github-helpers/index.ts | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/source/github-helpers/index.ts b/source/github-helpers/index.ts index 8eae0717..380cc10d 100644 --- a/source/github-helpers/index.ts +++ b/source/github-helpers/index.ts @@ -16,14 +16,17 @@ export const getDiscussionNumber = (): string | undefined => { return undefined; }; -/* Should work on `isRepoTree` `isBlame` `isSingleFile` `isCommitList` `isCompare` `isPRCommit` */ +/** +Tested on isRepoTree, isBlame, isSingleFile, isEditFile, isCommit, isCommitList, isCompare, isPR +Example tag content: https://github.com/sindresorhus/refined-github/commits/branch-or-commit-even-with-slashes.atom +*/ export const getCurrentBranch = (): string => { - return select.last<HTMLLinkElement>('link[rel="alternate"]')! + return select<HTMLLinkElement>('[type="application/atom+xml"]')! .href .split('/') - .slice(6) + .slice(6) // Drops the initial https://host/user/repo/route/ part .join('/') - .replace(/\.atom.*/, ''); + .replace(/\.atom$/, ''); }; export const isFirefox = navigator.userAgent.includes('Firefox/'); |