Skip to content

Commit 6b73ee1

Browse files
committed
v2.5.3
1 parent 6314c8c commit 6b73ee1

File tree

7 files changed

+21
-5
lines changed

7 files changed

+21
-5
lines changed

HISTORY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
### v2.5.2
1+
### v2.5.3
22

33
- Fix branch retrieval due to GitHub DOM changes
44
- Fix bug folder closing/opening repeat

dist/chrome.crx

221 Bytes
Binary file not shown.

dist/chrome.zip

192 Bytes
Binary file not shown.

dist/firefox.zip

199 Bytes
Binary file not shown.

dist/opera.nex

221 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "octotree",
3-
"version": "2.5.2",
3+
"version": "2.5.3",
44
"description": "Code tree for GitHub",
55
"main": "inject.js",
66
"scripts": {

src/adapters/github.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,31 @@ class GitHub extends PjaxAdapter {
143143

144144
// Get branch by inspecting URL or DOM, quite fragile so provide multiple fallbacks.
145145
// TODO would be great if there's a more robust way to do this
146-
const branchDropdownMenu = $('.branch-select-menu');
146+
/**
147+
* Github renders the branch name in one of below structure depending on the length
148+
* of branch name
149+
*
150+
* Option 1: when the length is short enough
151+
* <summary title="Switch branches or tags">
152+
* <span class="css-truncate-target">feature/1/2/3</span>
153+
* </summary>
154+
*
155+
* Option 2: when the length is too long
156+
* <summary title="feature/1/2/3/4/5/6/7/8">
157+
* <span class="css-truncate-target">feature/1/2/3...</span>
158+
* </summary>
159+
*/
160+
const branchDropdownMenuSummary = $('.branch-select-menu summary');
161+
const branchNameInTitle = branchDropdownMenuSummary.attr('title');
162+
const branchNameInSpan = branchDropdownMenuSummary.find('span').text();
163+
147164
const branch =
148165
// Pick the commit ID as branch name when the code page is listing tree in a particular commit
149166
(type === 'commit' && typeId) ||
150167
// Pick the commit ID or branch name from the DOM
151168
// Note: we can't use URL as it would not work with branches with slashes, e.g. features/hotfix-1
152169
($('.overall-summary .numbers-summary .commits a').attr('href') || '').split('/').slice(-1)[0] ||
153-
$('.select-menu-item[aria-checked="true"] span', branchDropdownMenu).text() ||
154-
$('.select-menu-button span', branchDropdownMenu).text() ||
170+
(branchNameInTitle.toLowerCase().startsWith('switch branches') ? branchNameInSpan : branchNameInTitle) ||
155171
// Pull requests page
156172
($('.commit-ref.base-ref').attr('title') || ':').match(/:(.*)/)[1] ||
157173
// Reuse last selected branch if exist

0 commit comments

Comments
 (0)