Git Hub - Unroll comments

Adds a button to load (unroll) all "hidden items" (comments).

  1. // ==UserScript==
  2. // @name Git Hub - Unroll comments
  3. // @description Adds a button to load (unroll) all "hidden items" (comments).
  4. // @author monnef
  5. // @version 1
  6. // @match https://github.com/**
  7. // @grant none
  8. // @namespace monnef.eu
  9. // @require https://cdn.jsdelivr.net/npm/jquery@3.5.0/dist/jquery.min.js
  10. // ==/UserScript==
  11.  
  12.  
  13. // settings
  14.  
  15. const workTime = 500;
  16. const initDelay = 1000;
  17. const scrollingEnabled = true;
  18. const debugLogs = false;
  19.  
  20. // end of settings
  21.  
  22. const logPrefix = '[GHUC] ';
  23. const log = (...xs) => console.log(logPrefix, ...xs);
  24. const debug = (...xs) => debugLogs && console.debug(logPrefix, ...xs);
  25.  
  26. const scrollTo = (_, e) => scrollingEnabled && e.scrollIntoView({behavior: 'smooth', block: 'center'});
  27.  
  28. const getPagForm = () => $('.ajax-pagination-form');
  29.  
  30. const getPagBut = () => $('.ajax-pagination-btn');
  31.  
  32. const clickLoadMore = () => {
  33. debug('click load more button');
  34. getPagBut().click();
  35. };
  36.  
  37. const work = () => {
  38. if(getPagForm()[0]) {
  39. const but = getPagBut();
  40. if (but.text().includes("Loading")) {
  41. debug("waiting until comments loading finishes...");
  42. but.each(scrollTo);
  43. } else {
  44. clickLoadMore();
  45. }
  46. setTimeout(work, workTime);
  47. } else {
  48. debug('pagination form not found, assuming all comments are unrolled');
  49. $('.js-timeline-item').last().each(scrollTo);
  50. }
  51. };
  52.  
  53. const init = () => {
  54. log('Git Hub - Unroll Comments by monnef is starting...')
  55. const but = $('<button/>')
  56. .text('Load all 🧻')
  57. .attr('title', '[GHUC] Git Hub - Unroll comments by monnef')
  58. .attr('class', 'btn mt-2')
  59. .click(() => {
  60. but.remove();
  61. work();
  62. });
  63. getPagForm().append(but);
  64. debug('initialized');
  65. };
  66.  
  67. $(() => setTimeout(init, initDelay));