Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit cf9a407

Browse files
committed
Get from localStorage justs once, and followee is a word
1 parent 7aac142 commit cf9a407

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

dashboard.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const events = [
3939
'team_add', 'member_add'
4040
]
4141

42+
let listOfFollowees
43+
4244
init()
4345
updateClasses()
4446
if (context === 'user') specifyTimelineEvents()
@@ -139,46 +141,50 @@ function specifyTimelineEvents() {
139141
observer.observe(dashboard, {subtree: true, childList: true})
140142
}
141143

142-
async function getFollowingList() {
144+
async function getFolloweeList() {
145+
if (listOfFollowees) return listOfFollowees
146+
143147
console.log('Dashboard extension: getting list of people you follow from localStorage')
144-
const following = localStorage.getItem('dashboard:following')
145-
if (!following || (following && (new Date().getTime() - new Date(JSON.parse(following).updatedAt))/1000 > 24*60*60)) {
146-
const results = await fetchFollowing()
147-
const following = {
148+
const followees = localStorage.getItem('dashboard:following')
149+
if (!followees || (followees && (new Date().getTime() - new Date(JSON.parse(followees).updatedAt))/1000 > 24*60*60)) {
150+
const results = await fetchFollowees()
151+
const followees = {
148152
updatedAt: (new Date()).getTime(),
149153
following: results
150154
}
151-
localStorage.setItem('dashboard:following', JSON.stringify(following))
152-
return results
155+
localStorage.setItem('dashboard:following', JSON.stringify(followees))
156+
listOfFollowees = results
153157
} else {
154-
return JSON.parse(following).following
158+
listOfFollowees = JSON.parse(followees).following
155159
}
160+
161+
return listOfFollowees
156162
}
157163

158-
async function fetchFollowing() {
164+
async function fetchFollowees() {
159165
console.log('Dashboard extension: updating list of people you follow from GitHub API (once every 24h)')
160166
return new Promise(async function(resolve) {
161-
let following = []
167+
let followees = []
162168
const user = document.querySelector('.HeaderNavlink.name img').alt.slice(1)
163169
const endpoint = `https://api.github.com/users/${user}/following`
164170
let page = 1
165171
while (page > 0) {
166172
const res = await fetch(`${endpoint}?page=${page}`)
167173
const people = await res.json()
168-
following = following.concat(people)
174+
followees = followees.concat(people)
169175
if (people.length === 30) {
170176
page++
171177
} else {
172178
page = 0
173-
resolve(following.map(o => o.login))
179+
resolve(followees.map(o => o.login))
174180
}
175181
}
176182
})
177183
}
178184

179185
// Could break if GitHub changes its markup
180186
async function addMoreSpecificIdentifiers(list) {
181-
const following = await getFollowingList()
187+
const followees = await getFolloweeList()
182188
for (const record of list) {
183189
if (!record.target.classList.contains('news')) continue
184190
for (const eventItem of record.addedNodes) {
@@ -188,7 +194,7 @@ async function addMoreSpecificIdentifiers(list) {
188194

189195
// Check if any links are to one of the followed people
190196
const fromFollowedPeople = Array.from(eventItem.querySelectorAll('a')).some(function(maybeActor) {
191-
return following.indexOf(maybeActor.pathname.slice(1)) >= 0
197+
return followees.indexOf(maybeActor.pathname.slice(1)) >= 0
192198
})
193199
eventItem.classList.add(fromFollowedPeople ? 'by_followed_people' : 'by_internet')
194200
}

0 commit comments

Comments
 (0)