mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
fix: update branch selector
This commit is contained in:
parent
c75abf5c33
commit
29e90054ba
1 changed files with 18 additions and 2 deletions
|
|
@ -59,11 +59,27 @@ function getBranches() {
|
|||
|
||||
function getCurrentBranch() {
|
||||
const selectedBranchButtonSelector =
|
||||
'.repository-content > .file-navigation > .branch-select-menu > button'
|
||||
'.repository-content .file-navigation .branch-select-menu summary'
|
||||
const branchNameFromButtonElement = $(selectedBranchButtonSelector, element =>
|
||||
(element as HTMLButtonElement).title.trim(),
|
||||
)
|
||||
if (branchNameFromButtonElement) return branchNameFromButtonElement
|
||||
const defaultTitle = 'Switch branches or tags'
|
||||
if (branchNameFromButtonElement && branchNameFromButtonElement !== defaultTitle)
|
||||
return branchNameFromButtonElement
|
||||
|
||||
const commitButtonSelector = '.repository-content .overall-summary .commits a'
|
||||
const urlFromCommitButton: string | undefined = $(
|
||||
commitButtonSelector,
|
||||
element => (element as HTMLAnchorElement).href,
|
||||
)
|
||||
if (urlFromCommitButton) {
|
||||
const commitPathRegex = /^(.*?)\/(.*?)\/commits\/(.*?)$/
|
||||
const result = urlFromCommitButton.match(commitPathRegex)
|
||||
if (result) {
|
||||
const [_, userName, repoName, branchName] = result
|
||||
return branchName
|
||||
}
|
||||
}
|
||||
|
||||
const selectedBranchSelector =
|
||||
'.select-menu.branch-select-menu .select-menu-modal .select-menu-list .select-menu-item.selected svg.select-menu-item-icon + span'
|
||||
|
|
|
|||
Loading…
Reference in a new issue