|
20 | 20 | // @grant none |
21 | 21 | // ==/UserScript== |
22 | 22 |
|
23 | | -(function() { |
| 23 | +(function () { |
24 | 24 |
|
25 | 25 | var ICONS = {}; |
26 | 26 | 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 | 102 | var filterListElement = 'github-news-feed-filter-list'; |
103 | 103 |
|
104 | 104 | function proxy(fn) { |
105 | | - return function() { |
| 105 | + return function () { |
106 | 106 | var that = this; |
107 | | - return function(e) { |
| 107 | + return function (e) { |
108 | 108 | var args = that.slice(0); // Clone. |
109 | 109 | args.unshift(e); // Prepend event. |
110 | 110 | fn.apply(this, args); |
|
149 | 149 | } |
150 | 150 | parent.appendChild(ul); |
151 | 151 |
|
152 | | - filters.forEach(function(subFilter) { |
| 152 | + filters.forEach(function (subFilter) { |
153 | 153 | var li = addFilterMenuItem(type, subFilter, ul, newsContainer, filterContainer); |
154 | 154 |
|
155 | 155 | if (subFilter.subFilters) { |
|
234 | 234 | setCurrentFilter(type, this.dataset[datasetId]); |
235 | 235 |
|
236 | 236 | // 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'); }); |
238 | 238 | showParentMenu(this); |
239 | 239 | this.parentNode.classList.add('open'); |
240 | 240 |
|
241 | 241 | // 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'); }); |
243 | 243 | this.parentNode.classList.add('private'); |
244 | 244 |
|
245 | 245 | // Toggle alert visibility. |
|
253 | 253 | var classNames = []; |
254 | 254 | var selected = document.querySelectorAll(":scope " + filterElement + ' .private'); |
255 | 255 | if (selected.length > 0) { |
256 | | - Array.prototype.forEach.call(selected, function(item) { |
| 256 | + Array.prototype.forEach.call(selected, function (item) { |
257 | 257 | classNames.push(item.filterClassNames); |
258 | 258 | }); |
259 | 259 | } |
260 | 260 |
|
261 | 261 | // 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('*'); }); })) { |
263 | 263 | 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) { |
265 | 265 | alert.parentNode.style.display = 'block'; |
266 | 266 | }); |
267 | 267 | } 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) { |
269 | 269 | 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); }); }); |
272 | 272 | anyVisibleAlert = show || anyVisibleAlert; |
273 | 273 | alert.style.display = show ? 'block' : 'none'; |
274 | 274 | // DEBUG: uncomment following line and comment previous line to debug all alerts. |
|
299 | 299 |
|
300 | 300 | // Fix filter action identification. |
301 | 301 | 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) { |
303 | 303 | return alert.parentNode; |
304 | | - }).forEach(function(alert) { |
| 304 | + }).forEach(function (alert) { |
305 | 305 | if (!!~alert.textContent.indexOf('created branch')) { |
306 | 306 | alert.classList.remove('create'); |
307 | 307 | alert.classList.add('branch_create'); |
|
332 | 332 |
|
333 | 333 | // Get unique list of repos. |
334 | 334 | 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) { |
336 | 336 | return alert.parentNode; |
337 | | - }).forEach(function(alert) { |
| 337 | + }).forEach(function (alert) { |
338 | 338 | var alertRepo = alert.querySelector(':scope [data-ga-click*="target:repo"]:not([data-ga-click*="target:repositories"])'); |
339 | 339 | if (alertRepo) { // Follow doesn't contain a repo link. |
340 | 340 | var userRepo = alertRepo.textContent; |
|
346 | 346 |
|
347 | 347 | // Get list of user repos (forks) per repo names. |
348 | 348 | var repos = {}; |
349 | | - userRepos.forEach(function(userRepo) { |
| 349 | + userRepos.forEach(function (userRepo) { |
350 | 350 | var repo = userRepo.split('/')[1]; |
351 | 351 | if (!repos[repo]) { |
352 | 352 | repos[repo] = []; |
|
355 | 355 | }); |
356 | 356 |
|
357 | 357 | // Populate global property. |
358 | | - Object.keys(repos).forEach(function(repo) { |
| 358 | + Object.keys(repos).forEach(function (repo) { |
359 | 359 | if (repos[repo].length === 1) { |
360 | 360 | var userRepo = repos[repo][0]; |
361 | 361 | REPOS.push({ id: userRepo, text: userRepo, link: userRepo, icon: 'octicon-repo', classNames: [userRepo] }); |
362 | 362 | } else { |
363 | 363 | 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) { |
365 | 365 | repoForks.classNames.push(userRepo); |
366 | 366 | repoForks.subFilters.push({ id: userRepo, text: userRepo, link: userRepo, icon: 'octicon-repo', classNames: [userRepo] }); |
367 | 367 | }); |
|
374 | 374 | USERS = [{ id: '*-user', text: 'All users', icon: 'octicon-organization', classNames: ['*-user'] }]; |
375 | 375 |
|
376 | 376 | 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) { |
378 | 378 | return alert.parentNode; |
379 | | - }).forEach(function(alert) { |
| 379 | + }).forEach(function (alert) { |
380 | 380 | 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) { |
384 | 384 | alert.classList.add(username); |
385 | | - users.add(username); |
386 | | - return true; |
387 | | - } |
388 | | - }); |
| 385 | + users.add(username); |
| 386 | + return true; |
| 387 | + } |
| 388 | + }); |
389 | 389 | }); |
390 | 390 |
|
391 | | - [...users].sort(function(a, b) { |
| 391 | + [...users].sort(function (a, b) { |
392 | 392 | return a.toLowerCase().localeCompare(b.toLowerCase()); |
393 | | - }).forEach(function(username) { |
| 393 | + }).forEach(function (username) { |
394 | 394 | var user = { id: username, text: username, icon: 'octicon-person', classNames: [username] }; |
395 | 395 | USERS.push(user); |
396 | 396 | }); |
397 | 397 | } |
398 | 398 |
|
399 | 399 | // Update filter counts. |
400 | 400 | 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) { |
402 | 402 | // Count alerts based on other filters. |
403 | 403 | var countFiltered = 0; |
404 | 404 | var classNames = [li.filterClassNames]; |
405 | 405 | var selected = document.querySelectorAll(":scope " + filterElement + ' li.filter-list-item.private'); |
406 | 406 | if (selected.length > 0) { |
407 | | - Array.prototype.forEach.call(selected, function(item) { |
| 407 | + Array.prototype.forEach.call(selected, function (item) { |
408 | 408 | if (item.parentNode.parentNode !== filterContainer) { // Exclude list item from current filter container. |
409 | 409 | classNames.push(item.filterClassNames); |
410 | 410 | } |
411 | 411 | }); |
412 | 412 | } |
413 | | - Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function(alert) { |
| 413 | + Array.prototype.map.call(newsContainer.querySelectorAll(':scope > div > .body'), function (alert) { |
414 | 414 | 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); }); }); |
417 | 417 | if (show) { |
418 | 418 | countFiltered++; |
419 | 419 | } |
|
424 | 424 | if (!!~li.filterClassNames[0].indexOf('*')) { |
425 | 425 | countAll = newsContainer.querySelectorAll(':scope > div > .body').length; |
426 | 426 | } 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) { |
428 | 428 | 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); })) { |
431 | 431 | countAll++; |
432 | 432 | } |
433 | 433 | }); |
|
476 | 476 | selected && selected.classList.remove('filter-selected'); |
477 | 477 | this.classList.add('filter-selected'); |
478 | 478 |
|
479 | | - Array.forEach(inner.querySelectorAll(filterListElement), function(menu) { |
| 479 | + Array.forEach(inner.querySelectorAll(filterListElement), function (menu) { |
480 | 480 | menu && menu.classList.remove('open'); |
481 | 481 | }); |
482 | 482 | filterContainer.classList.add('open'); |
|
586 | 586 | filterer.querySelector('a').dispatchEvent(new Event('click')); |
587 | 587 |
|
588 | 588 | // Update on clicking "More"-button. |
589 | | - new MutationObserver(function() { |
| 589 | + new MutationObserver(function () { |
590 | 590 | // Re-click the current selected filter on open filter tab. |
591 | 591 | filterer.querySelector('a.filter-selected').dispatchEvent(new Event('click')); |
592 | 592 | }).observe(newsContainer, { childList: true }); |
|
0 commit comments