Skip to content

Commit d800d80

Browse files
committed
Fix after another layout change. Refixes jerone#68.
1 parent f660940 commit d800d80

2 files changed

Lines changed: 39 additions & 34 deletions

File tree

β€ŽGithub_News_Feed_Filter/Github_News_Feed_Filter.user.jsβ€Ž

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
// @include https://github.com/?*
1818
// @include https://github.com/orgs/*/dashboard
1919
// @include https://github.com/orgs/*/dashboard?*
20-
// @version 8.2.6
20+
// @version 8.2.7
2121
// @grant none
2222
// ==/UserScript==
2323

@@ -53,7 +53,7 @@
5353
{ id: '*-action', text: 'All news feed', icon: 'octicon-radio-tower', classNames: ['*-action'] },
5454
{
5555
id: 'issues', text: 'Issues', icon: 'octicon-issue-opened', classNames: ['issues_labeled'], subFilters: [
56-
{ id: 'issues labeled', text: 'Labeled', icon: 'octicon-tag', classNames: ['issues_labeled'] },
56+
{ id: 'issues labeled', text: 'Labeled', icon: 'octicon-tag', classNames: ['issues_labeled'] }
5757
]
5858
},
5959
{
@@ -263,16 +263,14 @@
263263
}
264264

265265
// Show/hide alerts.
266-
if (classNames.length === 0 || classNames.every(function (cl) { return cl.every(function (c) { return !!~c.indexOf('*'); }); })) {
266+
if (classNames.length === 0 || classNames.every(function (cl) { return cl.every(function (c) { return ~c.indexOf('*'); }); })) {
267267
anyVisibleAlert = true;
268-
Array.prototype.forEach.call(newsContainer.querySelectorAll(':scope > div > div > .body'), function (alert) {
269-
alert.parentNode.style.display = 'block';
268+
getAllAlerts(newsContainer).forEach(function (alert) {
269+
alert.style.display = 'block';
270270
});
271271
} else {
272-
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > div > .body'), function (alert) {
273-
return alert.parentNode;
274-
}).forEach(function (alert) {
275-
var show = classNames.every(function (cl) { return cl.some(function (c) { return !!~c.indexOf('*') || alert.classList.contains(c); }); });
272+
getAllAlerts(newsContainer).forEach(function (alert) {
273+
var show = classNames.every(function (cl) { return cl.some(function (c) { return ~c.indexOf('*') || alert.classList.contains(c); }); });
276274
anyVisibleAlert = show || anyVisibleAlert;
277275
alert.style.display = show ? 'block' : 'none';
278276
// DEBUG: uncomment following line and comment previous line to debug all alerts.
@@ -288,7 +286,8 @@
288286
none = document.createElement('div');
289287
none.classList.add('no-alerts');
290288
none.appendChild(document.createTextNode('No feed items for this filter. Please select another filter.'));
291-
newsContainer.insertBefore(none, newsContainer.firstElementChild.nextElementSibling);
289+
var firstAlert = getAllAlerts(newsContainer)[0];
290+
firstAlert.parentNode.insertBefore(none, firstAlert);
292291
}
293292
}
294293

@@ -303,13 +302,11 @@
303302

304303
// Fix filter action identification.
305304
function fixActionAlerts(newsContainer) {
306-
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > div > .body'), function (alert) {
307-
return alert.parentNode;
308-
}).forEach(function (alert) {
309-
if (!!~alert.textContent.indexOf('created branch')) {
305+
getAllAlerts(newsContainer).forEach(function (alert) {
306+
if (~alert.textContent.indexOf('created branch')) {
310307
alert.classList.remove('create');
311308
alert.classList.add('branch_create');
312-
} else if (!!~alert.textContent.indexOf('deleted branch')) {
309+
} else if (~alert.textContent.indexOf('deleted branch')) {
313310
alert.classList.remove('delete');
314311
alert.classList.add('branch_delete');
315312
} else if (alert.getElementsByClassName('octicon-tag').length > 0 && !alert.classList.contains('release')) {
@@ -318,13 +315,13 @@
318315
} else if (alert.getElementsByClassName('octicon-tag-remove').length > 0) {
319316
alert.classList.remove('delete');
320317
alert.classList.add('tag_remove');
321-
} else if (!!~alert.textContent.indexOf('labeled an issue')) {
318+
} else if (~alert.textContent.indexOf('labeled an issue')) {
322319
alert.classList.add('issues_labeled');
323320
} else if (alert.classList.contains('gollum')) {
324321
alert.classList.remove('gollum');
325-
if (!!~alert.innerText.indexOf(' created a wiki page in ')) {
322+
if (~alert.innerText.indexOf(' created a wiki page in ')) {
326323
alert.classList.add('wiki_created');
327-
} else if (!!~alert.innerText.indexOf(' edited a wiki page in ')) {
324+
} else if (~alert.innerText.indexOf(' edited a wiki page in ')) {
328325
alert.classList.add('wiki_edited');
329326
}
330327
}
@@ -336,9 +333,7 @@
336333

337334
// Get unique list of repos.
338335
var userRepos = new Set();
339-
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > div > .body'), function (alert) {
340-
return alert.parentNode;
341-
}).forEach(function (alert) {
336+
getAllAlerts(newsContainer).forEach(function (alert) {
342337
var alertRepo = alert.querySelector(':scope [data-ga-click*="target:repo"]:not([data-ga-click*="target:repositories"])');
343338
if (alertRepo) { // Follow doesn't contain a repo link.
344339
var userRepo = alertRepo.textContent;
@@ -378,9 +373,7 @@
378373
USERS = [{ id: '*-user', text: 'All users', icon: 'octicon-organization', classNames: ['*-user'] }];
379374

380375
var users = new Set();
381-
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > div > .body'), function (alert) {
382-
return alert.parentNode;
383-
}).forEach(function (alert) {
376+
getAllAlerts(newsContainer).forEach(function (alert) {
384377
var usernameElms = alert.querySelectorAll(':scope [data-ga-click*="target:actor"]');
385378
Array.prototype.find.call(usernameElms, function (usernameElm) {
386379
var username = usernameElm.textContent;
@@ -389,6 +382,7 @@
389382
users.add(username);
390383
return true;
391384
}
385+
return false;
392386
});
393387
});
394388

@@ -414,23 +408,19 @@
414408
}
415409
});
416410
}
417-
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > div > .body'), function (alert) {
418-
return alert.parentNode;
419-
}).forEach(function (alert) {
420-
var show = classNames.every(function (cl) { return cl.some(function (c) { return !!~c.indexOf('*') || alert.classList.contains(c); }); });
411+
getAllAlerts(newsContainer).forEach(function (alert) {
412+
var show = classNames.every(function (cl) { return cl.some(function (c) { return ~c.indexOf('*') || alert.classList.contains(c); }); });
421413
if (show) {
422414
countFiltered++;
423415
}
424416
});
425417

426418
// Count alerts based on current filter.
427419
var countAll = 0;
428-
if (!!~li.filterClassNames[0].indexOf('*')) {
429-
countAll = newsContainer.querySelectorAll(':scope > div > div > .body').length;
420+
if (~li.filterClassNames[0].indexOf('*')) {
421+
countAll = getAllAlerts(newsContainer).length;
430422
} else {
431-
Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > div > .body'), function (alert) {
432-
return alert.parentNode;
433-
}).forEach(function (alert) {
423+
getAllAlerts(newsContainer).forEach(function (alert) {
434424
if (li.filterClassNames.some(function (cl) { return alert.classList.contains(cl); })) {
435425
countAll++;
436426
}
@@ -441,6 +431,13 @@
441431
});
442432
}
443433

434+
// Get all alerts.
435+
function getAllAlerts(newsContainer) {
436+
return Array.prototype.map.call(newsContainer.querySelectorAll(':scope div[data-repository-hovercards-enabled] > div > .body'), function (alert) {
437+
return alert.parentNode;
438+
});
439+
}
440+
444441
var CURRENT = {};
445442

446443
// Set current filter.
@@ -591,7 +588,7 @@
591588
new MutationObserver(function () {
592589
// Re-click the current selected filter on open filter tab.
593590
filterer.querySelector('a.selected').dispatchEvent(new Event('click'));
594-
}).observe(newsContainer, { childList: true });
591+
}).observe(newsContainer, { childList: true, subtree: true });
595592
})();
596593

597594
})();

β€ŽGithub_News_Feed_Filter/README.mdβ€Ž

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ Currently integrated filters:
6969

7070
## Version History
7171

72+
* **8.2.7**
73+
74+
* πŸ› Fix after another layout change. Refixes [#68](https://github.com/jerone/UserScripts/issues/68).
75+
76+
* **8.2.6**
77+
78+
* πŸ› Fix after another layout change. Refixes [#68](https://github.com/jerone/UserScripts/issues/68) with [#140](https://github.com/jerone/UserScripts/pull/140) (thanks [@darkred](https://github.com/darkred)).
79+
7280
* **8.2.5**
7381

7482
* πŸ› Fix showing filter. Fixes [#137](https://github.com/jerone/UserScripts/issues/137).

0 commit comments

Comments
Β (0)