Greasy Fork 还支持 简体中文。

GitHub Toggle Expanders

A userscript that toggles all expanders when one expander is shift-clicked

目前為 2019-09-02 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name GitHub Toggle Expanders
  3. // @version 2.0.0
  4. // @description A userscript that toggles all expanders when one expander is shift-clicked
  5. // @license MIT
  6. // @author Rob Garrison
  7. // @namespace https://github.com/Mottie
  8. // @include https://github.com/*
  9. // @run-at document-idle
  10. // @icon https://github.githubassets.com/pinned-octocat.svg
  11. // ==/UserScript==
  12. (() => {
  13. "use strict";
  14.  
  15. function toggleButton(el, modKey) {
  16. const stateNode = el.closest(".js-details-container");
  17. const state = stateNode && (
  18. // Resolved expander
  19. stateNode.classList.contains("open") ||
  20. // compare detail expander
  21. stateNode.classList.contains("Details--on")
  22. );
  23. const parentNode = stateNode && stateNode.closest(modKey
  24. // shift+ctrl+click = expand all on page
  25. ? ".repository-content"
  26. // shift+click = expand all in date
  27. : ".commit-group"
  28. );
  29. if (parentNode) {
  30. const containers = parentNode.querySelectorAll(".js-details-container");
  31. [...containers].forEach(node => {
  32. node.classList.toggle("open", state);
  33. node.classList.toggle("Details--on", state);
  34. });
  35. }
  36. }
  37.  
  38. function toggleDetails(el, modKey) {
  39. const state = el && el.open;
  40. const parentNode = el && el.closest(modKey
  41. ? "#discussion_bucket" // .js-discussion
  42. : ".discussion-item-body" // .container?
  43. );
  44. if (parentNode) {
  45. const containers = parentNode.querySelectorAll(
  46. ".outdated-comment, .js-comment-container"
  47. );
  48. [...containers].forEach(node => {
  49. node.open = state;
  50. });
  51. }
  52. }
  53.  
  54. document.body.addEventListener("click", event => {
  55. const target = event.target;
  56. const mod = event.ctrlKey
  57. || event.metaKey
  58. || window.location.pathname.includes("/compare/");
  59.  
  60. if (target && event.getModifierState("Shift")) {
  61. // give GitHub time to update the elements
  62. setTimeout(() => {
  63. if (target.matches(".js-details-target")) {
  64. toggleButton(target, mod);
  65. } else if (
  66. target.matches(".Details-content--closed, .Details-content--open")
  67. ) {
  68. toggleDetails(target.closest("details"), mod);
  69. }
  70. }, 100);
  71. }
  72. });
  73.  
  74. })();