From 735933c01165e4f706b6a8193035928d59761e7b Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Tue, 16 Feb 2016 02:55:43 +0700 Subject: [PATCH] simplify the code and some other tweaks --- extension/content.js | 21 +++++++++------------ package.json | 6 +++++- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/extension/content.js b/extension/content.js index 7fe471f1f4cd..07d2ede16bed 100755 --- a/extension/content.js +++ b/extension/content.js @@ -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() { @@ -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; diff --git a/package.json b/package.json index 409cf2277738..82d0a9c640b6 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,11 @@ }, "xo": { "envs": [ - "browser" + "browser", + "jquery" + ], + "ignores": [ + "extension/vendor/**" ] } }