Skip to content

Commit ff36495

Browse files
committed
Clean up
1 parent 4d412e7 commit ff36495

1 file changed

Lines changed: 40 additions & 40 deletions

File tree

Github_News_Feed_Filter/Github_News_Feed_Filter.user.js

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// @grant none
2121
// ==/UserScript==
2222

23-
(function() {
23+
(function () {
2424

2525
var ICONS = {};
2626
ICONS['octicon-book'] = 'M3 5h4v1H3V5zm0 3h4V7H3v1zm0 2h4V9H3v1zm11-5h-4v1h4V5zm0 2h-4v1h4V7zm0 2h-4v1h4V9zm2-6v9c0 .55-.45 1-1 1H9.5l-1 1-1-1H2c-.55 0-1-.45-1-1V3c0-.55.45-1 1-1h5.5l1 1 1-1H15c.55 0 1 .45 1 1zm-8 .5L7.5 3H2v9h6V3.5zm7-.5H9.5l-.5.5V12h6V3z';
@@ -102,9 +102,9 @@
102102
var filterListElement = 'github-news-feed-filter-list';
103103

104104
function proxy(fn) {
105-
return function() {
105+
return function () {
106106
var that = this;
107-
return function(e) {
107+
return function (e) {
108108
var args = that.slice(0); // Clone.
109109
args.unshift(e); // Prepend event.
110110
fn.apply(this, args);
@@ -149,7 +149,7 @@
149149
}
150150
parent.appendChild(ul);
151151

152-
filters.forEach(function(subFilter) {
152+
filters.forEach(function (subFilter) {
153153
var li = addFilterMenuItem(type, subFilter, ul, newsContainer, filterContainer);
154154

155155
if (subFilter.subFilters) {
@@ -234,12 +234,12 @@
234234
setCurrentFilter(type, this.dataset[datasetId]);
235235

236236
// Open/close sub list.
237-
Array.forEach(filterContainer.querySelectorAll(':scope .open'), function(item) { item.classList.remove('open'); });
237+
Array.forEach(filterContainer.querySelectorAll(':scope .open'), function (item) { item.classList.remove('open'); });
238238
showParentMenu(this);
239239
this.parentNode.classList.add('open');
240240

241241
// Give it a colored background.
242-
Array.forEach(filterContainer.querySelectorAll(':scope .private'), function(m) { m.classList.remove('private'); });
242+
Array.forEach(filterContainer.querySelectorAll(':scope .private'), function (m) { m.classList.remove('private'); });
243243
this.parentNode.classList.add('private');
244244

245245
// Toggle alert visibility.
@@ -253,22 +253,22 @@
253253
var classNames = [];
254254
var selected = document.querySelectorAll(":scope " + filterElement + ' .private');
255255
if (selected.length > 0) {
256-
Array.prototype.forEach.call(selected, function(item) {
256+
Array.prototype.forEach.call(selected, function (item) {
257257
classNames.push(item.filterClassNames);
258258
});
259259
}
260260

261261
// Show/hide alerts.
262-
if (classNames.length === 0 || classNames.every(function(cl) { return cl.every(function(c) { return !!~c.indexOf('*'); }); })) {
262+
if (classNames.length === 0 || classNames.every(function (cl) { return cl.every(function (c) { return !!~c.indexOf('*'); }); })) {
263263
anyVisibleAlert = true;
264-
Array.prototype.forEach.call(newsContainer.querySelectorAll(':scope > div > .body'), function(alert) {
264+
Array.prototype.forEach.call(newsContainer.querySelectorAll(':scope > div > .body'), function (alert) {
265265
alert.parentNode.style.display = 'block';
266266
});
267267
} else {
268-
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function(alert) {
268+
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function (alert) {
269269
return alert.parentNode;
270-
}).forEach(function(alert) {
271-
var show = classNames.every(function(cl) { return cl.some(function(c) { return !!~c.indexOf('*') || alert.classList.contains(c); }); });
270+
}).forEach(function (alert) {
271+
var show = classNames.every(function (cl) { return cl.some(function (c) { return !!~c.indexOf('*') || alert.classList.contains(c); }); });
272272
anyVisibleAlert = show || anyVisibleAlert;
273273
alert.style.display = show ? 'block' : 'none';
274274
// DEBUG: uncomment following line and comment previous line to debug all alerts.
@@ -299,9 +299,9 @@
299299

300300
// Fix filter action identification.
301301
function fixActionAlerts(newsContainer) {
302-
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function(alert) {
302+
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function (alert) {
303303
return alert.parentNode;
304-
}).forEach(function(alert) {
304+
}).forEach(function (alert) {
305305
if (!!~alert.textContent.indexOf('created branch')) {
306306
alert.classList.remove('create');
307307
alert.classList.add('branch_create');
@@ -332,9 +332,9 @@
332332

333333
// Get unique list of repos.
334334
var userRepos = new Set();
335-
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function(alert) {
335+
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function (alert) {
336336
return alert.parentNode;
337-
}).forEach(function(alert) {
337+
}).forEach(function (alert) {
338338
var alertRepo = alert.querySelector(':scope [data-ga-click*="target:repo"]:not([data-ga-click*="target:repositories"])');
339339
if (alertRepo) { // Follow doesn't contain a repo link.
340340
var userRepo = alertRepo.textContent;
@@ -346,7 +346,7 @@
346346

347347
// Get list of user repos (forks) per repo names.
348348
var repos = {};
349-
userRepos.forEach(function(userRepo) {
349+
userRepos.forEach(function (userRepo) {
350350
var repo = userRepo.split('/')[1];
351351
if (!repos[repo]) {
352352
repos[repo] = [];
@@ -355,13 +355,13 @@
355355
});
356356

357357
// Populate global property.
358-
Object.keys(repos).forEach(function(repo) {
358+
Object.keys(repos).forEach(function (repo) {
359359
if (repos[repo].length === 1) {
360360
var userRepo = repos[repo][0];
361361
REPOS.push({ id: userRepo, text: userRepo, link: userRepo, icon: 'octicon-repo', classNames: [userRepo] });
362362
} else {
363363
var repoForks = { id: repo, text: repo, icon: 'octicon-repo-clone', classNames: [repo], subFilters: [] };
364-
repos[repo].forEach(function(userRepo) {
364+
repos[repo].forEach(function (userRepo) {
365365
repoForks.classNames.push(userRepo);
366366
repoForks.subFilters.push({ id: userRepo, text: userRepo, link: userRepo, icon: 'octicon-repo', classNames: [userRepo] });
367367
});
@@ -374,46 +374,46 @@
374374
USERS = [{ id: '*-user', text: 'All users', icon: 'octicon-organization', classNames: ['*-user'] }];
375375

376376
var users = new Set();
377-
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function(alert) {
377+
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function (alert) {
378378
return alert.parentNode;
379-
}).forEach(function(alert) {
379+
}).forEach(function (alert) {
380380
var usernameElms = alert.querySelectorAll(':scope [data-ga-click*="target:actor"]');
381-
Array.prototype.find.call(usernameElms, function(usernameElm){
382-
var username = usernameElm.textContent;
383-
if (username) {
381+
Array.prototype.find.call(usernameElms, function (usernameElm) {
382+
var username = usernameElm.textContent;
383+
if (username) {
384384
alert.classList.add(username);
385-
users.add(username);
386-
return true;
387-
}
388-
});
385+
users.add(username);
386+
return true;
387+
}
388+
});
389389
});
390390

391-
[...users].sort(function(a, b) {
391+
[...users].sort(function (a, b) {
392392
return a.toLowerCase().localeCompare(b.toLowerCase());
393-
}).forEach(function(username) {
393+
}).forEach(function (username) {
394394
var user = { id: username, text: username, icon: 'octicon-person', classNames: [username] };
395395
USERS.push(user);
396396
});
397397
}
398398

399399
// Update filter counts.
400400
function updateFilterCounts(filterContainer, newsContainer) {
401-
Array.forEach(filterContainer.querySelectorAll(':scope li.filter-list-item'), function(li) {
401+
Array.forEach(filterContainer.querySelectorAll(':scope li.filter-list-item'), function (li) {
402402
// Count alerts based on other filters.
403403
var countFiltered = 0;
404404
var classNames = [li.filterClassNames];
405405
var selected = document.querySelectorAll(":scope " + filterElement + ' li.filter-list-item.private');
406406
if (selected.length > 0) {
407-
Array.prototype.forEach.call(selected, function(item) {
407+
Array.prototype.forEach.call(selected, function (item) {
408408
if (item.parentNode.parentNode !== filterContainer) { // Exclude list item from current filter container.
409409
classNames.push(item.filterClassNames);
410410
}
411411
});
412412
}
413-
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function(alert) {
413+
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function (alert) {
414414
return alert.parentNode;
415-
}).forEach(function(alert) {
416-
var show = classNames.every(function(cl) { return cl.some(function(c) { return !!~c.indexOf('*') || alert.classList.contains(c); }); });
415+
}).forEach(function (alert) {
416+
var show = classNames.every(function (cl) { return cl.some(function (c) { return !!~c.indexOf('*') || alert.classList.contains(c); }); });
417417
if (show) {
418418
countFiltered++;
419419
}
@@ -424,10 +424,10 @@
424424
if (!!~li.filterClassNames[0].indexOf('*')) {
425425
countAll = newsContainer.querySelectorAll(':scope > div > .body').length;
426426
} else {
427-
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function(alert) {
427+
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function (alert) {
428428
return alert.parentNode;
429-
}).forEach(function(alert) {
430-
if (li.filterClassNames.some(function(cl) { return alert.classList.contains(cl); })) {
429+
}).forEach(function (alert) {
430+
if (li.filterClassNames.some(function (cl) { return alert.classList.contains(cl); })) {
431431
countAll++;
432432
}
433433
});
@@ -476,7 +476,7 @@
476476
selected && selected.classList.remove('filter-selected');
477477
this.classList.add('filter-selected');
478478

479-
Array.forEach(inner.querySelectorAll(filterListElement), function(menu) {
479+
Array.forEach(inner.querySelectorAll(filterListElement), function (menu) {
480480
menu && menu.classList.remove('open');
481481
});
482482
filterContainer.classList.add('open');
@@ -586,7 +586,7 @@
586586
filterer.querySelector('a').dispatchEvent(new Event('click'));
587587

588588
// Update on clicking "More"-button.
589-
new MutationObserver(function() {
589+
new MutationObserver(function () {
590590
// Re-click the current selected filter on open filter tab.
591591
filterer.querySelector('a.filter-selected').dispatchEvent(new Event('click'));
592592
}).observe(newsContainer, { childList: true });

0 commit comments

Comments
 (0)