|
1 | 1 | // ==UserScript==
|
2 | 2 | // @name GitHub Toggle Expanders
|
3 |
| -// @version 1.0.6 |
| 3 | +// @version 1.1.0 |
4 | 4 | // @description A userscript that toggles all expanders when one expander is shift-clicked
|
5 | 5 | // @license MIT
|
6 | 6 | // @author Rob Garrison
|
|
14 | 14 | (() => {
|
15 | 15 | "use strict";
|
16 | 16 |
|
17 |
| - function toggle(el) { |
18 |
| - const state = closest(".commits-list-item, .js-details-container", el) |
19 |
| - .classList.contains("open"), |
20 |
| - // target buttons inside commits_bucket - fixes #8 |
21 |
| - selectors = ` |
22 |
| - .commits-listing .commits-list-item, |
23 |
| - #commits_bucket .js-details-container, |
24 |
| - .release-timeline-tags .js-details-container`; |
25 |
| - Array.from(document.querySelectorAll(selectors)).forEach(el => { |
26 |
| - el.classList.toggle("open", state); |
| 17 | + function toggle(el, ctrlKeyPressed) { |
| 18 | + const stateNode = closest(".js-details-container", el), |
| 19 | + state = stateNode.classList.contains("open"), |
| 20 | + parentNode = closest(ctrlKeyPressed ? |
| 21 | + ".container, .js-discussion" : |
| 22 | + ".commits-listing, .discussion-item-body, .release-timeline-tags", |
| 23 | + stateNode |
| 24 | + ), |
| 25 | + containerNodes = parentNode.querySelectorAll(".js-details-container"); |
| 26 | + |
| 27 | + Array.from(containerNodes).forEach(node => { |
| 28 | + node.classList.toggle("open", state); |
27 | 29 | });
|
28 | 30 | }
|
29 | 31 |
|
|
41 | 43 | const target = event.target;
|
42 | 44 | if (
|
43 | 45 | target && event.getModifierState("Shift") &&
|
44 |
| - target.matches(".ellipsis-expander") |
| 46 | + target.matches(".js-details-target") |
45 | 47 | ) {
|
46 | 48 | // give GitHub time to add the class
|
47 | 49 | setTimeout(() => {
|
48 |
| - toggle(target); |
| 50 | + toggle(target, event.ctrlKey); |
49 | 51 | }, 100);
|
50 | 52 | }
|
51 | 53 | });
|
|
0 commit comments