From 67687de0c81e16f6078929b34489c3d1f7e1a297 Mon Sep 17 00:00:00 2001
From: Ram Lmn
Date: Fri, 7 Jul 2017 23:30:13 +0530
Subject: [PATCH] Extend customizability
---
extension/content.css | 30 ++++++++++----
extension/options.html | 89 +++++++++++++++++++++++++++++++++++++++---
src/background.js | 10 ++++-
src/content.js | 60 +++++++++++++++++-----------
src/libs/show-names.js | 41 ++++++++++++++-----
5 files changed, 185 insertions(+), 45 deletions(-)
diff --git a/extension/content.css b/extension/content.css
index b6258392d7b6..455616c8f198 100644
--- a/extension/content.css
+++ b/extension/content.css
@@ -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;
diff --git a/extension/options.html b/extension/options.html
index 6bbeb4a32ecc..73e5d3523d47 100644
--- a/extension/options.html
+++ b/extension/options.html
@@ -3,23 +3,101 @@
Codestin Search App
+
+
+
diff --git a/src/background.js b/src/background.js
index fee22138fbed..34a544e3f889 100644
--- a/src/background.js
+++ b/src/background.js
@@ -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
diff --git a/src/content.js b/src/content.js
index 2fbca1cb4e74..83ca04732c61 100644
--- a/src/content.js
+++ b/src/content.js
@@ -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');
@@ -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
+ 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();
@@ -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()) {
diff --git a/src/libs/show-names.js b/src/libs/show-names.js
index db80112b268e..0303fe7da191 100644
--- a/src/libs/show-names.js
+++ b/src/libs/show-names.js
@@ -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,7 +46,9 @@ const fetchName = async username => {
export default async () => {
const myUsername = getUsername();
- const cache = (await getCachedUsers())[storageKey];
+ const cache = (await getCachedUsers())[storageKey] || {};
+
+ const options = await new OptionsSync().getAll();
// {sindresorhus: [a.author, a.author], otheruser: [a.author]}
const selector = `.js-discussion .author:not(.refined-github-fullname)`;
@@ -35,7 +56,7 @@ export default async () => {
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]) {