-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Extend customization #585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Extend customization #585
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import select from 'select-dom'; | ||
| import OptionsSync from 'webext-options-sync'; | ||
| import domify from './domify'; | ||
| import {getUsername, groupBy} from './utils'; | ||
|
|
||
|
|
@@ -8,16 +9,34 @@ const getCachedUsers = () => { | |
| return new Promise(resolve => chrome.storage.local.get(storageKey, resolve)); | ||
| }; | ||
|
|
||
| const fetchName = async username => { | ||
| // /following/you_know is the lightest page we know | ||
| // location.origin is required for Firefox #490 | ||
| const pageHTML = await fetch(`${location.origin}/${username}/following`) | ||
| .then(res => res.text()); | ||
| const fetchName = async (username, accessToken) => { | ||
| let fullname = ''; | ||
|
|
||
| const el = domify(pageHTML).querySelector('h1 strong'); | ||
| if (accessToken) { | ||
| // Check if user is on an enterprise domain | ||
| const url = location.origin.endsWith('github.com') ? | ||
| 'https://api.github.com' : | ||
| `${location.origin}/api/v3`; | ||
|
|
||
| const headers = new Headers(); | ||
| headers.set('Authorization', `token ${accessToken}`); | ||
|
|
||
| const userData = await fetch(`${url}/users/${username}`, {headers}) | ||
| .then(res => res.json()); | ||
|
|
||
| fullname = userData.name; | ||
| } else { | ||
| // `following/you_know` is the lightest page we know | ||
| // location.origin is required for Firefox #490 | ||
| const pageHTML = await fetch(`${location.origin}/${username}/following`) | ||
| .then(res => res.text()); | ||
|
|
||
| const el = domify(pageHTML).querySelector('h1 strong'); | ||
|
|
||
| // The full name might not be set | ||
| fullname = el && el.textContent.slice(1, -1); | ||
| } | ||
|
|
||
| // The full name might not be set | ||
| const fullname = el && el.textContent.slice(1, -1); | ||
| if (!fullname || fullname === username) { | ||
| // It has to be stored as false or else it will be fetched every time | ||
| return false; | ||
|
|
@@ -27,15 +46,17 @@ const fetchName = async username => { | |
|
|
||
| export default async () => { | ||
| const myUsername = getUsername(); | ||
| const cache = (await getCachedUsers())[storageKey]; | ||
| const cache = (await getCachedUsers())[storageKey] || {}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please send this line as a separate PR so we can get that in ASAP :)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| const options = await new OptionsSync().getAll(); | ||
|
|
||
| // {sindresorhus: [a.author, a.author], otheruser: [a.author]} | ||
| const selector = `.js-discussion .author:not(.refined-github-fullname)`; | ||
| const usersOnPage = groupBy(select.all(selector), el => el.textContent); | ||
|
|
||
| const fetchAndAdd = async username => { | ||
| if (typeof cache[username] === 'undefined' && username !== myUsername) { | ||
| cache[username] = await fetchName(username); | ||
| cache[username] = await fetchName(username, options.privateAccessToken); | ||
| } | ||
|
|
||
| for (const usernameEl of usersOnPage[username]) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this. Separate PR? 😃