-
Notifications
You must be signed in to change notification settings - Fork 1
/
github.touchbar-packet
139 lines (119 loc) · 2.74 KB
/
github.touchbar-packet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// ==TouchbarPacket==
// @name GitHub
// @match https://github.com/*
// ==/TouchbarPacket==
/* global touchbar:readonly */
const githubPaths = [
'/pulls',
'/issues',
'/marketplace',
'/explore',
'/topics',
'/trending',
'/collections',
'/events',
'/sponsors',
]
console.log('LOADING GITHUB SCRIPT')
console.log(
'PATHNAME',
location.pathname,
location.pathname == '/',
githubPaths.find(x => location.pathname.startsWith(x))
)
if (
location.pathname == '/' ||
githubPaths.find(x => location.pathname.startsWith(x))
) {
loadGeneral()
} else {
loadRepo()
}
function loadGeneral() {
console.log('not repo')
const ACTION_HOME = 'navigate-home'
const ACTION_PULL_REQUESTS = 'navigate-pull-requests'
const ACTION_ISSUES = 'navigate-issues'
const ACTION_MARKETPLACE = 'navigate-marketplace'
const ACTION_EXPLORE = 'navigate-explore'
touchbar.changeLayout([
{
type: 'button',
name: ACTION_HOME,
label: 'Home',
},
{
type: 'button',
name: ACTION_PULL_REQUESTS,
label: 'Pull requests',
},
{
type: 'button',
name: ACTION_ISSUES,
label: 'Issues',
},
{
type: 'button',
name: ACTION_MARKETPLACE,
label: 'Marketplace',
},
{
type: 'button',
name: ACTION_EXPLORE,
label: 'Explore',
},
])
touchbar.addEventListener(message => {
if (message.type == 'action') {
switch (message.name) {
case ACTION_HOME:
location.href = '/'
break
case ACTION_PULL_REQUESTS:
location.href = '/pulls'
break
case ACTION_ISSUES:
location.href = '/issues'
break
case ACTION_MARKETPLACE:
location.href = '/marketplace'
break
case ACTION_EXPLORE:
location.href = '/explore'
break
}
}
})
}
function loadRepo() {
// Repository
console.log('repo here')
const repoMenu = document.querySelector(
'main nav[aria-label="Repository"] ul'
)
console.log('REPO MENU', repoMenu)
const menuItemElements = repoMenu.querySelectorAll('li')
console.log(menuItemElements)
const menuItems = [...menuItemElements].map(elm => ({
link: elm.querySelector('a').href,
label: elm.querySelector('span').textContent,
}))
console.log(menuItems)
const layout = menuItems.map(item => ({
type: 'button',
name: `navigate-repo-${item.label}`,
label: item.label,
}))
console.log(menuItems, layout)
touchbar.changeLayout(layout)
touchbar.addEventListener(message => {
if (message.type == 'action') {
const item = menuItems.find(
x => message.name == `navigate-repo-${x.label}`
)
if (item) {
location.href = item.link
}
}
})
}