@@ -6,10 +6,34 @@ import { formatClass, parseIntFromElement } from 'utils/DOMHelper'
6
6
import { renderReact , run } from 'utils/general'
7
7
import { CopyFileButton , copyFileButtonClassName } from './CopyFileButton'
8
8
9
+ const selectors = {
10
+ globalNavigation : {
11
+ navbar : {
12
+ repositoryOwner : [
13
+ '.AppHeader-context-item[data-hovercard-type="user"]' ,
14
+ '.AppHeader-context-item[data-hovercard-type="organization"]' ,
15
+ ] . join ( ) ,
16
+ // its meant to be the element visually next to the `repositoryOwner` element
17
+ repositoryName :
18
+ 'nav[role="navigation"] ul[role="list"] li:nth-child(2) .AppHeader-context-item' ,
19
+ } ,
20
+ } ,
21
+ }
22
+
9
23
export function resolveMeta ( ) : Partial < MetaData > {
10
24
const metaData = {
11
- userName : $ ( '[itemprop="author"] > a[rel="author"]' , e => e . textContent ?. trim ( ) ) || undefined ,
12
- repoName : $ ( '[itemprop="name"] > a[href]' , e => e . textContent ?. trim ( ) ) || undefined ,
25
+ userName :
26
+ $ (
27
+ '[itemprop="author"] > a[rel="author"]' ,
28
+ e => e . textContent ?. trim ( ) ,
29
+ ( ) => $ ( selectors . globalNavigation . navbar . repositoryOwner , e => e . textContent ?. trim ( ) ) ,
30
+ ) || undefined ,
31
+ repoName :
32
+ $ (
33
+ '[itemprop="name"] > a[href]' ,
34
+ e => e . textContent ?. trim ( ) ,
35
+ ( ) => $ ( selectors . globalNavigation . navbar . repositoryName , e => e . textContent ?. trim ( ) ) ,
36
+ ) || undefined ,
13
37
branchName : getCurrentBranch ( true ) ,
14
38
}
15
39
if ( ! metaData . userName || ! metaData . repoName ) {
@@ -19,15 +43,15 @@ export function resolveMeta(): Partial<MetaData> {
19
43
}
20
44
21
45
export function isInRepoPage ( ) {
22
- const repoHeadSelector = '.repohead' // legacy
46
+ const repoHeadSelector = '.repohead'
23
47
const authorNameSelector = '.author[itemprop="author"]'
24
- const globalNavigationSelectors = [
25
- '.AppHeader-context-item[data-hovercard-type="user"]' ,
26
- '.AppHeader-context-item[data-hovercard-type="organization"]' ,
27
- ] . join ( )
28
48
return Boolean (
29
49
document . querySelector (
30
- [ repoHeadSelector , authorNameSelector , globalNavigationSelectors ] . join ( ) ,
50
+ [
51
+ repoHeadSelector ,
52
+ authorNameSelector ,
53
+ selectors . globalNavigation . navbar . repositoryOwner ,
54
+ ] . join ( ) ,
31
55
) ,
32
56
)
33
57
}
0 commit comments