|
17 | 17 | // @include https://github.com/?* |
18 | 18 | // @include https://github.com/orgs/*/dashboard |
19 | 19 | // @include https://github.com/orgs/*/dashboard?* |
20 | | -// @version 8.2.6 |
| 20 | +// @version 8.2.7 |
21 | 21 | // @grant none |
22 | 22 | // ==/UserScript== |
23 | 23 |
|
|
53 | 53 | { id: '*-action', text: 'All news feed', icon: 'octicon-radio-tower', classNames: ['*-action'] }, |
54 | 54 | { |
55 | 55 | 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'] } |
57 | 57 | ] |
58 | 58 | }, |
59 | 59 | { |
|
263 | 263 | } |
264 | 264 |
|
265 | 265 | // 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('*'); }); })) { |
267 | 267 | 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'; |
270 | 270 | }); |
271 | 271 | } 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); }); }); |
276 | 274 | anyVisibleAlert = show || anyVisibleAlert; |
277 | 275 | alert.style.display = show ? 'block' : 'none'; |
278 | 276 | // DEBUG: uncomment following line and comment previous line to debug all alerts. |
|
288 | 286 | none = document.createElement('div'); |
289 | 287 | none.classList.add('no-alerts'); |
290 | 288 | 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); |
292 | 291 | } |
293 | 292 | } |
294 | 293 |
|
|
303 | 302 |
|
304 | 303 | // Fix filter action identification. |
305 | 304 | 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')) { |
310 | 307 | alert.classList.remove('create'); |
311 | 308 | alert.classList.add('branch_create'); |
312 | | - } else if (!!~alert.textContent.indexOf('deleted branch')) { |
| 309 | + } else if (~alert.textContent.indexOf('deleted branch')) { |
313 | 310 | alert.classList.remove('delete'); |
314 | 311 | alert.classList.add('branch_delete'); |
315 | 312 | } else if (alert.getElementsByClassName('octicon-tag').length > 0 && !alert.classList.contains('release')) { |
|
318 | 315 | } else if (alert.getElementsByClassName('octicon-tag-remove').length > 0) { |
319 | 316 | alert.classList.remove('delete'); |
320 | 317 | alert.classList.add('tag_remove'); |
321 | | - } else if (!!~alert.textContent.indexOf('labeled an issue')) { |
| 318 | + } else if (~alert.textContent.indexOf('labeled an issue')) { |
322 | 319 | alert.classList.add('issues_labeled'); |
323 | 320 | } else if (alert.classList.contains('gollum')) { |
324 | 321 | alert.classList.remove('gollum'); |
325 | | - if (!!~alert.innerText.indexOf(' created a wiki page in ')) { |
| 322 | + if (~alert.innerText.indexOf(' created a wiki page in ')) { |
326 | 323 | 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 ')) { |
328 | 325 | alert.classList.add('wiki_edited'); |
329 | 326 | } |
330 | 327 | } |
|
336 | 333 |
|
337 | 334 | // Get unique list of repos. |
338 | 335 | 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) { |
342 | 337 | var alertRepo = alert.querySelector(':scope [data-ga-click*="target:repo"]:not([data-ga-click*="target:repositories"])'); |
343 | 338 | if (alertRepo) { // Follow doesn't contain a repo link. |
344 | 339 | var userRepo = alertRepo.textContent; |
|
378 | 373 | USERS = [{ id: '*-user', text: 'All users', icon: 'octicon-organization', classNames: ['*-user'] }]; |
379 | 374 |
|
380 | 375 | 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) { |
384 | 377 | var usernameElms = alert.querySelectorAll(':scope [data-ga-click*="target:actor"]'); |
385 | 378 | Array.prototype.find.call(usernameElms, function (usernameElm) { |
386 | 379 | var username = usernameElm.textContent; |
|
389 | 382 | users.add(username); |
390 | 383 | return true; |
391 | 384 | } |
| 385 | + return false; |
392 | 386 | }); |
393 | 387 | }); |
394 | 388 |
|
|
414 | 408 | } |
415 | 409 | }); |
416 | 410 | } |
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); }); }); |
421 | 413 | if (show) { |
422 | 414 | countFiltered++; |
423 | 415 | } |
424 | 416 | }); |
425 | 417 |
|
426 | 418 | // Count alerts based on current filter. |
427 | 419 | 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; |
430 | 422 | } 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) { |
434 | 424 | if (li.filterClassNames.some(function (cl) { return alert.classList.contains(cl); })) { |
435 | 425 | countAll++; |
436 | 426 | } |
|
441 | 431 | }); |
442 | 432 | } |
443 | 433 |
|
| 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 | + |
444 | 441 | var CURRENT = {}; |
445 | 442 |
|
446 | 443 | // Set current filter. |
|
591 | 588 | new MutationObserver(function () { |
592 | 589 | // Re-click the current selected filter on open filter tab. |
593 | 590 | filterer.querySelector('a.selected').dispatchEvent(new Event('click')); |
594 | | - }).observe(newsContainer, { childList: true }); |
| 591 | + }).observe(newsContainer, { childList: true, subtree: true }); |
595 | 592 | })(); |
596 | 593 |
|
597 | 594 | })(); |
0 commit comments