Greasy Fork is available in English.

PR: Expand All "Show resolved" buttons

Expand All "Show resolved" buttons in pull request reviews.

  1. // ==UserScript==
  2. // @name PR: Expand All "Show resolved" buttons
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Expand All "Show resolved" buttons in pull request reviews.
  6. // @author Marcin Warpechowski
  7. // @match https://github.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. const pluginName = 'processed-by-warpech-expand-show-resolved';
  15.  
  16. let scheduledTimeout;
  17.  
  18. function findAndApplyChanges() {
  19. console.log('Running... Expand All "Show resolved" buttons in PRs');
  20. Array.from(document.querySelectorAll(`button:not([${pluginName}]), .btn-link:not([${pluginName}])`)).forEach((elem) => {
  21. elem.setAttribute(pluginName, '');
  22. if ((elem.innerText === 'Show resolved' || elem.innerText === ' Show conversation')) {
  23. elem.dispatchEvent(new MouseEvent('click', {
  24. bubbles: true,
  25. cancelable: true
  26. }));
  27. }
  28. });
  29. }
  30.  
  31. // console.log('Postponing... Expand All "Show resolved" buttons in PRs');
  32. scheduledTimeout = setTimeout(findAndApplyChanges, 1000);
  33.  
  34. const targetNode = document.querySelector("div.application-main");
  35. const observerOptions = {
  36. childList: true,
  37. subtree: true
  38. }
  39.  
  40. const mutationCallback = (mutationList, observer) => {
  41. mutationList.forEach((mutation) => {
  42. switch(mutation.type) {
  43. case 'childList':
  44. // console.log('Postponing... Expand All "Show resolved" buttons in PRs');
  45. clearTimeout(scheduledTimeout);
  46. scheduledTimeout = setTimeout(findAndApplyChanges, 1000);
  47. break;
  48. }
  49. });
  50. }
  51.  
  52. const observer = new MutationObserver(mutationCallback);
  53. observer.observe(targetNode, observerOptions);
  54. })();