Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions extension/content.css
Original file line number Diff line number Diff line change
Expand Up @@ -395,17 +395,33 @@ svg.octicon.octicon-repo.dashboard-event-icon {
}

/* Make tab indented code more readable on GitHub and Gist */
.tab-size[data-tab-size='2'],
.tab-size[data-tab-size='4'],
.tab-size[data-tab-size='8'],
.inline-review-comment,
.gist table.lines,
.highlight pre, /* Readme code blocks */
.blob-code-inner /* PR inline diff */ {
body[data-tab-size='2'] .tab-size[data-tab-size],
body[data-tab-size='2'] .inline-review-comment,
body[data-tab-size='2'] .gist table.lines,
body[data-tab-size='2'] .highlight pre, /* Readme code blocks */
body[data-tab-size='2'] .blob-code-inner /* PR inline diff */ {
-moz-tab-size: 2 !important;
tab-size: 2 !important;
}

body[data-tab-size='4'] .tab-size[data-tab-size],
body[data-tab-size='4'] .inline-review-comment,
body[data-tab-size='4'] .gist table.lines,
body[data-tab-size='4'] .highlight pre, /* Readme code blocks */
body[data-tab-size='4'] .blob-code-inner /* PR inline diff */ {
-moz-tab-size: 4 !important;
tab-size: 4 !important;
}

body[data-tab-size='8'] .tab-size[data-tab-size],
body[data-tab-size='8'] .inline-review-comment,
body[data-tab-size='8'] .gist table.lines,
body[data-tab-size='8'] .highlight pre, /* Readme code blocks */
body[data-tab-size='8'] .blob-code-inner /* PR inline diff */ {
-moz-tab-size: 8 !important;
tab-size: 8 !important;
}

/* Larger comment box */
.comment-form-textarea {
min-height: 200px !important;
Expand Down
89 changes: 84 additions & 5 deletions extension/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,107 @@
<title>Refined GitHub options</title>
<style>
html {
font-family: sans-serif;
font-family: -apple-system, BlinkMacSystemFont,
'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell',
'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
}

h2 {
margin: 16px 0 8px;
font-weight: normal;
}

/* Increase spacing between sections */
h2 ~ h2,
form ~ form {
margin-top: 2em;
}

.checkbox label {
padding: 0;
display: flex;
}

.text label {
display: flex;
flex-direction: column;
}

input[type=text],
input[type=url] {
padding: 4px;
}

input[type=checkbox] {
margin: 4px;
}

input[type=checkbox] ~ span {
margin-left: 6px;
line-height: 21px;
}

select {
margin-left: 8px;
}
</style>

<form id="options-form">
<h2>News feed</h2>
<p>
<div class="checkbox">
<label>
<input type="checkbox" name="hideStarsOwnRepos">
Hide other users starring/forking your repos
<span>Hide other users starring/forking your repos</span>
</label>
</p>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="autoLoadMoreNews">
<span>Auto load more news on scrolling down</span>
</label>
</div>

<h2>Comments</h2>
<div class="checkbox">
<label>
<input type="checkbox" name="addReactionParticipants">
<span>Add reaction participants</span>
</label>
</div>
<div class="checkbox">
<label>
<input type="checkbox" name="showRealNames">
<span>Show real user names</span>
</label>
</div>

<h2>Code</h2>
<div class="select">
<label>
<span>Tab size</span>
<select name="tabSize">
<option value="0">default</option>
<option value="2">2</option>
<option value="4">4</option>
<option value="8">8</option>
</select>
</label>
</div>

<h2>Access token for API queries</h2>
<div class="text">
<label>
<input type="text" pattern="^[a-z0-9]{40}$" name="privateAccessToken" placeholder="Personal access token" autocomplete="false" spellcheck="false">
</label>
</div>
</form>

<form id="custom-domain">
<h2>GitHub Enterprise support</h2>
<p class="js-permission-api">
<input type="url" placeholder="https://github.yourdomain.com" size="30" required id="custom-domain-origin">
<button type="submit">Authorize</button>
</p>
</form>

<script src="options.js"></script>
10 changes: 9 additions & 1 deletion src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import injectContentScripts from 'webext-dynamic-content-scripts';
// Define defaults
new OptionsSync().define({
defaults: {
hideStarsOwnRepos: true
hideStarsOwnRepos: true,
autoLoadMoreNews: true,

addReactionParticipants: true,
showRealNames: true,

tabSize: 8,

privateAccessToken: ''
},
migrations: [
OptionsSync.migrations.removeUnused
Expand Down
60 changes: 38 additions & 22 deletions src/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,10 @@ function addTitleToEmojis() {
}
}

function setTabSize(size) {
$('body').attr('data-tab-size', size);
}

function init() {
if (select.exists('html.refined-github')) {
console.count('Refined GitHub was loaded multiple times: https://github.com/sindresorhus/refined-github/issues/479');
Expand Down Expand Up @@ -533,33 +537,40 @@ async function onDomReady() {

const username = getUsername();

markUnread.setup();
// Things that we want to do only when the user is logged in

Copy link
Copy Markdown
Member

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? 😃

if (username) {
markUnread.setup();

moveMarketplaceLinkToProfileDropdown();
moveMarketplaceLinkToProfileDropdown();

if (pageDetect.isGist()) {
addGistCopyButton();
}
if (pageDetect.isDashboard()) {
// Hide other users starring/forking your repos
const hideStarsOwnRepos = () => {
$('#dashboard .news .watch_started, #dashboard .news .fork')
.has(`.title a[href^="/${username}"]`)
.css('display', 'none');
};

if (pageDetect.isDashboard()) {
// Hide other users starring/forking your repos
const hideStarsOwnRepos = () => {
$('#dashboard .news .watch_started, #dashboard .news .fork')
.has(`.title a[href^="/${username}"]`)
.css('display', 'none');
};
if (options.hideStarsOwnRepos) {
hideStarsOwnRepos();
new MutationObserver(() => hideStarsOwnRepos())
.observe(select('#dashboard .news'), {childList: true});
}

if (options.hideStarsOwnRepos) {
hideStarsOwnRepos();
new MutationObserver(() => hideStarsOwnRepos())
.observe(select('#dashboard .news'), {childList: true});
if (options.autoLoadMoreNews) {
autoLoadMoreNews();
}
}

autoLoadMoreNews();
addUploadBtn();
new MutationObserver(addUploadBtn).observe(select('div[role=main]'), {childList: true, subtree: true});
}

addUploadBtn();
new MutationObserver(addUploadBtn).observe(select('div[role=main]'), {childList: true, subtree: true});
setTabSize(options.tabSize);

if (pageDetect.isGist()) {
addGistCopyButton();
}

if (pageDetect.isIssueSearch() || pageDetect.isPRSearch()) {
addYoursMenuItem();
Expand Down Expand Up @@ -613,9 +624,14 @@ async function onDomReady() {
}

if (pageDetect.isPR() || pageDetect.isIssue() || pageDetect.isCommit()) {
addReactionParticipants.add(username);
addReactionParticipants.addListener(username);
showRealNames();
if (options.addReactionParticipants) {
addReactionParticipants.add(username);
addReactionParticipants.addListener(username);
}

if (options.showRealNames) {
showRealNames();
}
}

if (pageDetect.isCommitList()) {
Expand Down
41 changes: 31 additions & 10 deletions src/libs/show-names.js
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';

Expand All @@ -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;
Expand All @@ -27,15 +46,17 @@ const fetchName = async username => {

export default async () => {
const myUsername = getUsername();
const cache = (await getCachedUsers())[storageKey];
const cache = (await getCachedUsers())[storageKey] || {};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 :)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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]) {
Expand Down