Skip to content

Commit

Permalink
simplify the code and some other tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Feb 15, 2016
1 parent 2f217df commit 735933c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
21 changes: 9 additions & 12 deletions extension/content.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* globals gitHubInjection */
'use strict';
const path = location.pathname;
const isDashboard = path === '/';
const isRepo = /^\/.*\/.*\//.test(location.pathname)
const isPR = () => /^\/.*\/.*\/pull\/\d+$/.test(location.pathname);
const isRepo = /^\/[^/]+\/[^/]+/.test(location.pathname);
const isPR = () => /^\/[^/]+\/[^/]+\/pull\/\d+$/.test(location.pathname);
const repoName = path.split('/')[2];

function linkifyBranchRefs() {
Expand All @@ -15,30 +16,26 @@ function linkifyBranchRefs() {
}

document.addEventListener('DOMContentLoaded', () => {
const username = document.querySelector('meta[name="user-login"]').getAttribute('content');
const username = $('meta[name="user-login"]').attr('content');

if (isDashboard) {
// hide other users starring/forking your repos
{
const hideStarsOwnRepos = () => {
const items = Array.from(document.querySelectorAll('#dashboard .news .watch_started, #dashboard .news .fork'));

for (const item of items) {
if (item.querySelector('.title a[href^="/' + username + '"')) {
item.style.display = 'none';
}
}
$('#dashboard .news .watch_started, #dashboard .news .fork')
.has(`.title a[href^="/${username}"`)
.css('display', 'none');
};

hideStarsOwnRepos();

new MutationObserver(() => hideStarsOwnRepos())
.observe(document.querySelector('#dashboard .news'), {childList: true});
.observe($('#dashboard .news').get(0), {childList: true});
}

// expand all the news feed pages
(function more() {
const btn = document.querySelector('.ajax-pagination-btn');
const btn = $('.ajax-pagination-btn').get(0);

if (!btn) {
return;
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
},
"xo": {
"envs": [
"browser"
"browser",
"jquery"
],
"ignores": [
"extension/vendor/**"
]
}
}

0 comments on commit 735933c

Please sign in to comment.